You could use the Windows’
net use \\server /user:domain\username password
Or use PowerShell cmdlet New-SmbMapping from the
New-SmbMapping -RemotePath '\\server' -Username "domain\username" -Password "password"
After that, you can simply use the UNC path for writing to the file, for example with
"Your output" | Out-File "\\server\path\myfile.txt"
CLICK HERE to find out more related problems solutions.