Found this nice function in Luc blow we are using this one for DS. But recently we received the request to get same level of verifications for devices (RDM in this case or any LUN not used as datastore)
Does anyone knows a powercli function to perform same checks available from GUI for Device detach?
http://www.lucd.info/2012/04/15/test-if-the-datastore-can-be-unmounted/
Regards
Gui
Try something like this
function Get-LunUnmountStatus{
param(
[CmdletBinding()]
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string[]]$CanonicalName
)
begin {
$esx = Get-View -ViewType HostSystem -Property ConfigManager.DiagnosticSystem
$diag = $esx | %{Get-View $_.ConfigManager.DiagnosticSystem}
$diagLUNs = $diag | %{$_.ActivePartition.Id.DiskName}
$ds = Get-View -ViewType Datastore -Property Summary.Type,Info
$dsLUNs = $ds | where {$_.Summary.Type -eq "VMFS"} |
%{$_.Info.Vmfs.Extent | %{$_.DiskName}}
$rdmLUNs = Get-View -ViewType VirtualMachine -Property Config.Hardware.Device | %{
$_.Config.Hardware.Device |
where {$_.Backing -is [VMware.Vim.VirtualDiskRawDiskMappingVer1BackingInfo]} |
%{$_.Backing.DeviceName}
}
}
process{
foreach($disk in $CanonicalName){
New-Object PSObject -Property @{
CanonicalName = $disk
# Not used in a datastore
NoDatastore = &{
$result = $true
if($dsLUNs -contains $disk){
$result = $false
}
$result
}
# Not used as an RDM disk
NoRDM = &{
$result = $true
if($rdmLUNs -contains $disk){
$result = $false
}
$result
}
# No scratch partition
NoScratchPartition = &{
$result = $true
if($diagLUNs -contains $disk){
$result = $false
}
$result
}
}
}
}
}
You can call it like this
Get-LunUnmountStatus -CanonicalName "naa.600107680170809ed0000000000000f7","naa.60010768018080aed0000000000000e8"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
