VMware Cloud Community
chakoe
Enthusiast
Enthusiast

Script for reporting partition-offset in Windows-Guests

Hi,

i have some Windows-Guests residing in a huge Cluster. These VM´s should be migrated from SAN to NFS, but we have to ensure, that only VM´s with an Disk-Offset ( Diskpart ) divisible by 4 ( named " aligned" ) are migrated.

So i need a Report to see, which VM´s ( Guests ) are already aligned ( so i only have to do a StoragevMotion) and which are not...

If i do it manually, it will take hours to check every VM, but it will work like this:

logon to the VM, start diskpart -> sel disk 0 -> list part ->decision by output-value " offset"

Any idea?

Thx in advance

Chakoe

0 Kudos
44 Replies
chakoe
Enthusiast
Enthusiast

strange....seems to be working on an XP SP2 32-Bit 🙂

but:

the client i have to use to run the script is in another domain than some of our ( virtual ) servers....is it possible to provide some credentials

( or a credential-file which contains my user-name and password ) ?

0 Kudos
LucD
Leadership
Leadership

Try running the script from a 32-bit session on the W2K8 server.

If you mean the Get-WmiObject cmdlet, you can use the Credentials parameter.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
chakoe
Enthusiast
Enthusiast

Good morning,

my script ( running on my XP 32-Bit SP2 ) actually looks like:

###############

$credential = Get-Credential myDom\UserAcc

Get-Cluster D100CP09 | Get-VM * | Sort-Object $_.Name |
where {(Get-Datastore -VM $_).Type -eq "NFS" -and $_.Guest.State -eq "Running" -and ($_.Guest.GuestId -match "win" ) } | %{
$temp = $_.Guest.Hostname
     $Startingoffset = (Get-WmiObject Win32_DiskPartition -Credential $credential -ComputerName $temp).Startingoffset
 
     if (($Startingoffset % 1KB) -ne 0) { Write-Host $_.Guest.Name "is not 1KB aligned" }
}

################

But now I´, getting the following error on every VM (  the provided Credential has local Admin-rights on the target VM´s )

Get-WmiObject : Access denied (Ausnahme von HRESULT: 0x80070005 (E_ACCESSDENIED))
At C:\Dokumente und Einstellungen\j131670\Lokale Einstellungen\Temp\55e3eb31-b368-46a0-ab81-d3951229e4d5.ps1:10 char:38
+      $Startingoffset = (Get-WmiObject <<<<  Win32_DiskPartition -Credential $credential -ComputerName $temp).Startingof
fset
    + CategoryInfo          : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
Edt: I´ve chose another cluster and in this Cluster, there are only VM´s on NFs, but those might be misaligned too....
0 Kudos
chakoe
Enthusiast
Enthusiast

I got it!!  Smiley Happy

Set-PowerCLIConfiguration -DefaultVIServerMode single -ProxyPolicy NoProxy -Confirm:$false Set-PowerCLIConfiguration -ProxyPolicy NoProxy -Confirm:$false      clear      Write-Host "################################" Get-Cluster D100CP05 | Get-VM * | Sort-Object $_.Name |                  where {(Get-Datastore -VM $_).Type -eq "VMFS" -and $_.Guest.State -eq "Running" -and $_.Guest.GuestId -match "win" -and $_.Name -match "SRVM"  } | %{      $temp = $_.Guest.Hostname            $offset_d0p0 = Get-WmiObject  Win32_DiskPartition -ComputerName $temp  | where {$_.Name -eq "Datenträger Nr. 0, Partition Nr. 0" }  | Select Startingoffset      $offset_d1p0 = Get-WmiObject  Win32_DiskPartition -ComputerName $temp  | where {$_.Name -eq "Datenträger Nr. 1, Partition Nr. 0" }  | Select Startingoffset      $offset_d2p0 = Get-WmiObject  Win32_DiskPartition -ComputerName $temp  | where {$_.Name -eq "Datenträger Nr. 2, Partition Nr. 0" }  | Select Startingoffset      $offset_d3p0 = Get-WmiObject  Win32_DiskPartition -ComputerName $temp  | where {$_.Name -eq "Datenträger Nr. 3, Partition Nr. 0" }  | Select Startingoffset            if ($offset_d0p0.Startingoffset -eq  "32256")   { Write-Host $temp "Disk:0 Part:0 ist 32KB aligned. Alinging OK ! " -BackgroundColor Black -ForegroundColor Green }      if ($offset_d0p0.Startingoffset -eq  "1048576") { Write-Host $temp "Disk:0 Part:0 ist 1024KB aligned. Alinging OK ! " -BackgroundColor Black -ForegroundColor Green }      if ($offset_d0p0.Startingoffset -eq  "8225280") { Write-Host $temp "Disk:0 Part:0 ist 8033KB aligned, NICHT OK ! " -BackgroundColor Black -ForegroundColor Red }            if ($offset_d1p0.Startingoffset -eq  "32256")   { Write-Host $temp "Disk:1 Part:0 ist 32KB aligned. Alinging OK ! " -BackgroundColor Black -ForegroundColor Green }      if ($offset_d1p0.Startingoffset -eq  "1048576") { Write-Host $temp "Disk:1 Part:0 ist 1024KB aligned. Alinging OK ! " -BackgroundColor Black -ForegroundColor Green }      if ($offset_d1p0.Startingoffset -eq  "8225280") { Write-Host $temp "Disk:1 Part:0 ist 8033KB aligned, NICHT OK ! " -BackgroundColor Black -ForegroundColor Red }            if ($offset_d2p0.Startingoffset -eq  "32256")   { Write-Host $temp "Disk:2 Part:0 ist 32KB aligned. Alinging OK ! " -BackgroundColor Black -ForegroundColor Green }      if ($offset_d2p0.Startingoffset -eq  "1048576") { Write-Host $temp "Disk:2 Part:0 ist 1024KB aligned. Alinging OK ! " -BackgroundColor Black -ForegroundColor Green }      if ($offset_d2p0.Startingoffset -eq  "8225280") { Write-Host $temp "Disk:2 Part:0 ist 8033KB aligned, NICHT OK ! " -BackgroundColor Black -ForegroundColor Red }      if ($offset_d3p0.Startingoffset -eq  "32256")   { Write-Host $temp "Disk:3 Part:0 ist 32KB aligned. Alinging OK ! " -BackgroundColor Black -ForegroundColor Green }      if ($offset_d3p0.Startingoffset -eq  "1048576") { Write-Host $temp "Disk:3 Part:0 ist 1024KB aligned. Alinging OK ! " -BackgroundColor Black -ForegroundColor Green }      if ($offset_d3p0.Startingoffset -eq  "8225280") { Write-Host $temp "Disk:3 Part:0 ist 8033KB aligned, NICHT OK ! " -BackgroundColor Black -ForegroundColor Red }            Write-Host "################################"       }

Now i only have to check why I´m getting an RPC-Error on some VM´s  ( RPC-Server not avaiable ), there might be Problem with the firewalls...

0 Kudos
chakoe
Enthusiast
Enthusiast

So:

the acutal error is:

Get-WmiObject : Access denied (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Bei \\v998spwmv10175n\d$\VCenter-Skripte\Check_alignging\Check_Aligning_ZiZo-Cluster.ps1:20 Zeichen:30
+     $offset_d3p0 = Get-WmiObject <<<<   Win32_DiskPartition -ComputerName $temp -Credential $credential  | where {$_.Name -eq "Datenträger Nr. 3, Partition Nr. 0" }  | Select Starting
offset
    + CategoryInfo          : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Even if i provide the Credentials  ( $credential = Get-Credential ..... ) and then use the $credential in the Get-WmiObject.....

Doesn´t matter if i provide an local-admin-account for the target VM´s or if i use a Domain-Admin-User...

is there another special way to configure the authentication?

0 Kudos