Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Error checking with WMI Lastreboot script

Reply
 
Old 06-18-2008   #1 (permalink)
TimParker


 
 

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 SpecsSystem Spec
Old 06-19-2008   #2 (permalink)
Jon


 
 

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
e |
Quote:
Quote:

>> select
>> csname,@{n="LastBootUpTime";e={$_.converttodatetime($_.lastbootuptime)}}
>>
>> if (-not($?)){Write-Host "ERROR: $Machine `n$($error[0].ToString())"}
>>
>> }
>>
csname LastBootUpTime
------ --------------
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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46