Here is my dilemma. I want to get a report of logical diskspace on a vm in a cluster environment – if I run:
$b += Get-WMIObject Win32_LogicalDisk -filter “DriveType=3″ -Computername (Get-Content c:\scripts\servers.txt) | Select SystemName,DeviceID,@{Name=â€size(GB)â€; Expression={“{0:N1}†-f($.size/1gb)}},@{Name=â€freespace(GB)â€;Expression={“{0:N1}†-f($.freespace/1gb)}} |ConvertTo-HTML -Fragment -PreContent “<h2> Logical Disk Space </h2>†|
out-string
I get the necessary information, however, I need to always update the “servers.txt†file – what if I happen to move a vm from one host to another? I know I can run this on each host, but then I still need to update the “servers.txt†file on each host.
I have tried -computer $vms with a variable being $vms = get-vm | sort name – but this comes back with RPC server unavailable.
The problem with your get-vm | sort name command is that Get-VM doesn’t return computer names, it returns VM objects. The -ComputerName parameter doesn’t know what to do with that. Sorting them on the Name property doesn’t change the fact that it’s a VM object.
Get-VM | Select -Expand Name
Will extract the contents of the Name property and return a collection of String objects, which is what -computername will accept. Assuming your “Name” property does indeed contain the computer names of the VMs.
error message
PS C:\scripts\report> .\testreport.ps1 testreportout.htm
Get-WMIObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\scripts\report\testreport.ps1:64 char:7
PS C:\scripts\report> .\testreport.ps1 testreportout.htm
Get-WMIObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\scripts\report\testreport.ps1:64 char:7
RPC server unavailable means you’re not connecting to the WMI service on the remote computer. Likely a firewall problem, assuming the computer name is correct. You also need to ensure that the computer names are resolvable by your client computer.
For example, just because the VM is named “Joe’s Computer” doesn’t mean the guest OS is using “JOE’S COMPUTER” as its computer name, which is what gets registered with DNS. In other words, VM name does not necessarily equal computer name.
But I can’t tell what’s in $VMS. If it isn’t a collection of strings, then it won’t work.
If this is a VMware environment you may also want to consider gathering your disk information through VMWares powerCLI. I find it much less invasive than making WMI requests to every individual PC, much more likely to succeed also.
If you assign a variable to your VM objects:
$VMs = Get-VM
You can loop through and gather disk information based on the extensionData properties, here’s an example:
I’m not sure where we’re at. As I mentioned, the name of a VM is not necessarily its computer name (DNS) on the network. If you’re getting “RPC Server Not Found” errors, then it’s because WMI was either (a) unable to resolve the name to an IP address via DNS or (b) unable to connect to the WMI service on the machine - possibly because of a firewall. What you’re doing to retrieve the VM names is correct. You need to resolve the name resolution and/or network connectivity and/or firewall access.