I'm having issues with error 9009
and error code 6
when trying to run the below. I can successfully run this on 1 machine without the ForEach loop so, i'm wondering what's going on with PSExec here.
$Credential = Get-Credential
$Random = Get-Random -Maximum 3
ForEach ($device in $site) {
New-PSDrive -Name ($SiteCode + $Random) -PSProvider FileSystem -Root ('\\' + $device + '\c$') -Description STE -Credential $Credential
Copy-Item C:\ClientInstall\ -Destination "$($SiteCode + $Random):" -Verbose -Recurse -Force
psexec \\$device cmd.exe /c c:\ClientInstall\clientinstall.cmd
}
Remove-PSDrive -Name ($Sitecode + '*') -Force -PSProvider FileSystem
The $device
variable is just an IP of the client which is in the $site variable which is a list of IP's. These are non-domain joined devices so, hence the faff.
Thanks in advance
EDIT:
I then tried the following:
$Credential = get-credential
$Random = Get-Random -Maximum 3
ForEach ($device in $site) {
New-PSDrive -Name ($SiteCode + $Random) -PSProvider FileSystem -Root ('\\' + $device + '\c$') -Description STE -Credential $Credential
Copy-Item C:\ClientInstall\ -Destination "$($SiteCode + $Random):" -Verbose -Recurse -Force
psexec ("\\" + $device) cmd.exe /c c:\ClientInstall\clientinstall.cmd
}
Remove-PSDrive -Name ($Sitecode + '*') -Force -PSProvider FileSystem
Main Change being:
psexec ("\\" + $device) cmd.exe /c c:\ClientInstall\clientinstall.cmd
This returns:
psexec : Connecting to 10.00.00.101...
At line:1 char:1
+ psexec ("\\" + $posdevice) cmd.exe /c c:\ClientInstall\sccmguidrepair ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Connecting to 10.00.00.101...:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Starting PSEXESVC service on 10.00.00.100...Connecting with PsExec service on 10.00.00.101...Starting cmd.exe on 10.00.00.101...
cmd.exe exited on 10.00.00.101 with error code 6.
Does anyone know what's going on here? Lost.
Thanks