



So, with PowerShell 2.0 CTP’s arrival, and me finally having some time to mess around with some of the new features, here’s my previous (and first popular) post re-hashed for PowerShell 2.0 CTP. This will only work on machines with WS-Management installed, so it probably won’t work on most of your machines (unless you’ve deployed it), but it works well in my little test world. It utilizes two new features. These features are the [ADSISearcher] and Invoke-Expression. Instead of creating all of the Directory Service objects each time, you can just cast the ASDISearcher type and you’re done. Invoke-Expression allows you to use the -computer parameter and pass one, or many, computers to the cmdlet. I chose to use a single command here.
[adsisearcher]$searcher = “LDAP://dc=foo,dc=bar,dc=com”
$searcher.filter = “(objectclass=computer)”
foreach ($machine in ($searcher.findall()))
{
invoke-expression -computer $machine.properties.cn -command ”c:\windows\`$NtUninstallKB917013`$\spuninst\spuninst.exe /q /norestart”
}
I haven’t had a chance to test it, but you could use mutiple computers. We could change the foreach loop to write to a text file, then read that file for the computer names.
...
foreach ($machine in ($searcher.findall())){ add-content c:\temp\machines.txt "$($machine.properties.cn)" }
invoke-expression -computer (get-content c:\temp\machines.txt) -command "c:\windows\`$NtUninstallKB917013`$\spuninst\spuninst.exe /q /norestart"
That’ll kick off on 50 machines at a time. You can adjust that via the -ThrottleLimit parameter, and make it more or less, depending on bandwidth, CPU power, etc.
As you can see, I tend to learn better by example or by practical application. You’ll never see me write a book :) More soon!!


More Options ...

Categories
Tag Cloud
Blog RSS
Comments RSS


Void
Life « Default
Earth
Wind
Water
Fire
Light 