After connecting to remote computer and executing some powershell job, I need to save a text file with output to a remote server using powershell.
My file name is created depending on computer name and date.
$filename = '' + $enddate + '' + $name + ''
Output is:
$output = "\\10.0.50.8\Informatyka\Posnet_raporty"
There is a username and password to connect to folder "Posnet_raporty"
$username = "user"
$password = "pass"
I use 2 functions to create the file and have been trying to use the NET USE
command to create a disc on the remote computer to save the file there, but it has failed ;/ (already mapped source from this adress, net use don't like it)
If ([int]$end1 -gt 30) {
$end1, $end2 | Out-File Q:\$filename'.txt'
}
else {
$end1, $end2 | Out-File Q:\'@'$filename'.txt'
}
The output of $end1
is a number (this does not apply to the question, but I prefer to write everything I can)
edit: net use fail, can not work with this same source what is already mapped on computers. PSDrive is only accessible in PowerShell session.