I have following script to run some basic commands on remote machine and log the output to the share. I'm getting access denied exception on the share even though the share has full control access for everyone including me executing the script,
script:
invoke-command -session $s -ScriptBlock {
param($log)
cd 'c:\temp' | out-file $log -NoClobber
cmd /c 'dir' | out-file $log -NoClobber
} -argumentList '\\share_location\log_file_path.log'
fyi, in the above script the session $s is generated with my credentials.
exception:
Access to the path '\\share_location\log_file_path.log' is denied.
+ CategoryInfo : OpenError: (:) [Out-File], UnauthorizedAccessException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand
Could someone suggest what I'm missing here?