Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Running script remotely causes it to fail

$
0
0

Hi there

I have been working on an image updating script in Powershell 3.0 for the past few weeks. The script, when run locally as either an admin or the local System account, works perfectly. It falls down when trying to run it remotely however. I have searched these forums and others without success, not really sure why its failing.

The script has the following:

Sets out variables:

$RoboCMD = 'C:\windows\system32\Robocopy.exe'
$DeploymentShare = '\\server\share'
$LocalInstFolder = '"C:\Local Update Folder\store\'

It then contains a Hash table of security updates with our internal update ID's assigned:

$GoldSec = @{"SecPatches201303" = "1""SecPatches201302" = "2""SecPatches201301" = "3""SecPatches201212" = "4""SecPatches201211" = "5""SecPatches201210" = "6""SecPatches201209" = "7""SecPatches201208" = "8""SecPatches201207" = "9""SecPatches201206" = "10""SecPatches201205" = "11""SecPatches201204" = "12""SecPatches201203" = "13""SecPatches201202" = "14""SecPatches201201" = "15""SecPatches201111" = "16""SecPatches201110" = "17""SecPatches201109" = "18""SecPatches201108" = "19""SecPatches201106" = "20""SecPatches201105" = "21"
}

Finally, we look into the registry to see if this value already exists (we store these numbers in the registry as a belt-n-braces way of maintaining a record of whats been installed). If the reg value is found, the update is assumed to be installed and the loop continues. If it isnt found, the update is robocopied from our deployment share to the local install folder, where it is then run with a /s silent switch:

    ForEach($Update in $GoldSec.Value){
    $RegQuery = 0
    $RegQuery = Get-ItemProperty -Path $VersionNumber -Name $Update -ErrorAction Ignore

    If($RegQuery.$Update -eq $Update)
    {
    $EVT.WriteEntry("Found Update " + $Update + " already installed.","Information")
    }
    Else{
    $SecNeededUpdates += $Update
    $EVT.WriteEntry("Update " + $Update + " is outstanding, copying","Information")
    $RoboArgs = $DeploymentShare + $Update + " " + $LocalInstFolder + $Update + '" ' + $Update + ".exe"
    Start-Process -FilePath $RoboCMD -ArgumentList $RoboArgs -wait
    $InstCMD = $LocalInstFolder + $Update + "\" + $Update + '.exe"'
    $EVT.WriteEntry("Update " + $Update + " is installing.....","Information")
    Start-Process -FilePath $InstCMD -ArgumentList "/s" -Wait
    $Update = 0
    }
    }

As I said, when run locally, this all works great and these update packages are installed fine. If I run the script using the an invoke-command (invoke-command-ComputerName$PCID-FilePath'\\deploymentserver\scripts\updates\Updates.ps1'), I see the following error:

This command cannot be run due to the error: The system cannot find the file specified.

    + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException

    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

No files are copied, but I see the event logs being written. Ive verified that the robocopy.exe exists on the machine and I can also run rudimentary invoke-commands, such as ping or calc. This at least means the script started to run, but couldnt start the copy for some reason. The computer account's permissions have been checked for read access to the share, as have mine.

Im quite stumped :S


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>