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.   


  3. #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

  4. #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? Browsers & Mail
WMI Query runs forever on Domain Controller Server General
split txt file VB Script
Query csv and return all entries within last x days VB Script
Update data source names on 300 machines PowerShell