VBScript user trying to learn PowerShell. Can someone help me on how I can just test if a machine responds to a wmi connect and get the error code?
vbscript example
Set objLoc = WScript.CreateObject("WbemScripting.SWbemLocator") Set objWmi = objLoc.ConnectServer(vServerName,DEFAULT_NAMESPACE,,,,,wbemConnectFlagUseMaxWait) If Err.Number Then 'wmi doesn't respond else 'wmi responds End if
I understand using the get-wmiobject but don't really need to see the full details, only if it connects or not. Doing this for a monitoring type of script.
Get-WmiObject Win32_LocalTime -computername server1 -ErrorVariable $myerror Trap [system.exception] {$z=$null;continue} write-host $myerror
Thanks a bunch --Todd
|