This is really slow and will take forever if I do one at a time.
Can you help me write it in a way that will either:
>> split the source txt file into multiple files with 100 entries each (I can then do a for loop and lauch powershell script against each of the 29 text files)
or
>> somehow run the wmi query against 10 separate machines at a time
I'm basically looking to get multiple treads working for me...
Thanks.
$computers = Get-Content vms.txt
$computers |sort -Descending | ForEach-Object {
$state = (get-wmiobject -query "select * from Win32_Service where
Name='ccmexec'" -ComputerName $_).state
$process = get-wmiobject -query "select * from Win32_Process where
Name='svchost.exe'" -ComputerName $_
$process | sort WorkingSetSize -desc |select-object -first 1 | foreach-
object {
$pname=$_.ProcessName
$phandle=$_.Handle
$psize=([Math]::round($_.WorkingSetSize / 1mb,1))}
$file = Get-WmiObject -Query "select * from CIM_Datafile Where Name =
'c:\\windows\\system32\\msi.dll'" -ComputerName $_
if ($file -eq $null) {
#try the NT path
$file = Get-WmiObject -Query "select * from CIM_Datafile Where Name =
'c:\\winnt\\system32\\msi.dll'" -ComputerName $_
}
$dllname = $file.Name
$dllversion = $file.version
Write-Host "$_ , CCM:$state , $pname, $phandle, $psize MB, $dllname, "
}
For PowerShell v1, this is one way (all nicely "packaged up":
http://jtruher.spaces.live.com/blog/cns!7143DA6E51A2628D!130.entry
For PowerShell v2 CTP/CTP2, there are new background job cmdlets. Example:
http://technet.microsoft.com/en-us/library/bb978574(TechNet.10).aspx
Marco
--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp
PowerGadgets MVP
http://www.powergadgets.com/mvp
Get-Content vms.txt | Split-Job .\Get-SMSInfo.ps1 | Export-Csv SMSInfo.csv
You can find the Split-Job script at my blog:
http://www.jansveld.net/powershell/2008/06/split-job-version-0-9/
Hope this helps,
Arnoud
Get-SMSInfo.ps1:
process {
$state = (get-wmiobject -query "select * from Win32_Service where
Name='ccmexec'" -ComputerName $_).state
$process = get-wmiobject -query "select * from Win32_Process where
Name='svchost.exe'" -ComputerName $_
$process | sort WorkingSetSize -desc |select-object -first 1 |
foreach-object {
$pname=$_.ProcessName
$phandle=$_.Handle
$psize=([Math]::round($_.WorkingSetSize / 1mb,1))
}
$file = Get-WmiObject -Query "select * from CIM_Datafile Where Name =
'c:\\windows\\system32\\msi.dll'" -ComputerName $_
if ($file -eq $null) {
#try the NT path
$file = Get-WmiObject -Query "select * from CIM_Datafile Where Name
= 'c:\\winnt\\system32\\msi.dll'" -ComputerName $_
}
$dllname = $file.Name
$dllversion = $file.version
# Write-Host "$_ , CCM:$state , $pname, $phandle, $psize MB, $dllname,
$dllversion"
# Send the output to the pipeline instead of the host
$_ | select @{name='ComputerName';exp={$_}},
@{name='CCM';exp={$state}},
@{name='pname';exp={$pname}},
@{name='phandle';exp={$phandle}},
@{name='psize';exp={$psize}},
@{name='dllname';exp={$dllname}},
@{name='dllversion';exp={$dllversion}}
}
--
http://www.jansveld.net/powershell