locked
Remote Powershell, cannot run script RRS feed

  • Question

  • Hi, trying this command:

    Invoke-Command -ComputerName remoteserver -ScriptBlock {\\some_server\share\script.ps1}

    But I get this error:

    The term '\\some_server\share\script.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
        + CategoryInfo          : ObjectNotFound: (\\some_server\...\script.ps1:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
        + PSComputerName        : remoteserver

    But when running just the \\some_server\share\script.ps1 locally on the remoteserver It works, using same user. Any ideas?

    Thanks.

    Tuesday, January 31, 2017 8:11 AM

Answers

  • You cannot remotely refer to a file on a third server.  It is a remoting restriction.

    You may be able to do this:

    Invoke-Command -ComputerName remoteserver -file \\some_server\share\script.ps1


    \_(ツ)_/

    • Marked as answer by niklasrene Wednesday, February 1, 2017 8:40 AM
    Tuesday, January 31, 2017 8:22 AM

All replies

  • You cannot remotely refer to a file on a third server.  It is a remoting restriction.

    You may be able to do this:

    Invoke-Command -ComputerName remoteserver -file \\some_server\share\script.ps1


    \_(ツ)_/

    • Marked as answer by niklasrene Wednesday, February 1, 2017 8:40 AM
    Tuesday, January 31, 2017 8:22 AM
  • It's a remoting restriction use -file parameter to specify location of PS script.
    Tuesday, January 31, 2017 11:34 AM
  • It's a remoting restriction use -file parameter to specify location of PS script.

    Isn't that already the answer here?


    \_(ツ)_/

    Tuesday, January 31, 2017 11:35 AM
  • Thanks, works.

    Wednesday, February 1, 2017 8:40 AM
  • Hi, another similar challenge; Im trying to run a silent install of sql server with powershell. the file, install.ps1 contains this:

    & "\\fileserver\mssql2016\setup.exe" /ConfigurationFile="\\fileserver2\ConfigurationFile-SSQLSERVER.ini" /IAcceptSQLServerLicenseTerms /AGTSVCPASSWORD="strongpw /SQLSVCPASSWORD="strongpw

    This ps1 runs ok locally on the sql server, but remotely I run this the correct way mentioned in the answer, but I get the error:

    The term '\\fileserver\mssql2016\setup.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    + CategoryInfo          : ObjectNotFound: (\\fileserver\mssql2016\setup.exe:String) [], CommandNotFoundException

    Wednesday, February 1, 2017 2:13 PM
  • You cannot remotely access a third systems.  You must copy the install file to the remote server and use a local path.


    \_(ツ)_/

    Wednesday, February 1, 2017 3:38 PM