VMware Cloud Community
AsianFlowerGirl
Contributor
Contributor
Jump to solution

Hello, I have some question for "POWER-CLI"

Hello~ Benevolent Super Power-cliers~

I have some question.

Firstly, I don't have good english skill.

If I mentioned strange words, please understand.

My goal is search several disks's "DiskName", "SCSI Target Number", "connected SCSI Controller's PCI Slot Number"

But this code print only '1' Hard Disk.

I want '2' more Hard Disk's information.

Please modify my code.

---------------------------------------------------------------------------------

$VM = get-vm "rhel72disktest"
$IP = $VM.Guest.IpAddress | where {([IPAddress]$_).AddressFamily -eq [System.Net.Sockets.AddressFamily]::InterNetwork}
$Username = 'root'
$Password = 'dlatl123#'
$Pass = ConvertTo-SecureString -AsPlainText $Password -Force
$SecureString = $Pass
$MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$SecureString
$VMSummaries = @()
$DiskMatches = @()
$request_count = 2
$DiskID = @('Hard Disk 12','Hard Disk 3')      # This is Hard Disk Name on vCenter
$vm_devpath = @()
$CompairVariable = 0

$VMView = $VM | Get-View
$VirtualSCSIController_all = $VMView.Config.Hardware.Device | Where {$_.DeviceInfo.Label -match "SCSI"}

    ForEach ($VirtualSCSIController in ($VMView.Config.Hardware.Device | Where {$_.DeviceInfo.Label -match "SCSI"}))
        {
        ForEach ($VirtualDiskDevice  in ($VMView.Config.Hardware.Device | Where {$_.ControllerKey -eq $VirtualSCSIController.Key}))
            {
                $VMSummary = "" | Select VM, HostName, PowerState, DiskFile, DiskName, DiskSize, SCSIController, SCSITarget
                $VMSummary.VM = $VM.Name
                $VMSummary.DiskName = $VirtualDiskDevice.DeviceInfo.Label
                $VMSummary.DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB
                $VMSummary.SCSIController = $VirtualSCSIController.BusNumber
                $VMSummary.SCSITarget = $VirtualDiskDevice.UnitNumber
                $VMSummaries += $VMSummary

                if($VirtualDiskDevice.DeviceInfo.Label -match $DiskID[$request_count])
                    {
                        $CompairVariable = $VMSummary.SCSIController
                        $VMSummary.SCSITarget                   
                        $DiskID
                        $VirtualSCSIController_all[$CompairVariable].SlotInfo
                    }                               
             }                                                 
         }
       

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this.
The Where clause on the 2nd ForEach now also checks if the harddisk has a label that is defined in the array $DiskId

PS: I took out all lines that don't really have a purpose in the script.

$VM = Get-VM "rhel72disktest"

$VMSummaries = @()

$DiskID = @('Hard Disk 12','Hard Disk 3')   # This is Hard Disk Name on vCenter


$VMView = $VM | Get-View


ForEach ($VirtualSCSIController in ($VMView.Config.Hardware.Device | Where {$_.DeviceInfo.Label -match "SCSI"}))

{

   ForEach ($VirtualDiskDevice  in

   ($VMView.Config.Hardware.Device |

   Where {$_.ControllerKey -eq $VirtualSCSIController.Key -and $DiskID -contains $_.DeviceInfo.Label}))

  {

   $VMSummary = "" | Select VM, HostName, PowerState, DiskFile, DiskName, DiskSize, SCSIController, SCSITarget

   $VMSummary.VM = $VM.Name

   $VMSummary.DiskName = $VirtualDiskDevice.DeviceInfo.Label

   $VMSummary.DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB

   $VMSummary.SCSIController = $VirtualSCSIController.BusNumber

   $VMSummary.SCSITarget = $VirtualDiskDevice.UnitNumber

   $VMSummaries += $VMSummary

  }

}


$VMSummaries


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

View solution in original post

5 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this.
The Where clause on the 2nd ForEach now also checks if the harddisk has a label that is defined in the array $DiskId

PS: I took out all lines that don't really have a purpose in the script.

$VM = Get-VM "rhel72disktest"

$VMSummaries = @()

$DiskID = @('Hard Disk 12','Hard Disk 3')   # This is Hard Disk Name on vCenter


$VMView = $VM | Get-View


ForEach ($VirtualSCSIController in ($VMView.Config.Hardware.Device | Where {$_.DeviceInfo.Label -match "SCSI"}))

{

   ForEach ($VirtualDiskDevice  in

   ($VMView.Config.Hardware.Device |

   Where {$_.ControllerKey -eq $VirtualSCSIController.Key -and $DiskID -contains $_.DeviceInfo.Label}))

  {

   $VMSummary = "" | Select VM, HostName, PowerState, DiskFile, DiskName, DiskSize, SCSIController, SCSITarget

   $VMSummary.VM = $VM.Name

   $VMSummary.DiskName = $VirtualDiskDevice.DeviceInfo.Label

   $VMSummary.DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB

   $VMSummary.SCSIController = $VirtualSCSIController.BusNumber

   $VMSummary.SCSITarget = $VirtualDiskDevice.UnitNumber

   $VMSummaries += $VMSummary

  }

}


$VMSummaries


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

AsianFlowerGirl
Contributor
Contributor
Jump to solution

Thank you for your advise LucD !!

I have one more question.

After running your scripts, I can see many parameters of 'Hard Disk #'

Especially, Among them I want see 'DiskName', 'SCSIController' and 'SCSITarget' gradually.

But Now, I can check as follows :

-------------------------------------------------------

VM             : rhel72disktest
HostName       :
PowerState     :
DiskFile       :
DiskName       : Hard Disk 3
DiskSize       : 17179869184
SCSIController : 0
SCSITarget     : 2

VM             : rhel72disktest
HostName       :
PowerState     :
DiskFile       :
DiskName       : Hard Disk 12
DiskSize       : 17179869184
SCSIController : 0
SCSITarget     : 12

---------------------------------------------------------

So, I edit this code.

---------------------------------------------------------

$VMSummaries → $VMSummaris.DiskName

                           → $VMSummaris.SCSIController

                           → $VMSummaris.SCSITarget

----------------------------------------------------------

I want see as follow:

-----------------------------------------------------------

Hard Disk 3

0        # SCSIController Address

2        # SCSITarget Address

Hard Disk 12

0

12

-----------------------------------------------------------

But, This source is displayed

-----------------------------------------------------------

Hard Disk 3

Hard Disk 12

0

0

2

12

-----------------------------------------------------------

How can I check what I want?

And.... I have one more request....

I want see displayed SCSIController's PCI Slot Number.

Can you give me some advise?

-----------------------------------------

(Example)

Hard Disk 3

0        # SCSIController Address

2        # SCSITarget Address

160    # SCSIController's PCI Slot Number

Hard Disk 12

0

12

224

------------------------------------------

I'm much obliged to you for your help.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You mean like this?

$VM = Get-VM "rhel72disktest"

$VMSummaries = @()


$DiskID = @('Hard Disk 12','Hard Disk 3')   # This is Hard Disk Name on vCenter

$VMView = $VM | Get-View


ForEach ($VirtualSCSIController in ($VMView.Config.Hardware.Device | Where {$_.DeviceInfo.Label -match "SCSI"}))

{

   ForEach ($VirtualDiskDevice  in

   ($VMView.Config.Hardware.Device |

   Where {$_.ControllerKey -eq $VirtualSCSIController.Key -and $DiskID -contains $_.DeviceInfo.Label}))

  {

   $VMSummary = "" | Select VM, HostName, PowerState, DiskFile, DiskName, DiskSize, SCSIController, SCSITarget, SCSIPCISlot

   $VMSummary.VM = $VM.Name

   $VMSummary.DiskName = $VirtualDiskDevice.DeviceInfo.Label

   $VMSummary.DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB

   $VMSummary.SCSIController = $VirtualSCSIController.BusNumber

   $VMSummary.SCSITarget = $VirtualDiskDevice.UnitNumber

   $VMSummary.SCSIPCISlot = $VirtualSCSIController.SlotInfo.PciSlotNumber

   $VMSummaries += $VMSummary

  }

}


$VMSummaries | %{

   $_.DiskName

   $_.SCSIController

   $_.SCSITarget

   $_.SCSIPCISlot

}


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

AsianFlowerGirl
Contributor
Contributor
Jump to solution

OH !!!!!

Exactly~!!!!!

Thank you very much !!

Can you allow I called you my master?? (= In Korean, This is called SABU-NIM)

Thank you LucD, Thank you!

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You're welcome Smiley Happy


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

Reply
0 Kudos