SNIP | VMware - VM - Get migration details (name, datastore, path, etc..)
Function Lints-VM-Get-MigrationDetails {
[CmdletBinding()]
Param(
[parameter(
Mandatory=$true,
ValueFromPipeline=$true)]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]]$vms
)
Begin {
$paths = @()
}
Process {
foreach ($v in $vms) {
$Path = ""
$CurrentFolder = $v.Folder
if ($CurrentFolder -eq $null -and $v.VApp -ne $null) {
$Path = $v.VApp.Name + "\"
$CurrentFolder = Get-Folder -ID (Get-VApp $v.VApp).ExtensionData.ParentFolder
}
While ($CurrentFolder.name -ne "vm") {
$Path = $CurrentFolder.Name + "\" + $Path
$CurrentFolder = $CurrentFolder.Parent
if ($CurrentFolder.count -gt 0 ){
$CurrentFolder = $CurrentFolder[0]
}
}
$Path = ($v |Get-Datacenter).Name + "\" + $Path
$v_temp = new-object PSObject
$v_temp | add-member -type NoteProperty -Name VMName -Value $v.Name
$v_temp | add-member -type NoteProperty -Name PowerState -Value $v.PowerState
$v_temp | add-member -type NoteProperty -Name DataStore -Value (($v.ExtensionData.Config.Files.VmPathName -split " ")[0] -replace "\[",'' -replace "\]",'')
$v_temp | add-member -type NoteProperty -Name Path -Value ($Path -replace ".$")
$v_temp | add-member -type NoteProperty -Name PortGroup -Value ($v | Get-NetworkAdapter).NetworkName
$v_temp
}
}
}