Author Posts

November 15, 2013 at 1:49 pm

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 “

Logical Disk Space

” |
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.

Your help is much appreciated.

Signed,

powershell newbie

November 16, 2013 at 10:28 am

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.

November 16, 2013 at 10:43 am

Thanks Don!!! I will give this a try!!!

November 21, 2013 at 6:32 am

hmmmmm...I'm getting access-denied error 🙁

# Variables
$VMS = get-vm | Select -Expand Name

# VM Logical diskspace
# $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)}} |
$b += Get-WMIObject Win32_LogicalDisk -filter "DriveType=3" -computername $VMS | Select Name,DeviceID,@{Name="size(GB)"; Expression={"{0:N1}" -f($_.size/1gb)}},@{Name="freespace(GB)";Expression={"{0:N1}" -f($_.freespace/1gb)}} |
ConvertTo-HTML -Fragment -PreContent "

Logical Disk Space

" |
out-string

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
+ $b += Get-WMIObject Win32_LogicalDisk -filter "DriveType=3" -computername $VMS | ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Get-WMIObject : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At C:\scripts\report\testreport.ps1:64 char:7
+ $b += Get-WMIObject Win32_LogicalDisk -filter "DriveType=3" -computername $VMS | ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

November 21, 2013 at 7:08 am

changed code to the following:

$b += Get-WMIObject Win32_LogicalDisk -filter "DriveType=3" -computername $VMS -Authentication PacketPrivacy -Impersonation Impersonate | Select Name,DeviceID,@{Name="size(GB)"; Expression={"{0:N1}" -f($_.size/1gb)}},@{Name="freespace(GB)";Expression={"{0:N1}" -f($_.freespace/1gb)}} |

This works! however, I still get rpc unavailable

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
+ $b += Get-WMIObject Win32_LogicalDisk -filter "DriveType=3" -computername $VMS – ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Get-WMIObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\scripts\report\testreport.ps1:64 char:7
+ $b += Get-WMIObject Win32_LogicalDisk -filter "DriveType=3" -computername $VMS – ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Get-WMIObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\scripts\report\testreport.ps1:64 char:7
+ $b += Get-WMIObject Win32_LogicalDisk -filter "DriveType=3" -computername $VMS – ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

I guess I need to put in some checks...not sure. your help is much appreciated.

Thanks

November 21, 2013 at 8:25 am

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.

November 21, 2013 at 8:42 am

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:


$Disks = @()
Foreach ($VM in $VMs)
{
$DiskProperties = $VM.ExtensionData.Guest.Disk
$Disk = New-Object -TypeName PSObject
$Disk | Add-Member -MemberType NoteProperty -Name Server -Value $Server.Name
$Disk | Add-Member -MemberType NoteProperty -Name DriveLetter -Value $DiskProperties.DiskPath
$Disk | Add-Member -MemberType NoteProperty -Name 'Capacity(GB)' -Value ([math]::round(($DiskProperties.Capacity / 1GB), 2))
$Disk | Add-Member -MemberType NoteProperty -Name 'FreeSpace(GB)' -Value ([math]::round(($DiskProperties.FreeSpace / 1GB), 2))
$Disk | Add-Member -MemberType NoteProperty -Name PercentFree -Value ([math]::Round(($Disk.'Freespace(GB)' / $Disk.'Capacity(GB)') * 100))
$Disks += $Disk
}

You'll end up with a $Disks array that you can pipe into your ConvertTo-HTML piece and factor into your report.

PS. This is old code using the [math] for rounding, it could be cleaned up to use standard numerical formatting.

November 21, 2013 at 8:53 am

sorry Don, I didn't include the $vms

it is: $VMS = get-vm | Select -Expand Name

November 21, 2013 at 8:56 am

if I run the get-vm | Select -Expand Name on the host server I get:

PS C:\scripts\report> get-vm | Select -Expand name
APP01
CT-BI
CT-COMM
CTPDC01
DBT90
DWT90
TSD90
TST90
VMM
WEBT90

All servers..whether online or offline....DBT90 is off

December 3, 2013 at 7:27 am

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.