Question

Back story:

I am working on a script that will be pointed at a Microsoft SCCM collection. This script is meant to query for all members in the collection and do something. So far I can restart specific services on all collection members, such as the SCCM service. The next bit I am working on is uninstalling a patch from each member in the collection.

Something like this works to restart the service on each collection member:

foreach ($member in get-cmdevice -collectionname "A collection name"){Get-Service -ComputerName $member.name -Name CcmExec | Restart-Service}

The script:

foreach ($member in get-cmdevice -collectionname "Some collection name") 
{   
    $ession = new-PSSession -ComputerName $member
    Invoke-Command -Session $ession {wusa.exe /uninstall /kb:######/quiet /log /norestart} 
}

The resulting error:

new-PSSession:One or more computer names is not valid

Trying to emulate the 1st script, by only adding the invoke-command, results in the script trying to uninstall the update from the local computer.

Thoughts?

Was it helpful?

Solution

Got it. Had to add

.name

after $member down in the session. I was trying to pull the whole object / array in.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top