VMware Cloud Community
JFitchVMA
Enthusiast
Enthusiast
Jump to solution

Trying to list SCSI Controller type with Guest OS

I'm trying to pull a list using PowerCLI of each VM, the SCSI controller each has, and the OS it is running. I'm able to pull the data just fine, but the problem I'm running into is trying to export it with anything (html, csv, xml). Here is my script so far:

$vm = Get-View -ViewType VirtualMachine -Property @("Name", "Config.Hardware.Device", "Guest.GuestFullName") | Select-Object -Property Name, @{N="SCSI Controller"; E={($_.Config.Hardware.Device | where{$_.DeviceInfo.Label -match "SCSI"}).DeviceInfo.Summary}}, @{N="Running OS";E={$_.Guest.GuestFullName}}|Format-Table -Autosize -Wrap

The problem I'm running into is that when I try to do:

$vm | convetto-html

It exports what appears to be a GUID ID, but not the actual data. If I echo out the $vm variable I see the data I expect formatted just like I want, I just can't seem to get that out into a format outside of the console. I've also tried a different method

$vms = Get-View -ViewType VirtualMachine -Property @("Name", "Config.Hardware.Device", "Guest.GuestFullName")
$result = @()
foreach($vm in $vms)
{   
    $newrow = "" | select-object Name, Controller, OS
    $newrow.name = $vm.name
    $newrow.controller = $vm | Select-Object -Property ($_.Config.Hardware.Device | where{$_.DeviceInfo.Label -match "SCSI"}).DeviceInfo.Summary
    $newrow.os = $vm | Select-Object -Property $_.Guest.GuestFullName
    $result += $newrow
}

It lists the VM name, but the other two columns show VMware.Vim.VirtualMachine. I'm probably missing something simple here but I can't figure it out. What am I missing?

Thanks for your help in advance.

Jonathon Fitch blog: atangledweb.net Virtualization enthusiast and advocate
0 Kudos
1 Solution

Accepted Solutions
Zsoldier
Expert
Expert
Jump to solution

Try this:

$vms = Get-View -ViewType VirtualMachine -Property @("Name", "Config.Hardware.Device", "Guest.GuestFullName")
$result = @()
foreach($vm in $vms)
{   
    $newrow = "" | select-object Name, Controller, OS
    $newrow.name = $vm.name
    $newrow.controller = ($vm.Config.Hardware.Device | where{$_.DeviceInfo.Label -match "SCSI"}).DeviceInfo.Summary
    $newrow.os = $vm.Guest.GuestFullName
    $result += $newrow
}

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier

View solution in original post

0 Kudos
4 Replies
Zsoldier
Expert
Expert
Jump to solution

Try this:

$vms = Get-View -ViewType VirtualMachine -Property @("Name", "Config.Hardware.Device", "Guest.GuestFullName")
$result = @()
foreach($vm in $vms)
{   
    $newrow = "" | select-object Name, Controller, OS
    $newrow.name = $vm.name
    $newrow.controller = ($vm.Config.Hardware.Device | where{$_.DeviceInfo.Label -match "SCSI"}).DeviceInfo.Summary
    $newrow.os = $vm.Guest.GuestFullName
    $result += $newrow
}

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
0 Kudos
JFitchVMA
Enthusiast
Enthusiast
Jump to solution

Chris, that worked. I'm still learning Powershell and PowerCLI so if you don't mind what's the difference between doing a select-object out of the vm object vs calling it the way you did, and what does () do on the controller line? Thanks for your help!

Jonathon Fitch blog: atangledweb.net Virtualization enthusiast and advocate
0 Kudos
Zsoldier
Expert
Expert
Jump to solution

Select-Object isn't necessarily a wrong way to go about it, but you would needed to have changed the syntax to something like this:

$newrow.os = ($vm | Select-Object -Property @{N="Guest";E={$_.Guest.GuestFullName}}).Guest

This will return just the property as a string.  In your script, select-object cannot, afaik, expand an object, only a string.

Regarding the (), it's kinda like math.  What you are doing is telling PS to run what's inside them first.  If you left it just like this:

$newrow.controller = ($vm.Config.Hardware.Device | where{$_.DeviceInfo.Label -match "SCSI"})

This would return the object and/or objects that meet your match statement.  By appending ".DeviceInfo.Summary" you are telling powershell to only return the string under the object you queryed for.

I'm still fairly green when it comes to this stuff, much less trying to explain it.  Anyone, feel free to correct me, but does this make sense JFitchVMA?

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
0 Kudos
JFitchVMA
Enthusiast
Enthusiast
Jump to solution

That does make sense. thanks for the explanation.

Jonathon Fitch blog: atangledweb.net Virtualization enthusiast and advocate
0 Kudos