You could use the Windows’ net
utility
net use \\server /user:domain\username password
Or use PowerShell cmdlet New-SmbMapping from the SmbShare
module:
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 Out-File
"Your output" | Out-File "\\server\path\myfile.txt"
CLICK HERE to find out more related problems solutions.