cscript error Access is Denied

I have a PS script that runs that invokes a vbs script. This works fine until I try to include the -computername attribute. When I do that I get an Access is denied error.

Script: 

$computerName = Read-Host "Computer Name: "
$employeecode = Read-Host "Employee Code: "

Invoke-Command -ScriptBlock { cscript.exe \\serverpath\UserPrintersScrape.vbs $computerName $employeecode } -ComputerName $computerName

When I run it, i get this error: 

CScript Error: Loading script "\\serverpath\UserPrintersScrape.vbs" failed (Access is denied. ).

However if I run this it runs fine:

$computerName = Read-Host "Computer Name: "
$employeecode = Read-Host "Employee Code: "

Invoke-Command -ScriptBlock { cscript.exe \\serverpath\UserPrintersScrape.vbs $computerName $employeecode }

The problem is, I need this to run on a remote pc. Any thoughts on how to resolve this or what is causing it?

Edit: One other thing to note, when I add the -computername I run it on my local pc for testing and get the error.

June 30th, 2015 5:08pm

Second hop restriction.  Look it up.

Free Windows Admin Tool Kit Click here and download it now
June 30th, 2015 5:47pm

Building on what jrv said, you might consider breaking this out into three steps: Copy the VBS file to the remote computer, run the VBS (what you're doing now, except make it a local path), and then remove the VBS file (unless you don't care about polluting your drive with files). PS Remoting will not allow the remote computer to delegate your credentials to another computer (the computer in your UNC) by default.
June 30th, 2015 6:07pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics