This script has the following Requirements:
- VI Toolkit
- Powershell
- WMI query
- Windows VM’s
The following script get al lists of all Windows VM’s which are powered on. The next step is a WMI query which queries the Win32_DiskPartition class. The final step is a match with the $StartingOffset variable.
Add-PSSnapIn VMware.VimAutomation.Core
# Connect to vCenter
$VC = Connect-VIServer (Read-Host "Enter vCenter server")
$StartingOffset = "65536"
# Get all VM’s with powerstate = PoweredOn
$VMS = Get-VM | Where {$_.PowerState -eq "PoweredOn"} |Sort Name
ForEach ($VM in $VMS)
{
# Process only Windows Server VM’s
if ($VM.Guest.OSFullName -match "Microsoft Windows*")
{
# Do a WMI Query
$results = get-wmiobject -class "Win32_DiskPartition" -namespace "root\CIMV2" -ComputerName $VM
foreach ($objItem in $results)
{
# Do the match
if ($objItem.StartingOffset -match $StartingOffset){
write-host $objItem.SystemName
write-host $objItem.Name
write-host "Partition aligned" -foregroundcolor green
write-host}
else{
write-host $objItem.SystemName
write-host $objItem.Name
write-host "Partition NOT aligned" -foregroundcolor red
write-host
}
}
}
}
# Disconnect from vCenter
Disconnect-VIServer -Confirm:$False
after running the script, the following output will be generated:
great script.
it would be nice if it will output an excel or xml file.
but hey, i am the script noob here.
Nice script. Am getting a “The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)” attempting to run however. during the WMI query..
I’m getting similar
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x80070
6BA)
At C:\Test.ps1:15 char:21
+ $wmi = get-wmiobject <<<< -class "Win32_DiskPartition" -namespace "root\CIMV
2" -ComputerName $vm
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMExcept
ion
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands
.GetWmiObjectCommand
Funny, i was writing a very similar script and troubleshooting out he RPC server issue when I ran into this. Would’ve saved me a bit of time! I like it.
I am writing mine to be a csv generator for reporting.
The RPC error issue was in my case resovled by adding the “remote management” check box on the targeted server / desktop if the firewall was anabled or disabling the firewall. (this is in my lab, so limited cases.