• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

split source file into many files with 100 entries each to feedscripts that runs wmi query agains ma

  • Thread starter Tolli Lowell-Forker (1)
  • Start date
T

Tolli Lowell-Forker (1)

#1
I have a source file with 2900 machine names. I'm currently reading
it line by line and running 3 wmi queries against each machine:
checking if a service is running
checking for memory use of a specific process
checking for the version of a dll

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, "
}
 

My Computer

M

Marco Shaw [MVP]

#2
Tolli Lowell-Forker (1) wrote:

> I have a source file with 2900 machine names. I'm currently reading
> it line by line and running 3 wmi queries against each machine:
> checking if a service is running
> checking for memory use of a specific process
> checking for the version of a dll
>
> 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...
>
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

Blog:
http://marcoshaw.blogspot.com
 

My Computer

A

Arnoud Jansveld

#3
Re: split source file into many files with 100 entries each to fee

Tolli, it looks like you could use the Split-Job script I just posted. You
only need to make some minor modifications to the script so that it takes and
writes its data to/from the pipeline (see below). You could then run the
following:

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



"Marco Shaw [MVP]" wrote:

> Tolli Lowell-Forker (1) wrote:

> > I have a source file with 2900 machine names. I'm currently reading
> > it line by line and running 3 wmi queries against each machine:
> > checking if a service is running
> > checking for memory use of a specific process
> > checking for the version of a dll
> >
> > 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...
> >
>
> 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
>
> Blog:
> http://marcoshaw.blogspot.com
>
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)