Author Posts

August 29, 2015 at 7:03 am

Could you please help me to validate this.
Scenario: I am trying move files from a shared path to remote machine.In that situation i am doing Test-Connection to check whether server is pingable or not.If Test-Connection returns true i am using Move-Item to move files. But in this case even though server is pingable,i dont have acces to that server to login. So Move-Item fails with message "Access-Denied". Could you please help me to validate this.

If i dont have an access, simply i should log those details and need to move to next instead of displaying those error on the screen like below.

PS H:\> Move-Item -Path D:\Test.txt -Destination \\ServerName\D$\Test.txt -Force
Move-Item : Access is denied
At line:1 char:1
+ Move-Item -Path D:\Test.txt -Destination \\ServerName\D$\Test.txt -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (D:\Test.txt:String) [Move-Item], UnauthorizedAccessException
+ FullyQualifiedErrorId : MoveItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.MoveItemCommand
Even i tried to catch this in Catch block like below but its not helping me.
Catch [System.UnauthorizedAccessException]
write-host "Not authorized to perform this operation"

August 29, 2015 at 7:06 am

Consider reading The Big Book of PowerShell Error Handling. It's free on our Resouces / ebooks menu and has a lot of detail about dealing with errors.