locked
cscript error Access is Denied RRS feed

  • Question

  • 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.

    Tuesday, June 30, 2015 9:06 PM

Answers

  • Second hop restriction.  Look it up.


    \_(ツ)_/

    • Proposed as answer by Mike Laughlin Tuesday, June 30, 2015 10:06 PM
    • Marked as answer by AnnaWY Tuesday, July 14, 2015 9:52 AM
    Tuesday, June 30, 2015 9:44 PM
  • 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.
    • Proposed as answer by AnnaWY Thursday, July 2, 2015 7:28 AM
    • Marked as answer by AnnaWY Tuesday, July 14, 2015 9:53 AM
    Tuesday, June 30, 2015 10:05 PM

All replies

  • Second hop restriction.  Look it up.


    \_(ツ)_/

    • Proposed as answer by Mike Laughlin Tuesday, June 30, 2015 10:06 PM
    • Marked as answer by AnnaWY Tuesday, July 14, 2015 9:52 AM
    Tuesday, June 30, 2015 9:44 PM
  • 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.
    • Proposed as answer by AnnaWY Thursday, July 2, 2015 7:28 AM
    • Marked as answer by AnnaWY Tuesday, July 14, 2015 9:53 AM
    Tuesday, June 30, 2015 10:05 PM
  • I'll try the route of copying the file to the computer and running it from there.

    Thanks!

    Monday, July 6, 2015 2:57 PM
  • When trying to copy the file locally and run it, I get the same issue. Going to work on the second hop restriction.
    Monday, July 6, 2015 3:50 PM