Windows Vista Forums

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

  1. #1


    Tolli Lowell-Forker (1) Guest

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

    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 System SpecsSystem Spec

  2. #2


    Marco Shaw [MVP] Guest

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

    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/...628D!130.entry

    For PowerShell v2 CTP/CTP2, there are new background job cmdlets. Example:
    http://technet.microsoft.com/en-us/l...chNet.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 System SpecsSystem Spec

  3. #3


    Arnoud Jansveld Guest

    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/2...b-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/...628D!130.entry
    >
    > For PowerShell v2 CTP/CTP2, there are new background job cmdlets. Example:
    > http://technet.microsoft.com/en-us/l...chNet.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 System SpecsSystem Spec

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

Similar Threads
Thread Forum
How can I preview split file without downloading entire file and combining parts?
In Outlook express, I used to be able to view the first part or several parts of a split movie or pictures to see whether it was worth downloading....
Browsers & Mail
WMI Query runs forever on Domain Controller
I am testing a small piece of code that I'm working on to tie a piece of software to a specific machine on the network. I've been using WMI queries...
Server General
restore pst file that has been split
Was using: Outlook 2003 on a Windows Vista Home Edition desktop Program: Backup and Restore was set for weekly backup of several folders including...
Vista General
split txt file
Hello, I have a txt file (C:\test\kunden.txt) like follow: Gruppe_1;Name;Vorname Gruppe_1;Name1;Vorname1 Gruppe_2;Name1;Vorname1...
VB Script
file copy operations using source file input and script?
we have a text file that contains a full directory listing of a given drive's folder structure, this text file directory list represents the same...
PowerShell
Query csv and return all entries within last x days
I have a comma delimited file in the following format: Computer Name,Time Date,Time Zone,Action Workstation1,11/8/2007 12:03:34 PM,Central Standard...
VB Script
Update data source names on 300 machines
My organization is migrating from SQL Server 2000 to SQL Server 2005. There are many legacy applicaitons on 2000 that are being upgraded, and...
PowerShell