Gwith

try/catch

May 22nd, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. try
  2. {
  3. $CS = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $Computer -ErrorAction Stop
  4. $BS = Get-WmiObject -Class Win32_Bios -ComputerName $Computer -ErrorAction Stop
  5. $OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computer -ErrorAction Stop
  6. }
  7. catch
  8. {
  9.  
  10. "$(get-date) - $computer failed the wmi call!" | out-file c:\errorlog.txt -Append
  11. $error[0].Exception.Message | out-file c:\errorlog.txt -Append
  12. break
  13. }
Advertisement
Add Comment
Please, Sign In to add comment