Deepanshu Kalra
Deepanshu Kalra

Reputation: 469

Copy-Item over remote network path using WinRS throws UnauthorisedAccessException

$_sourcepath = '\\servername\DriveLetter$\folder\file.zip'
$_destinationPath = 'D:\Temp\file.zip'
Copy-Item -Path $_sourcepath -Destination $_destinationPath;

My PowerShell script is run using WinRS in MSBuilds. It throws UnauthorisedAccessException but works fine when running on the local server.

Now I'm using $Username = Domain\username"; $Password = ConvertTo-SecureString "password" -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential($Username, $Password) $session = new-pssession -computername 'serverName' -credential $cred Invoke-Command -Session $session -ScriptBlock {copy-Item -Path $($args[0]) -destination $($args[1])} -argumentlist $_sourcepath,$_destinationPath ;

and im still getting Unauthorized AccessException.

Upvotes: 0

Views: 116

Answers (0)

Related Questions