Windows PowerShell Time out question

  • Follow


Wondering if there's a way to limit how long PowerShell will try to get the 
following information out of a servers WMI. Here's what I've got currently, 
it works fine so long the servers respond...

$a = New-Object -comobject Excel.Application
$a.visible = $True

$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)

$c.Cells.Item(1,1) = "Domain"
$c.Cells.Item(1,2) = "Server Name"
$c.Cells.Item(1,3) = "Operating System"
$c.Cells.Item(1,4) = "IP Address"
$c.Cells.Item(1,5) = "Service Packs"
$c.Cells.Item(1,6) = "System Type"
$c.Cells.Item(1,7) = "Manufacturer"
$c.Cells.Item(1,8) = "Model"
$c.Cells.Item(1,9) = "Serial Number"
$c.Cells.Item(1,10) = "Number of Processors"
$c.Cells.Item(1,11) = "Processor Speed"
$c.Cells.Item(1,12) = "Total Phsyical Memory (GB)"
$c.Cells.Item(1,13) = "Report Time Stamp"

$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True

$intRow = 2

$colComputers = get-content C:\servers.txt
foreach ($strComputer in $colComputers)
{
clear-variable -name os
clear-variable -name computer
clear-variable -name bios
clear-variable -name processor
$OS = get-wmiobject Win32_OperatingSystem -computername $strComputer
$Computer = Get-WmiObject Win32_computerSystem -computername $strComputer
$Bios = Get-WmiObject win32_bios -computername $strComputer
$processor = get-wmiobject win32_processor -computername $strcomputer | 
select-object -first 1 name
$IP = get-wmiobject win32_ip -computername $strcomputer

$c.Cells.Item($intRow,1) = $computer.Domain
$c.Cells.Item($intRow,2) = $strComputer.Toupper()
$c.Cells.Item($intRow,3) = $OS.Caption
$c.Cells.Item($intRow,4) = $IP.IPaddress[0]
$c.Cells.Item($intRow,5) = $OS.CSDVersion
$c.Cells.Item($intRow,6) = $Computer.SystemType
$c.Cells.Item($intRow,7) = $Computer.Manufacturer
$c.Cells.Item($intRow,8) = $Computer.Model
$c.Cells.Item($intRow,9) = $Bios.serialnumber
$c.Cells.Item($intRow,10) = $Computer.NumberOfProcessors
$c.Cells.Item($intRow,11) = $processor.name
$c.Cells.Item($intRow,12) = $computer.TotalPhysicalMemory
$c.Cells.Item($intRow,13) = Get-date

$intRow = $intRow + 1
}
$d.EntireColumn.AutoFit()


Help is much appreciated.
0
Reply Utf 6/25/2010 8:42:20 PM

I am presuming you're using Powershell v1.

The alternate (if you can't adjust the timeouts) would be to Invoke those as Jobs in Powershell V2 where they can run in Parallel.

What can happen then is just watch for the ones that timeout and collect the results quicker.  Just place the block of code as a function and call it like this.

$colComputers = get-content C:\servers.txt
foreach ($strComputer in $colComputers)
{
     START-JOB SERVER-FUNCTION($StrComputer)
}

$Int=1

$JOBLIST=GET-JOB
DO {
$DONE=$TRUE
FOREACH ($JOBTODO in $JOBLIST)
{
     IF (($JOBTODO.STATE -eq 'Completed' ) -and ($JOBTODO.HASMOREDATA -eq $TRUE)) 
 { $X=RECEIVE-JOB $JOBTODO
   $INT++
   $DONE=$FALSE 
# 
# Here is where your Excel Code might fit in
#   
#
 }
} UNTIL ($DONE -eq $TRUE

Not a perfect example but this would be a loop to watch for the jobs and keep collecting data and add to the spreadsheet.

And improvement would be to watch for errors and drop them (Ie server offline)

But just an example of how jobs could improve on your inventory spreadsheet.

Cheers! 
Sean
The Energized Tech
www.powershell.ca



Sean T. wrote:

Windows PowerShell Time out question
25-Jun-10

Wondering if there is a way to limit how long PowerShell will try to get the
following information out of a servers WMI. Here is what I have got currently,
it works fine so long the servers respond...

$a = New-Object -comobject Excel.Application
$a.visible = $True

$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)

$c.Cells.Item(1,1) = "Domain"
$c.Cells.Item(1,2) = "Server Name"
$c.Cells.Item(1,3) = "Operating System"
$c.Cells.Item(1,4) = "IP Address"
$c.Cells.Item(1,5) = "Service Packs"
$c.Cells.Item(1,6) = "System Type"
$c.Cells.Item(1,7) = "Manufacturer"
$c.Cells.Item(1,8) = "Model"
$c.Cells.Item(1,9) = "Serial Number"
$c.Cells.Item(1,10) = "Number of Processors"
$c.Cells.Item(1,11) = "Processor Speed"
$c.Cells.Item(1,12) = "Total Phsyical Memory (GB)"
$c.Cells.Item(1,13) = "Report Time Stamp"

$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True

$intRow = 2

$colComputers = get-content C:\servers.txt
foreach ($strComputer in $colComputers)
{
clear-variable -name os
clear-variable -name computer
clear-variable -name bios
clear-variable -name processor
$OS = get-wmiobject Win32_OperatingSystem -computername $strComputer
$Computer = Get-WmiObject Win32_computerSystem -computername $strComputer
$Bios = Get-WmiObject win32_bios -computername $strComputer
$processor = get-wmiobject win32_processor -computername $strcomputer |
select-object -first 1 name
$IP = get-wmiobject win32_ip -computername $strcomputer

$c.Cells.Item($intRow,1) = $computer.Domain
$c.Cells.Item($intRow,2) = $strComputer.Toupper()
$c.Cells.Item($intRow,3) = $OS.Caption
$c.Cells.Item($intRow,4) = $IP.IPaddress[0]
$c.Cells.Item($intRow,5) = $OS.CSDVersion
$c.Cells.Item($intRow,6) = $Computer.SystemType
$c.Cells.Item($intRow,7) = $Computer.Manufacturer
$c.Cells.Item($intRow,8) = $Computer.Model
$c.Cells.Item($intRow,9) = $Bios.serialnumber
$c.Cells.Item($intRow,10) = $Computer.NumberOfProcessors
$c.Cells.Item($intRow,11) = $processor.name
$c.Cells.Item($intRow,12) = $computer.TotalPhysicalMemory
$c.Cells.Item($intRow,13) = Get-date

$intRow = $intRow + 1
}
$d.EntireColumn.AutoFit()


Help is much appreciated.

Previous Posts In This Thread:


Submitted via EggHeadCafe - Software Developer Portal of Choice 
Store ASP.NET Site Visitor Stats in MongoDb
http://www.eggheadcafe.com/tutorials/aspnet/3a73c6de-82a1-4690-a7aa-d0eda58203f7/store-aspnet-site-visitor-stats-in-mongodb.aspx
0
Reply Sean 6/26/2010 2:06:19 AM

1 Replies
1029 Views

(page loaded in 0.306 seconds)

6/8/2014 1:00:48 AM


Reply: