Author Posts

July 17, 2015 at 5:00 am

Hi, I am constantly getting an error about the RPC server unavailable. Can you tell me what is wrong with the code on either the XML document or the ps1 script?

Xml Document:

'12.10.10.4'
"DeviceID='E:'"
"backup_server_1"

'12.10.10.5'
"DeviceID='E:'"
"backup_server_2"

Script (I will change it to objects at some point but for now just to get it working is key for me)
`
[xml]$configFile = Get-Content "C:\_x\config.xml"

$ConvertToGB = (1024 * 1024 * 1024)

"Server" + "," + "DriveLetter" + "," + "SitesHosted" + "," + "Size" + "," + "Free"

foreach($config in $configFile.config.Server)
{
$disk = Get-WmiObject Win32_LogicalDisk -ComputerName $config.ip_address -Filter $config.partition | Select-Object Size,FreeSpace
$config.ip_address + $config.partition + $config.host_example + ([math]::round(($disk.Size / $ConvertToGB),2)) + "GB" + "," + ([math]::round((($disk.FreeSpace / $ConvertToGB)),2)) + "GB"
}
`

July 17, 2015 at 5:13 am

having trouble pasting my xml document...
but xml is like the following

config
server
within server
there is
ip_address
partition
and hostname which is a description

July 17, 2015 at 5:20 am

RPC server unavailable means that WMI can't make contact with the remote server. Either because it doesn't recognise what you are trying to pass as the computername/IP address or because DCOM is disabled on the remote machine (check the Windows firewall – it blocks DCOM by default)

I'd use a CSV file rather than XML for this as you can read the CSV file and each row becomes an object

Your script is needlessly complicated – see the comments on your previous post

July 17, 2015 at 5:44 am

You also need to add error handling in your script. If a computer is offline or WMI can't connect, you should account for that:

foreach($config in $configFile.config.Server) {
    if (Test-Connection -ComputerName $config.ip_address -Count 2 -Quiet) {
        try {
            $disk = Get-WmiObject Win32_LogicalDisk -ComputerName $config.ip_address -Filter $config.partition -ErrorAction Stop | Select-Object Size,FreeSpace
            $config.ip_address + $config.partition + $config.host_example + ([math]::round(($disk.Size / $ConvertToGB),2)) + "GB" + "," + ([math]::round((($disk.FreeSpace / $ConvertToGB)),2)) + "GB"
        }
        catch {
            "There was a problem getting WMI information from {0}. {1}" -f $config.ip_address, $_.Exception.Message

        }

    }
    else {
        "{0} could not be reached (i.e. PINGed)" -f $config.ip_address
    }    
}

July 17, 2015 at 6:12 am

Thanks Rob and also Richard.

Another question, what if I wanted to add a status if the gigs are say over 15 gigs?
e.g.
if over 15 gigs, it is "OK"
if it is less than 15 gigs then "Warning"
else below 10 gigs is "Critical"

July 17, 2015 at 6:18 am

I would suggest searching for "Powershell Storage Report". There are a plethora of examples on how to get storage information from servers with threshold indications like you are asking