VMware Cloud Community
piyushranusri
Enthusiast
Enthusiast
Jump to solution

folder, host and datacenter need to be add

i got the vm having with persistent disk type in vmware by this powershell command

Get-VM | % { Get-HardDisk -VM $_ | Where {$_.Persistence -eq "IndependentPersistent"} } | Export-Csv D:\disks.csv –NoTypeInformation

can you help me to add folder details, host and datacenter too in the script. Or share the working script which gave me the desired output

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could use the BlueFolderPath VIProperty I provided in Folder By Path

The script, inclusive the BlueFolderPath definition

New-VIProperty -Name 'BlueFolderPath' -ObjectType 'VirtualMachine' -Value {

    param($vm)

    function Get-ParentName{

        param($object)

        if($object.Folder){

            $blue = Get-ParentName $object.Folder

            $name = $object.Folder.Name

        }

        elseif($object.Parent -and $object.Parent.GetType().Name -like "Folder*"){

            $blue = Get-ParentName $object.Parent

            $name = $object.Parent.Name

        }

        elseif($object.ParentFolder){

            $blue = Get-ParentName $object.ParentFolder

            $name = $object.ParentFolder.Name

        }

        if("vm","Datacenters" -notcontains $name){

            $blue + "/" + $name

        }

        else{

            $blue

        }

    }

    (Get-ParentName $vm).Remove(0,1)

} -Force | Out-Null

Get-VM | where{Get-HardDisk -VM $_ | Where {$_.Persistence -eq "IndependentPersistent"}} |

Select Name,@{N='Folder';E={$_.BlueFolderPath}},

    @{N='VMHost';E={$_.VMHost.Name}},

    @{N='Datacenter';E={(Get-Datacenter -VM $_).Name}} |

Export-Csv D:\disks.csv –NoTypeInformation


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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

You could use the BlueFolderPath VIProperty I provided in Folder By Path

The script, inclusive the BlueFolderPath definition

New-VIProperty -Name 'BlueFolderPath' -ObjectType 'VirtualMachine' -Value {

    param($vm)

    function Get-ParentName{

        param($object)

        if($object.Folder){

            $blue = Get-ParentName $object.Folder

            $name = $object.Folder.Name

        }

        elseif($object.Parent -and $object.Parent.GetType().Name -like "Folder*"){

            $blue = Get-ParentName $object.Parent

            $name = $object.Parent.Name

        }

        elseif($object.ParentFolder){

            $blue = Get-ParentName $object.ParentFolder

            $name = $object.ParentFolder.Name

        }

        if("vm","Datacenters" -notcontains $name){

            $blue + "/" + $name

        }

        else{

            $blue

        }

    }

    (Get-ParentName $vm).Remove(0,1)

} -Force | Out-Null

Get-VM | where{Get-HardDisk -VM $_ | Where {$_.Persistence -eq "IndependentPersistent"}} |

Select Name,@{N='Folder';E={$_.BlueFolderPath}},

    @{N='VMHost';E={$_.VMHost.Name}},

    @{N='Datacenter';E={(Get-Datacenter -VM $_).Name}} |

Export-Csv D:\disks.csv –NoTypeInformation


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

Reply
0 Kudos
piyushranusri
Enthusiast
Enthusiast
Jump to solution

Thanks LucD.

Smiley Happy

Reply
0 Kudos