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 problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I preview split file without downloading entire file and combining parts? nkringo Browsers & Mail 0 23 Nov 2009
WMI Query runs forever on Domain Controller Scott S. Server General 1 29 Jul 2009
split txt file Mike Berger VB Script 3 21 Aug 2008
Query csv and return all entries within last x days tstar31 VB Script 1 17 Jul 2008
Update data source names on 300 machines drew PowerShell 5 23 Jun 2008