Search code examples
powershell-2.0rundeck

Rundeck job fails with PermissionDenied UnauthorizedAccessException


I have a job in a rundeck that connects to windows machine by some domain network's user credentials and runs the script that copies some folder from another machine in the domain network. Connection to windows node done by WinRM.

When I run that script by rundeck job it fails with error

[ERROR  ]  Test-Path : Access is denied
10:43:56    At E:\scripts\site_backup.ps1:20 char:10
10:43:56    + if(-not (Test-Path $BackupDirectory)) {
10:43:56    +          ~~~~~~~~~~~~~~~~~~~~~~~~~~    

PermissionDenied: (\\some.path.local\dprr...rw-tests-pq:String) [Test-Path], UnauthorizedAccessException

However, if I run that script under the same user connecting by RDP to that machine it works fine.

I suspect WinRM service does not have enough privileges. Maybe I am wrong. How can I resolve that issue? Any help will be appreciated.


Solution

  • That's "double hop" PowerShell problem. You can check a full explanation here, and here a good approach. Also here a good wokaround.