![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Error checking with WMI Lastreboot script I have the following script that I am working on creating to grab the last reboot day of all the machines on my network so I can watch for machines/users that might need a gentle nudge to reboot for patches to be installed. # define a string array variable that hold the computer names $machines = get-qadcomputer -searchroot "mydomain.com/Lancaster Computers" |Sort-Object name | foreach {$_.name} #Get Wmi Data for specific machine gwmi -Class Win32_OperatingSystem -errorAction "silentlyContinue" - ComputerName $Machines | select csname, @{n="LastBootUpTime";e={$_.converttodatetime($_.lastbootuptime)}} I get the following error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) At line 11, position 5 gwmi -Class Win32_OperatingSystem -errorAction "silentlyContinue" - ComputerName $Machines | I thought the -errorAction silentlycontinue would skip by errors. I guess I was wrong. Is there a way to get it to list the machine name, an error text message and then move on? TIA. Tim |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Error checking with WMI Lastreboot script "TimParker" <timpar@xxxxxx> wrote in message news:d6550cd5-0e03-44b5-a35e-b25c905da689@xxxxxx Quote: > I thought the -errorAction silentlycontinue would skip by errors. I > guess I was wrong. Is there a way to get it to list the machine name, > an error text message and then move on? > You could loop through the individual machines, and make use of the automatic variable $?, which tests whether a previous line is successful or not. (Using 'Trap' statements would also be a similar route) .... #--------------------------------- $Machines = (".","NoSuchMachine","localhost") foreach ($Machine in $Machines) { gwmi -Class Win32_OperatingSystem -errorAction "silentlyContinue" -ComputerName $Machine | select csname,@{n="LastBootUpTime";e={$_.converttodatetime($_.lastbootuptime)}} if (-not($?)){Write-Host "ERROR: $Machine `n$($error[0].ToString())"} } #--------------------------------- Output .... PS (1) > $Machines = (".","NoSuchMachine","localhost") PS (2) > foreach ($Machine in $Machines) { Quote: Quote: >> >> >> gwmi -Class Win32_OperatingSystem -errorAction >> "silentlyContinue" -ComputerName $Machin Quote: Quote: >> select >> csname,@{n="LastBootUpTime";e={$_.converttodatetime($_.lastbootuptime)}} >> >> if (-not($?)){Write-Host "ERROR: $Machine `n$($error[0].ToString())"} >> >> } >> ------ -------------- ABCD 19/06/2008 06:19:16 ERROR: NoSuchMachine The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) ABCD 19/06/2008 06:19:16 PS (3) > -- Jon |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re: Help required with file size checking script | VB Script | |||
| Inactive printer-checking script | PowerShell | |||
| Help with Powershell - Disk space checking script - New to PS | PowerShell | |||
| Send-FTP Script with Error Checking? | PowerShell | |||
| Re: checking for results when executing a script | PowerShell | |||