Hi,
how can I get the Attached and Mount Status of devices in the below script.
It Attached and Mounted shows blank.
Please help.
$report = @()
Get-Cluster -PipelineVariable cluster |
Get-VMHost $esxhost -PipelineVariable esx |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $esx -V2
$esxcli.storage.core.device.list.invoke() |
#where{$_.Device -match $match} |
ForEach-Object -Process {
$obj = $esxcli.storage.core.device.list.CreateArgs()
$obj.device = $_.Device
$path = $esxcli.storage.core.path.list.Invoke($obj)
$esxcli.storage.core.device.list.Invoke($obj) |
ForEach-Object -Process {
$dev = $_
$ds = (Get-Datastore -RelatedObject $esx) |
where{$_.ExtensionData.Info.Vmfs.Extent.diskname -contains $dev.Device}
$report += Add-Member -InputObject $_ -MemberType NoteProperty -Name vCenter -Value (([uri]$esx.ExtensionData.Client.ServiceUrl).Host) -PassThru |
Add-Member -MemberType NoteProperty -Name Cluster -Value $cluster.Name -PassThru |
Add-Member -MemberType NoteProperty -Name VMHost -Value $esx.Name -PassThru |
Add-Member -MemberType NoteProperty -Name Datastore -Value $ds.Name -PassThru |
Add-Member -MemberType NoteProperty -Name LUN -Value (($path.LUN | Sort-Object -Unique) -join '|') -PassThru
}
}
}
$report | Sort LUN | Select vCenter,Cluster,VMHost,LUN,Vendor,Datastore,Device, @{N="Size";E={[math]::round($_.Size/1024)}}, DeviceMaxQueueDepth,NoofoutstandingIOswithcompetingworlds,Attached,Mounted,IsPerenniallyReserved | ft -auto
You're doing the calculated property in the wrong calculation.
Also IsOffline is a calculated property, so you have to compare with a [String] in this case.
$report = @()
Get-Cluster -PipelineVariable cluster |
Get-VMHost $esxhost -PipelineVariable esx |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $esx -V2
$esxcli.storage.core.device.list.invoke() |
#where{$_.Device -match $match} |
ForEach-Object -Process {
$obj = $esxcli.storage.core.device.list.CreateArgs()
$obj.device = $_.Device
$path = $esxcli.storage.core.path.list.Invoke($obj)
$esxcli.storage.core.device.list.Invoke($obj) |
ForEach-Object -Process {
$dev = $_
$ds = (Get-Datastore -RelatedObject $esx) |
where { $_.ExtensionData.Info.Vmfs.Extent.diskname -contains $dev.Device }
$report += Add-Member -InputObject $_ -MemberType NoteProperty -Name vCenter -Value (([uri]$esx.ExtensionData.Client.ServiceUrl).Host) -PassThru |
Add-Member -MemberType NoteProperty -Name Cluster -Value $cluster.Name -PassThru |
Add-Member -MemberType NoteProperty -Name VMHost -Value $esx.Name -PassThru |
Add-Member -MemberType NoteProperty -Name Datastore -Value $ds.Name -PassThru |
Add-Member -MemberType NoteProperty -Name OperationalState -Value (Get-ScsiLun -VmHost $esx -CanonicalName $dev.Device).ExtensionData.OperationalState[0] -PassThru |
Add-Member -MemberType NoteProperty -Name LUN -Value (($path.LUN | Sort-Object -Unique) -join '|') -PassThru |
Add-Member -MemberType NoteProperty -Name Attached -Value ( $dev.IsOffline -eq 'false') -PassThru |
Add-Member -MemberType NoteProperty -Name Mounted -Value ($ds -ne $null) -PassThru
}
}
}
$report |
sort LUN |
select vCenter, Cluster, VMHost, LUN, Vendor, Datastore, Device,
@{N = "Size"; E = { [math]::round($_.Size / 1024) } },
DeviceMaxQueueDepth, NoofoutstandingIOswithcompetingworlds, IsPerenniallyReserved, OperationalState,
Attached,Mounted |
Format-Table -AutoSize
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
And where are you placing the values in Attached and Mounted?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Not sure, where to place those values for Attached and Mounted
That is not what I asked.
Which values are to go in Attached and Mounted?
By which command do you get those values?
There is nothing in your code that fetches anything for Attached and Mounted, which explains why they show blanks.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I wanted to know, if the device is used by Datastore as mounted. and status of ESXi as below
If you are looking for the OperationalState, you will have to add the following.
The name of the property is OperationalState, not Attached or Mounted.
Add-Member -MemberType NoteProperty -Name OperationalState -Value (Get-ScsiLun -VMHost $esx -CanonicalName $dev.Device).ExtensionData.OperationalState[0] -PassThru
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
I tried as below
$report = @()
Get-Cluster -PipelineVariable cluster |
Get-VMHost $esxhost -PipelineVariable esx |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $esx -V2
$esxcli.storage.core.device.list.invoke() |
#where{$_.Device -match $match} |
ForEach-Object -Process {
$obj = $esxcli.storage.core.device.list.CreateArgs()
$obj.device = $_.Device
$path = $esxcli.storage.core.path.list.Invoke($obj)
$esxcli.storage.core.device.list.Invoke($obj) |
ForEach-Object -Process {
$dev = $_
$ds = (Get-Datastore -RelatedObject $esx) |
where{$_.ExtensionData.Info.Vmfs.Extent.diskname -contains $dev.Device}
$report += Add-Member -InputObject $_ -MemberType NoteProperty -Name vCenter -Value (([uri]$esx.ExtensionData.Client.ServiceUrl).Host) -PassThru |
Add-Member -MemberType NoteProperty -Name Cluster -Value $cluster.Name -PassThru |
Add-Member -MemberType NoteProperty -Name VMHost -Value $esx.Name -PassThru |
Add-Member -MemberType NoteProperty -Name Datastore -Value $ds.Name -PassThru |
Add-Member -MemberType NoteProperty -Name OperationalState -Value (Get-ScsiLun -VMHost $esx -CanonicalName $dev.Device).ExtensionData.OperationalState[0] -PassThru |
Add-Member -MemberType NoteProperty -Name LUN -Value (($path.LUN | Sort-Object -Unique) -join '|') -PassThru
}
}
}
$report | Sort LUN | Select vCenter,Cluster,VMHost,LUN,Vendor,Datastore,Device, @{N="Size";E={[math]::round($_.Size/1024)}}, DeviceMaxQueueDepth,NoofoutstandingIOswithcompetingworlds,IsPerenniallyReserved,OperationalState,@{N='Attached';E={$_.IsOffline -eq 'false'}},@{N='Mounted';E={$ds -contains $_.Device}} | ft -auto
added as below, Attached is showing as True, but Mounted is showing as false, looks validation is not working, I am missing something.
@{N='Attached';E={$_.IsOffline -eq 'false'}},@{N='Mounted';E={$ds -contains $_.Device}}
You're doing the calculated property in the wrong calculation.
Also IsOffline is a calculated property, so you have to compare with a [String] in this case.
$report = @()
Get-Cluster -PipelineVariable cluster |
Get-VMHost $esxhost -PipelineVariable esx |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $esx -V2
$esxcli.storage.core.device.list.invoke() |
#where{$_.Device -match $match} |
ForEach-Object -Process {
$obj = $esxcli.storage.core.device.list.CreateArgs()
$obj.device = $_.Device
$path = $esxcli.storage.core.path.list.Invoke($obj)
$esxcli.storage.core.device.list.Invoke($obj) |
ForEach-Object -Process {
$dev = $_
$ds = (Get-Datastore -RelatedObject $esx) |
where { $_.ExtensionData.Info.Vmfs.Extent.diskname -contains $dev.Device }
$report += Add-Member -InputObject $_ -MemberType NoteProperty -Name vCenter -Value (([uri]$esx.ExtensionData.Client.ServiceUrl).Host) -PassThru |
Add-Member -MemberType NoteProperty -Name Cluster -Value $cluster.Name -PassThru |
Add-Member -MemberType NoteProperty -Name VMHost -Value $esx.Name -PassThru |
Add-Member -MemberType NoteProperty -Name Datastore -Value $ds.Name -PassThru |
Add-Member -MemberType NoteProperty -Name OperationalState -Value (Get-ScsiLun -VmHost $esx -CanonicalName $dev.Device).ExtensionData.OperationalState[0] -PassThru |
Add-Member -MemberType NoteProperty -Name LUN -Value (($path.LUN | Sort-Object -Unique) -join '|') -PassThru |
Add-Member -MemberType NoteProperty -Name Attached -Value ( $dev.IsOffline -eq 'false') -PassThru |
Add-Member -MemberType NoteProperty -Name Mounted -Value ($ds -ne $null) -PassThru
}
}
}
$report |
sort LUN |
select vCenter, Cluster, VMHost, LUN, Vendor, Datastore, Device,
@{N = "Size"; E = { [math]::round($_.Size / 1024) } },
DeviceMaxQueueDepth, NoofoutstandingIOswithcompetingworlds, IsPerenniallyReserved, OperationalState,
Attached,Mounted |
Format-Table -AutoSize
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Perfect...Thank you very much 🙂