Windows PowerShell Time out question

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
Utf
6/25/2010 8:42:20 PM
windows.powershell 690 articles. 0 followers. Follow

1 Replies
1700 Views

Similar Articles

[PageSpeed] 35

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
Sean
6/26/2010 2:06:19 AM
Reply:

Similar Artilces:

ASP Files not working windows VISTA IIS..
Hi..please advice how do i run asp files in my localhost and i'm using windows vistasundar ...

Formatting Question #3
I have the following: =IF((B21-C21)>0,B21-C21 & " Under Budget", B21-C21 & " Over Budget") How can I get the resulting value to be formatted as currency? I have formatted the cell as currency but I guess with the & "text" it doesn't treat the numerical part as currency. You are correct. So to overcome that, Put your currency symbol into the formula too. =IF((B21-C21)>0,"$"&B21-C21 & " Under Budget", "$"&B21-C21 & " Over Budget") "M.Siler" wrote: > I have the fo...

reinstalling windows
windows has become corrupted. when i have attempted to reinstall windows the set up screen tells me " the file cmdide.sys is corrupted. press any key to continue". at the bottom of the screen it says " setup failed". do i need to format the disc so that i can reinstall windows and if so, how do i do it? thanks, mike mikalle wrote: > windows has become corrupted. when i have attempted to reinstall windows the > set up screen tells me " the file cmdide.sys is corrupted. press any key to > continue". at the bottom of the screen it says &qu...

CRM Questions on SFOC
Just a question... What are the advantanges and disadvantages to using the CRM Toolbar for creating Task, Appointments, E-mails and Contacts, which creates them in both CRM and in Outlook? If in both you could synch with a Palm or other PDA from within the Outlook folders, and I know you they synch automatically between, but would you not want to keep your corporate business contacts separate in CRM and then personal or personal business is Outlook? Just some clarificaion would be helpful. Thanks! Shauna A great advantage of the SFO CRM Appointment button is that you get visibilit...

Windows live mail
My windows live mail account will not send or recieve any messages. Every time I attempt to send an email. I get this message... windows cannot send this message you need a digital id, this message is not encrypted. I have tried to download a program for a digital id but this has not solved the problem. Dew "Dew" wrote: > My windows live mail account will not send or recieve any messages. Every > time I attempt to send an email. I get this message... windows cannot send > this message you need a digital id, this message is not encrypted. I have >...

Outlook 2007 question
I installed outlook 2007 and now I try to customise it but I notice that the Tools/Opions and Tools/Customize menus are disabled. Why and how to enable them? thanks I notice now that the problem is more severe. I cannot reply to messages, save is not working. It seems that most of the functionality is disabled. I can receive emails but cannot answer them. Any clue? this is very bothering. Thanks! "YLY" wrote: > I installed outlook 2007 and now I try to customise it but I notice that the > Tools/Opions and Tools/Customize menus are disabled. Why and how to enable > t...

Windows Vista
Not sure whats going on, but when I opened Windows Mail this afternoon I decided not to send any emails and generates the message :- The connection to the server has failed. Subject 'test 1', Account: 'pop.123-reg.co.uk', Server: 'smtp.123-reg.co.uk', Protocol: SMTP, Port: 25, Secure(SSL): No, Socket Error: 10060, Error Number: 0x800CCC0E I had this a few weeks ago and on going into account properties and clicking on and off the various Connection tick boxes, the problem cleared. However this time there is no change. Any Ideas ?? Submitted via EggHeadCafe -...

open windows
How do I close ALL open windows w/ ONE click Post Originated from http://www.VistaForums.com Vista Support Forums "kotus" wrote in message news:%23QO5zHhnKHA.1548@TK2MSFTNGP06.phx.gbl... > How do I close ALL open windows w/ ONE click > If you can tolerate an extra click, you can right-click the group of windows in your task bar > Close group Otherwise you'd probably need a mini-app that with a desktop shortcut that does what you want. -- Jon On Mon, 25 Jan 2010 14:58:46 -0800, kotus wrote: > How do I close ALL open windows w/ ONE...

Unknown 12029 while using window.ActiveXObject & window.XMLHttpRequest
Hi, I am using the following code in my .jsp file for request to, and get a response from a web server - without reloading the page. But this code is working if i will use http://localhost:8080/.../xxx.jsp. But if i will call remotely like http://12.12.12.1111:8080/.../xxx.jsp it's throwing "Unknown 12029" Exception. Kindly let me know what changes i should do. Plz explain me detailly on this. // code for Mozilla, Netscape, etc... if (window.XMLHttpRequest) { req=new XMLHttpRequest() req.onreadystatechange=state_Change req.open("GET",urlT,true) ...

For the Third Time
Once again, if someone could help me out, I'd appreciate it. First, I need to know how if it possible to empty the mailbox store. I cannot clean it, defrag it, or run any of the included tools with this in order to get the 16gb capacity freed up so I can actually do work on it. If it is possible to empty this, please advise me on how to do it. I have all email clients connecting to an outside POP3 provider till this is worked out. Second, why would a 16gb container get filled in less than 2 days? Is it a spam issue that we are having, or what could be the problem? How do I ...

Windows pdate Status: Failed
Hi, This is my problem: http://yfrog.com/1fupdatekj So, how can I manage to install this update? I am using Acer Laptop with its own Vista and HP LP2275w monitor. Thanks in advance. Koray For home users, no-charge support is available by calling 1-866-PCSAFETY (and/or 1-866-234-6020) in the United States and in Canada or by contacting your local Microsoft subsidiary. There is no-charge for support calls that are associated with security updates. When you call, clearly state that your problem is related to a Security Update and cite the update's KB number (e.g., KB9999...

Spam question
I'm not sure if this is the right group for posting this question, but since Outlook XP is my default client, I thought I'd start here. As many do, I get a ton of spam, but I've noticed the send to address isn't correct. Let's say I'm "sunbeam@whatever.net." I get mail with a single addressee to sunbalm, sunshine, sunbreath, etc. How does this happen and is there any way in Outlook XP to restrict the mail I receive to my specific address? mb http://www.slipstick.com/rules/junkmail.htm might be helpful. "moonbone" <relax@home.com> w...

Uninstalling PowerShell in Vista Home to upgrade to Vista Ultimate
I have Vista Home on a Dell studio laptop. I have just reinstalled this after a HD replacement. I am trying to upgrade to Vista Ultimate. A Compatibility check during the start of the upgrade says to uninstall Windows PowerShell. I went to the microsoft support site for guidance. I am unable to see PowerShell or its KB in the list of installed updates as the guidance said I should see. Hence, I am unable to select it to uninstall. The list of installed updates only says "Update for Microsoft Windows" or "Hotfix for Microsoft Windows." How can I get it to show ...

Simple Date/Time Macro
ActiveCell.FormulaR1C1 = "9/16/2009" Range("B1").Select ActiveCell.FormulaR1C1 = "9:25 AM" Range("C1").Select End Sub I want to set up a simple workbook that enters the above information on the current line in the sheet. When I recorded the keystrokes I wanted, I ended up with the following macro, which only works once. Starting with the second line, running the macro puts the date in the right place, skips Column B and then leaves the cursor in R1C1. How do I get this macro to enter all the information on the current line (date in c...

Windows Explorer doesn't show keywords
When I use Windows Explorer to navigate and search through my files (using the View - choose details - keywords and other selections) I can't see the keywords - even though they are part of the file (can view in file properties). I can see the Author, Title, Subject, Category, Comments - everything that is in the file properties except keywords. Is there a setting I'm not selecting? -- David C. Beveridge -------- Original-Nachricht -------- > When I use Windows Explorer to navigate and search through my files (using > the View - choose details - keywords a...

Outlook Mail not working with Windows 7
I have Windows 7 Home Premium (64 Bit) and Office 2003 Pro. I setup my POP3 e-mail account and was able to send and receive mail once. I setup a second POP3 account and neither will work. I installed Outlook 2007 with the same result. From what I have read, the 32 bit OS does not have this problem. So far, no one has been able to come up with a work around for this. Any help will be appreciated. Its nothing to do with win32/64 When you test the accounts within Outlook, you should if theres a problem see some relevent err msgs "ernie146nn" <ernie146nn@discussions...

windows 98 computer, running Office 2000, I deleted Outlook.pst thru windows explorer.
Please help, Outlook stoped recieving emails and said the problem was the Outlook.pst file. 1st. I tried reloading Office 2000 "did not help" 2nd. I deleted the Outlook.pst file on my windows 98 Computer running Office 2000 thru windows explorer The file was too large for the recycle bin and I chose delete. 3rd. Then I tried re installing office 2000 again and it did not reinstall the "outlook.pst file" Now I know that all my emails were in that .pst I have tried FINAL DATA 2.0 recovery software thru another hard drive and had no success finding the .pst file, where ...

Windows recovery console
How can I stop Windows Recovery Console coming up at Windows startup. There are a number of StartUp folders and none of them list WRC In news:%23qYZva4QLHA.4960@TK2MSFTNGP05.phx.gbl, tatar typed on Tue, 24 Aug 2010 13:20:08 +0100: > How can I stop Windows Recovery Console coming up at Windows startup. > There are a number of StartUp folders and none of them list WRC You have added the Windows Recovery Console to your HDD? Anyway to change the default boot OS all you need to do is: Control Panel System Advanced (tab) Startup and Recovery (Settings) Default operatin...

Pictures disappear over time
A website will download an excel file that is embedded in an IE window. I save that file as type .xls. For about a week, the pictures in the Excel file will display. After that, the pictures no longer display. How do I get the pictures that support the Excel document to save in a location where they aren't deleted over time? I've tried changing the web properties option to not put files in a sub folder, but when I save in Excel, the picture files aren't where I can find them. Also, if I save the file as .htm instead of .xls, I get a folder with images in it in the same fo...

crystal report question 05-04-04
Hi, is it possible to use my own sql statement to build the crystal reports in crm 1.2? I want to use some functions i.e. count(*) to add some statistic on the reportings. Thanks in advance Jani ...

difference between window dimensions and window client area dimensions
I need to find the difference between window dimensions and window client area dimensions for an SDI application. Currently I'm using the brute force method: CRect clientRect; GetClientRect(&clientRect); CRect mainRect; GetWindowRect(&mainRect); int frameExtraX = mainRect.Width() - clientRect.Width(); int frameExtraY = mainRect.Height() - clientRect.Height(); This is ugly and doesn't always work, so I would like to get frameExtraX and frameExtraY from some kind of system metrics values. Thank you! You've already said the magic words "system metrics&q...

windows messenger/Outlook 2002
Hello........i am running office xp 2002 on windows xp professional and every time that i open up outlook 2002, windows messgenger 6.0 opens up...windows messenger is not even on the list of programs automatically set to open up on the Start up programs tab...can anybody help and tell why this is happening?....thanks...Rolf disable messenger integration on tools, options, other Renegade wrote: > Hello........i am running office xp 2002 on windows xp > professional and every time that i open up outlook 2002, > windows messgenger 6.0 opens up...windows messenger is > not e...

Windows update error
I get the follow messege when i try and run a windows update. Files required to use Windows Update are no longer registered or installed on your computer. To continue: Register or reinstall the files for me now (Recommended) Let me read about more steps that might be required to solve the problem What to thye mean by redister or reinstall filles. How do i do it? Adam wrote: > I get the follow messege when i try and run a windows update. > > Files required to use Windows Update are no longer registered or > installed on your computer. To continue: > > ...

how to transfer email from window xp to window 7
wOULD ANY ONE PLS LET ME KNOW THE STEPS OF HOW I COULD TRANSFER EMAIL MESSAGES FROM OUTLOOK EXPRESS TO WINDOW 7 VERSION You don't do it through Microsoft Word, the topic of this newsgroup. "Dummies for win7" <Dummies for win7@discussions.microsoft.com> wrote in message news:0DF468BF-FEE6-4BDD-8292-38000059C489@microsoft.com... : wOULD ANY ONE PLS LET ME KNOW THE STEPS OF HOW I COULD TRANSFER EMAIL : MESSAGES FROM OUTLOOK EXPRESS TO WINDOW 7 VERSION ...

Macro to record user name and date/time
Is it possible to record a macro that when someone on the network opens my workbook that it records the user's name, time and date on a hidden protected worksheet? Can this then be expanded further by if the user then changes something, either adds, modify, or delete information from my workbook then the user's name, date, time and changes (including worksheet name, cell co-ordinates (i.e. A1) and information modified from and modified too) are recorded on a hidden protected worksheet? Thanx in advance. Maddoktor ...