I modified this script(https://gallery.technet.microsoft.com/scriptcenter/Create-HTML-Uptime-and-68e6acc0) to hit multiple servers, but it doesn't generate a report even if only one of the systems are down. How do I modify the script to continue on errors and generate the report at the end? The error is:
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\Users\user\Desktop\CheckDiskSpaceDomain\GetDiskDriveSpaceDomain.ps1:19 char:25
+ $os = Get-WmiObject <<<< -class win32_OperatingSystem -cn $s
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
You cannot call a method on a null-valued expression.
At C:\Users\user\Desktop\CheckDiskSpaceDomain\GetDiskDriveSpaceDomain.ps1:21 char:51
+ uptime = (get-date) - $os.converttodatetime <<<< ($os.lastbootuptime)}
+ CategoryInfo : InvalidOperation: (converttodatetime:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Looks like you have the issue when you run get-wmiObject, after that call just write
-ErrorAction "Resume"
Looks like the $OS is actually the null-value so you might want to do something like this that will know if $s is null and make a decision of what to do:
if ($OS -ne $null){
$uptime = (get-date) - $os.converttodatetime
}
else {
write-host " OS is null"
}
For more info on error handeling :
Try using -erroraction silentlycontinue
User contributions licensed under CC BY-SA 3.0