none
Calling PsExec from within Powershell script....Error: RemoteExeption, NativeCommandErro RRS feed

  • Question

  • Hi All,

    i am using poweshell 4.0. i am getting below error while executing one the script

    Calling PsExec from within Powershell script....Error: RemoteExeption, NativeCommandErro

    our code: 

    If(Get-Service -ComputerName $($Server.ServerName) -Name psexesvc -ErrorAction SilentlyContinue){
     (Get-Service -ComputerName $($Server.ServerName) -Name psexesvc).Stop()
    cmd.exe /c "sc \\$($Server.ServerName) delete psexesvc"
    }
    $PendingReboot=&"\\servername\C$\tool\PsExec.exe" \\$($Server.Servername) -s cmd /c "echo . | Powershell set-executionpolicy bypass -force;\\servername\C$\script\PendingReboot.ps1"
     If($PendingReboot -eq $True){
        $Reboot="RebootRequired"
            }
            If($PendingReboot -eq $False){
            $Reboot="NoReboot"
                }

    Error:

    PsExec.exe : 
    At \\servername\C$\script\Servers.ps1:136 char:16
    + $PendingReboot=&"\\servername\C$\tool\PsExec.exe" \\$($Server.S ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:String) [], RemoteException
        + FullyQualifiedErrorId : NativeCommandError
     
    PsExec v2.11 - Execute processes remotely
    Copyright (C) 2001-2014 Mark Russinovich
    Sysinternals - www.sysinternals.com
    \\servername\C$\script\PendingReboot.ps1 : The term '\\servername\C$\script\PendingReboot.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.
    At line:1 char:35
    + set-executionpolicy bypass 
    -force;\\servername\C$\script\PendingReboot.ps1...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~
        + CategoryInfo          : ObjectNotFound: (\\\servername\C$\script\PendingReboot. 
       s1:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
     
    Connecting to local system...Starting PSEXESVC service on local system...Connecting with PsExec service on 
    server1...Starting cmd on server2..
    cmd exited on server2 with error code 1.

    same code worked fine on another server in different environment.

    is there anything we need to do on the server from which we are running this code?

    • Moved by Bill_Stewart Wednesday, September 5, 2018 10:06 PM Unanswerable drive-by question
    Thursday, July 5, 2018 3:26 PM