Hi,
I'm looking for a way to get the following field in a csv file
Controller, channel, diskName,vmdk,vm
For now I have:
Connect-VIServer localhost | Out-Null
$VMs = Get-VM SEQDEV7 | Get-View
ForEach ($VM in $VMs) {
If($VM) {
Foreach ($SCSI_Controller in ($VM.Config.Hardware.Device | where {$_.DeviceInfo.Label -like "SCSI*"} )) {
Write-Host $SCSI_Controller.DeviceInfo.Label
Foreach ($Disk_Key in $SCSI_Controller.Device) {
Foreach ($Disk_Device in ($VM.Config.Hardware.Device | where {$_.key -eq $Disk_Key } )) {
Write-Host " " $Disk_Device.UnitNumber : $Disk_Device.DeviceInfo.Label : $Disk_Device.Backing.Filename
}
}
}
}
}
$DiskPort | Export-Csv -NoTypeInformation -Path C:\Users\malabelle\Desktop\tests\test-scsi-ide.csv
ForEach ($VM in $VMs) {
If($VM) {
Foreach ($SCSI_Controller in ($VM.Config.Hardware.Device | where {$_.DeviceInfo.Label -like "IDE*"} )) {
Write-Host $SCSI_Controller.DeviceInfo.Label
Foreach ($Disk_Key in $SCSI_Controller.Device) {
Foreach ($Disk_Device in ($VM.Config.Hardware.Device | where {$_.key -eq $Disk_Key } )) {
Write-Host " " $Disk_Device.UnitNumber : $Disk_Device.DeviceInfo.Label : $Disk_Device.Backing.Filename
}
}
}
}
}
Which gives me
SCSI controller 0
0 : Hard disk 1 : [TEST_Sequence_Dev] SEQDEV7/SEQDEV7.vmdk
1 : Hard disk 2 : [TEST_Sequence_Dev] SEQDEV7/SEQDEV7_2.vmdk
SCSI controller 1
14 : Hard disk 3 : [TEST_Sequence_Dev] SEQDEV7/SEQDEV7_3.vmdk
IDE 0
IDE 1
0 : CD/DVD Drive 1 : [TEST150A] ISO/pe-defrag-directboot.iso
Any idea?
I did a major rewrite of your script to do it in a more PowerShell way of doing things. I think the next script will give you the desired result:
Connect-VIServer localhost | Out-Null Get-VM | ForEach-Object { $VM = $_ $VM.ExtensionData.Config.Hardware.Device | ` Where-Object {$_.DeviceInfo.Label -like "SCSI*" -or $_.DeviceInfo.Label -like "IDE*"} | ` ForEach-Object { $SCSI_Controller = $_ $SCSI_Controller.Device | ForEach-Object { $Disk_Key = $_ $VM.ExtensionData.Config.Hardware.Device | ` Where-Object {$_.key -eq $Disk_Key} | ` ForEach-Object { $Disk_Device = $_ $Report = "" | Select-Object -Property Controller,Channel,Disk,Vmdk,VM $Report.Controller = $SCSI_Controller.DeviceInfo.Label $Report.Channel = $Disk_Device.UnitNumber $Report.Disk = $Disk_Device.DeviceInfo.Label $Report.Vmdk = $Disk_Device.Backing.Filename $Report.VM = $VM.Name $Report } } } } | Export-Csv -NoTypeInformation -Path C:\Users\malabelle\Desktop\tests\test-scsi-ide.csv
Regards, Robert
I did a major rewrite of your script to do it in a more PowerShell way of doing things. I think the next script will give you the desired result:
Connect-VIServer localhost | Out-Null Get-VM | ForEach-Object { $VM = $_ $VM.ExtensionData.Config.Hardware.Device | ` Where-Object {$_.DeviceInfo.Label -like "SCSI*" -or $_.DeviceInfo.Label -like "IDE*"} | ` ForEach-Object { $SCSI_Controller = $_ $SCSI_Controller.Device | ForEach-Object { $Disk_Key = $_ $VM.ExtensionData.Config.Hardware.Device | ` Where-Object {$_.key -eq $Disk_Key} | ` ForEach-Object { $Disk_Device = $_ $Report = "" | Select-Object -Property Controller,Channel,Disk,Vmdk,VM $Report.Controller = $SCSI_Controller.DeviceInfo.Label $Report.Channel = $Disk_Device.UnitNumber $Report.Disk = $Disk_Device.DeviceInfo.Label $Report.Vmdk = $Disk_Device.Backing.Filename $Report.VM = $VM.Name $Report } } } } | Export-Csv -NoTypeInformation -Path C:\Users\malabelle\Desktop\tests\test-scsi-ide.csv
Regards, Robert
Wow thanks alot.