ganapa2000
Enthusiast
Enthusiast

SCSI ID shows blanks

Jump to solution

Hi,

I am unable to get the SCSI ID as 0:0 or 1:1 etc in the below script and out for SCSI ID shows blank

$report = foreach($vc in $global:defaultviservers){
foreach($vm in (Get-View -ViewType VirtualMachine -Property Name,runtime.powerState,runtime.consolidationNeeded,Guest.net,Config.Hardware.numCPU,Config.Hardware.MemoryMB,
Runtime.Host,Guest.GuestFullName, Config.GuestFullName,Parent,ResourcePool,Config.Hardware.Device,Config.version,Config.Tools.ToolsVersion,guest.toolsversionstatus,
Config.Files.VMPathName,Config.Template -Server $vc )){
if($vm.Config.Template){
$t = Get-View -Id (Get-View $vm.Runtime.Host).Parent
}
else{
$t = Get-View $vm.ResourcePool -Property Name,Parent -Server $vc
while($t.getType().Name -eq "ResourcePool"){
$t = Get-View $t.Parent -Property Name,Parent -Server $vc
}
}
if($t.GetType().Name -eq "ClusterComputeResource"){
$cluster = $t.Name
}
else{
$cluster = "Stand Alone Host"
}
while($t.getType().Name -ne "Datacenter"){
$t = Get-View $t.Parent -Property Name,Parent -Server $vc
}
$datacenter = $t.Name
$vm.Config.Hardware.Device | where {$_ -is [VMware.Vim.VirtualDisk]} |
Select @{N="VM";E={$vm.Name}},
@{N='powerState';E={$vm.runtime.powerState}},
@{N='IP';E={[string]::Join(',',($vm.Guest.Net | %{$_.IpAddress | where{$_.Split('.').Count -eq 4} | %{$_}}))}},
@{N='NumCPU';E={$vm.config.Hardware.NumCpu}},
@{N='Memory GB';E={$vm.Config.Hardware.MemoryMB| %{[math]::Round($_/1kb,2)}}},
@{N='vCenter';E={$vc.Name}},
@{N='VMHost';E={$script:esx = Get-View -Id $vm.Runtime.Host -Server $vc ; $script:esx.name}},
@{N='GuestOS';E={$vm.Guest.GuestFullName}},
@{N='ConfiguredOS';E={$vm.Config.GuestFullName}},
@{N="Folder";E={$path}},
@{N="Cluster";E={$cluster}},
@{N="Datacenter";E={$datacenter}},
@{N="ScsiID";E={$strControllerKey = $_.ExtensionData.ControllerKey.ToString(); "{0}`:{1}" -f $strControllerKey[$strControllerKey.Length - 1], $_.ExtensionData.Unitnumber}},
@{N="Hard Disk";E={$_.DeviceInfo.Label}},
@{N="Disk datastore";E={$_.Backing.Filename.Split(']')[0].TrimStart('[')}},
@{N='Needs Consolidation';E={$vm.Runtime.consolidationNeeded}},
@{N="Disk capacity GB";E={$_.CapacityInKB| %{[math]::Round($_/1MB,2)}}},
@{N="Disk type";E={
if($_.Backing.GetType().Name -match "flat"){
"Flat"
}
else{
$_.Backing.CompatibilityMode
}}},
@{N='DeviceName';E={
if($_.Backing.GetType().Name -match 'raw'){
$_.Backing.DeviceName
}
else{
$script:lunnaa = (Get-View -Id $_.Backing.Datastore -Server $vc ).Info.Vmfs.Extent[0].DiskName
$script:lun = $script:esx.Config.StorageDevice.ScsiLun | where{$_.CanonicalName -eq $script:lunnaa}
$script:lun.Descriptor | where{$_.Id -match 'vml.'} | Select -ExpandProperty Id
}}},
@{N='LUN NAA';E={
if($_.Backing.GetType().Name -match 'raw'){
$lunUuid = $_.Backing.LunUuid
$script:lun = $script:esx.Config.StorageDevice.ScsiLun | where{$_.Uuid -eq $lunUuid}
$script:lun.CanonicalName
}
else{
$script:lunnaa
}}},
@{N='LUN ID';E={
$dev = $script:esx.Config.StorageDevice.PlugStoreTopology.Device | where {$_.Lun -eq $script:lun.Key}
$script:esx.Config.StorageDevice.PlugStoreTopology.Path | where {$_.Device -eq $dev.Key} |
Select -First 1 -ExpandProperty LunNumber
}},
@{N='VMConfigFile';E={$VM.config.files.VMpathname}},
@{N='VMDKPath';E={$_.Backing.FileName}},
@{N="HW Version";E={$vm.Config.version}},
@{N="VMware Tools version";E={$vm.Config.Tools.ToolsVersion}},
@{N="Tools Status";E={$vm.guest.toolsversionstatus}},
@{N="NIC Name";E={($vm.config.hardware.device | where {($_.DeviceInfo.Label -like "Network*")}).DeviceInfo.Label}},
@{N="NIC Connected";E={($vm.config.hardware.device | where {($_.DeviceInfo.Label -like "Network*")}).Connectable.Connected}},
@{N="Mac"; E={($vm.Config.Hardware.Device | where{$_.DeviceInfo.Label -like "Network*"}).MacAddress}},
@{N="Portgroup"; E={
$nic = $vm.Config.Hardware.Device | where{$_.DeviceInfo.Label -like "Network*"}
[string]::Join(',',(
$nic | %{
if($_.DeviceInfo.Summary -notmatch 'DVSwitch'){
$_.DeviceInfo.Summary
}
else{
Get-View -ViewType DistributedVirtualPortgroup -Property Name -Filter @{'Key'=$_.Backing.Port.PortgroupKey} -Server $vc |
Select -ExpandProperty Name
}}))}}
}
}
$report | Export-Csv report.csv -NoTypeInformation -UseCulture

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Try with this

@{N="ScsiID";E={
    $dev = $_
    $ctrl = $vm.Config.Hardware.Device | where{$_.Key -eq $dev.ControllerKey}
    "{0}:{1}" -f $ctrl.BusNumber,$dev.UnitNumber}},


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership

Try with this

@{N="ScsiID";E={
    $dev = $_
    $ctrl = $vm.Config.Hardware.Device | where{$_.Key -eq $dev.ControllerKey}
    "{0}:{1}" -f $ctrl.BusNumber,$dev.UnitNumber}},


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

View solution in original post

0 Kudos
ganapa2000
Enthusiast
Enthusiast

LucD, that worked but Folder is showing blank.

I tried as below, still it is shows blank

@{N="Folder";E={($vm.Folder.name}},

0 Kudos
LucD
Leadership
Leadership

You didn't mention Folder in your original question.

Try with

@{N='Folder';E={(Get-View -Id $vm.Parent).Name}},


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

0 Kudos
ganapa2000
Enthusiast
Enthusiast

Thanks LucD for your help!!!

0 Kudos