Hi,
I am getting the below error for folder name and it is not working.
please help
The property 'Folder' cannot be found on this object. Verify that the property exists and can be set.
At D:\Disk_Info.ps1:48 char:1
+ $diskInfo.Folder = $vm.Folder.Name
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
$DiskInfoDef = @"
public struct DiskInfo {
public string Folder;
public string VMname;
public string Label;
public string Path;
public bool Thin;
public bool RDM;
public string Used;
public string CapacityMB;
public string AllocatedMB;
"@
$vms = Get-View -ViewType VirtualMachine
$maxSnapshot = ($vms | %{$_.LayoutEx.Snapshot.Count} | Measure-Object -Maximum).Maximum
1..$maxSnapshot | %{
$DiskInfoDef += ("`n`tpublic string Snap" + $_ + "MB;")
$DiskInfoDef += ("`n`tpublic string Snap" + $_ + "Name;")
}
$DiskInfoDef += "`n}"
Add-Type -Language CsharpVersion3 -TypeDefinition $DiskInfoDef
$snapHash = @{}
filter Get-SnapHash{
$snapHash[$_.Snapshot.Value] = $_.Name
if($_.ChildSnapshotList){
$_.ChildSnapShotList | Get-SnapHash
}
}
$vms | %{
$vm = $_
if($vm.Snapshot){
$vm.Snapshot.RootSnapshotList | Get-SnapHash
}
$_.Config.Hardware.Device | where {$_.DeviceInfo.Label -like "Hard disk *"} | %{
$hd = $_
$vm.LayoutEx.Disk | where {$_.Key -eq $hd.Key} | %{
$diskFiles = $_.Chain | %{$_.FileKey} | %{$_}
}
$diskAllocated = 0
$vmdkName = $vm.LayoutEx.File[$diskFiles[0]].Name
$vm.LayoutEx.File | where {$diskFiles -contains $_.Key} | %{
$diskAllocated += $_.Size
}
$used = "na"
if($hd.Backing.ThinProvisioned){
$used = ("{0:P1}" -f ($diskAllocated / 1KB/$hd.CapacityInKB))
}
$diskInfo = New-Object DiskInfo
$diskInfo.Folder = $vm.Folder.Name
$diskInfo.VMname = $vm.Name
$diskInfo.Label = $hd.DeviceInfo.Label
$diskInfo.Path = $vmdkName
$diskInfo.Thin = $hd.Backing.ThinProvisioned
$diskInfo.RDM = $hd.Backing.GetType().Name.Contains("RawDisk")
$diskInfo.Used = $used
$diskInfo.CapacityMB = ("{0:N1}" -f ($hd.CapacityInKB/1KB))
$diskInfo.AllocatedMB = ("{0:N1}" -f ($diskAllocated / 1MB))
$snapNr = 1
if($vm.Snapshot){
$vm.LayoutEx.Snapshot | %{
$_.Disk | where {$_.Key -eq $hd.Key} | %{
$prevFiles = $_.Chain | %{$_.FileKey} | %{$_}
}
$vm.LayoutEx.Disk | where {$_.Key -eq $hd.Key} | %{
foreach($chain in $_.Chain){
if($prevFiles -notcontains $chain.FileKey[0] -and $prevFiles -notcontains $chain.FileKey[1]){
break
}
}
}
$snapFiles = $chain.FileKey | %{$_}
$snapSize = ""
$snapName = ""
if($snapFiles){
$snapAllocated = 0
$vm.LayoutEx.File | where {$snapFiles -contains $_.Key} | %{
$snapAllocated += $_.Size
}
$snapSize = ("{0:N1}" -f ($snapAllocated / 1MB))
$snapName = $snapHash[$_.Key.Value]
}
$diskInfo.("Snap" + $snapNr + "MB") = $snapSize
$diskInfo.("Snap" + $snapNr + "Name") = $snapName
$snapNr++
}
}
$diskInfo
}
} | ft -auto
The $vm variable contains a VirtualMachine object returned by Get-View.
That type of object does not have a Folder property.
You can get the foldername with
(Get-View -Id $vm.Parent).Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The $vm variable contains a VirtualMachine object returned by Get-View.
That type of object does not have a Folder property.
You can get the foldername with
(Get-View -Id $vm.Parent).Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Got it. Thanks for your help.