Hi All,
Hope everyone is having holiday time.
I am trying to get the disk and lun details of two serves using the script.
Server A has 5 drives and server B has 4. So i expect an output of 9 rows. 5 disks from Server A and 4 from B.
But my output is showing wrong results. Eg: There is no W drive for Server B. But its present in output. Can you please advise where did my append in array for wrong.
$vm="server1","server2"
$array1 =@()
foreach ($v in $vm)
{
$Win32_LogicalDisk = Get-WmiObject -Class Win32_LogicalDisk -computername $vm | Where-Object {($_.DeviceID -ne 'C:') -and ($_.DeviceID -ne 'T:') }
$Win32_LogicalDiskToPartition = Get-WmiObject -Class Win32_LogicalDiskToPartition -computername $vm
$Win32_DiskDriveToDiskPartition = Get-WmiObject -Class Win32_DiskDriveToDiskPartition -computername $vm
$Win32_DiskDrive = Get-WmiObject -Class Win32_DiskDrive -computername $vm
# Search the SCSI Lun Unit for the disk
$p= @{
Computer = ""
DeviceID = ""
SCSIBus = ""
SCSIPort = ""
SCSITargetId = ""
SCSILogicalUnit = ""
Size=""
FreeSpace=""}
$Win32_LogicalDisk |
ForEach-Object {
if ($_)
{
$LogicalDisk = $_
$LogicalDiskToPartition = $Win32_LogicalDiskToPartition |
Where-Object {$_.Dependent -eq $LogicalDisk.Path}
if ($LogicalDiskToPartition)
{
$DiskDriveToDiskPartition = $Win32_DiskDriveToDiskPartition |
Where-Object {$_.Dependent -eq $LogicalDiskToPartition.Antecedent}
if ($DiskDriveToDiskPartition)
{
$DiskDrive = $Win32_DiskDrive |
Where-Object {$_.__Path -eq $DiskDriveToDiskPartition.Antecedent}
if ($DiskDrive)
{
$p.Computer = $v
$p.DeviceID = $LogicalDisk.DeviceID
$p.SCSIBus = $DiskDrive.SCSIBus
$p.SCSIPort = $DiskDrive.SCSIsPort
$p.SCSITargetId = $DiskDrive.SCSITargetId
$p.SCSILogicalUnit = $DiskDrive.SCSILogicalUnit
$p.Size=[Math]::Round($DiskDrive.size / 1GB, 2)
$p.FreeSpace=[Math]::Round($LogicalDisk.FreeSpace / 1GB, 2)
$array1 += [PSCustomObject]$p
}
}
}
}
}
}