I figured I would share this since it may save somebody in the future. :)
This took me a solid week of work to figure out and put into SCORCH. It's not pretty but it saves me a ton of calls at night. I do have controls in place to make sure it does not expand more then a few times before calling me.
- I have two .Net Activity Modules running PowerShell with a Compare Values to make sure the SCSI IDs match.
- Frist script below pulls the SCSI ID from the Windows Machine.
- Second Script pulls SCSI ID from VMware to check it.
- I use the Compare Values to make sure they match before moving to the expand disk.
Hope this helps!
$z = Invoke-Command -ComputerName <ServerThatNeedsMoreRoom> -ScriptBlock {
### Incoming From SCORCH ####
$computerName = "<ServerThatNeedsMoreRoom>"
$driveLetter = "D"
$winDriveLetter = "$($driveLetter):"
#########
# Getting Disk Info from Windows Server
$LogicalDisk = Get-WmiObject -Class Win32_LogicalDisk | Where-Object {$_.DeviceID -like $winDriveLetter}
$Win32_LogicalDiskToPartition = Get-WmiObject -Class Win32_LogicalDiskToPartition
$Win32_DiskDriveToDiskPartition = Get-WmiObject -Class Win32_DiskDriveToDiskPartition
$Win32_DiskDrive = Get-WmiObject -Class Win32_DiskDrive
$LogicalDiskToPartition = $Win32_LogicalDiskToPartition | Where-Object {$_.Dependent -eq $LogicalDisk.Path}
$DiskDriveToDiskPartition = $Win32_DiskDriveToDiskPartition | Where-Object {$_.Dependent -eq $LogicalDiskToPartition.Antecedent}
$DiskDrive = $Win32_DiskDrive | Where-Object {$_.__Path -eq $DiskDriveToDiskPartition.Antecedent}
### For Troubleshooting ####
write-host "Testing"
$ts1 = $DiskDriveToDiskPartition.Antecedent
$ts2 = $DiskDrive
#### Export out of Invoke ####
[PSCustomObject]@{
'Computer' = $computerName
'DeviceID' = $LogicalDisk.DeviceID
'SCSIBus' = $DiskDrive.SCSIBus
'SCSIPort' = $DiskDrive.SCSIPort
'SCSITargetId' = $DiskDrive.SCSITargetId
'SCSILogicalUnit' = $DiskDrive.SCSILogicalUnit
'ts1' = $ts1
'ts2' = $ts2
}
}
# **** Output Here *****" #
$z.Computer
$SCSIIINFO = "$($z.SCSIBus.ToString()):$($z.SCSITargetId.ToString())"
#write-host "**** Internal Check *****"
#write-host $z.ts1
#write-host $z.ts2
#write-host " "
#write-host $z.DeviceID
## Incoming from SCORCH ####
$WSCSI = "<Carry Over SCSI ID from the Get Windows SCSI ID>"
$computerName = "<VM Name>"
Connect-VIServer –Server VCenterServer -username username1 -Password Password1 -SaveCredentials
$diskInfo= @()
$VMView = Get-VM $computerName | Get-View
foreach ($VirtualSCSIController in ($VMView.Config.Hardware.Device | Where-Object {$_.DeviceInfo.Label -match "SCSI Controller"}))
{
foreach ($virtualDiskDevice in ($VMView.Config.Hardware.Device | Where-Object {$_.ControllerKey -eq $VirtualSCSIController.Key}))
{
$virtualDisk = "" | Select-Object VMname, SCSIController, DiskName, SCSI_ID, DiskFile, DiskSize
$virtualDisk.VMname = $VMview.Name
$virtualDisk.SCSIController = $VirtualSCSIController.DeviceInfo.Label
$virtualDisk.DiskName = $virtualDiskDevice.DeviceInfo.Label
$virtualDisk.SCSI_ID = "$($VirtualSCSIController.BusNumber.ToString()):$($virtualDiskDevice.UnitNumber.ToString())"
$virtualDisk.DiskFile = $virtualDiskDevice.Backing.FileName
$virtualDisk.DiskSize = $virtualDiskDevice.CapacityInKB * 1KB / 1GB
if ($virtualDisk.SCSI_ID -eq $WSCSI) {
$disk_SCSI = $virtualDisk.SCSI_ID
$disk_Name = $virtualDiskDevice.DeviceInfo.Label
$disk_size = $virtualDisk.DiskSize
}
}
}
Disconnect-VIServer -Server VCenterServer -Force -Confirm:$false
$disk_SCSI
$disk_Name
$disk_size
