Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 168455

Re: $global:defaultVIServer variable gets overwritten with datastores in PowerCLI 6.0 Release 2

$
0
0

Is there a better way to get the list of datastores (and their paths) with PowerCLI 6.0?


Are you looking for something like this?


function Get-ChildEntityRecursion{

    param(

    $ChildEntity,

    $ParentPath

    )

        process{

            $ChildEntity | foreach-object{

            $ChildChildEntity = get-view ($_)

                If ($ChildChildEntity.ChildEntity){

                $FullPath = $ParentPath +"\"+ $($ChildChildEntity.Name)

                Get-ChildEntityRecursion $ChildChildEntity.ChildEntity -ParentPath $FullPath

                }

                Else{

                $FullPath = $ParentPath +"\"+ $($ChildChildEntity.Name)

                $FullPath

                }

            }

        }

}

 

$ServiceInstance = get-view serviceinstance

$RootFolder = get-view($ServiceInstance.content.rootfolder)

$RootFolder.ChildEntity | foreach-object{

    $DatacenterFolder = get-view ($_)

    $TopFolder = get-view($DatacenterFolder.DatastoreFolder)

    $FullPath = $($global:defaultVIServer.name) + "\" +  $($DatacenterFolder.Name)

    Get-ChildEntityRecursion -ChildEntity $TopFolder.ChildEntity -ParentPath $FullPath

}

 

Note:
The script works only with one connection to a VC.
I didn't test it so much, but it works in my lab.

It doesn't rely on "vmstores:", so if the information is in vCenter it is possible to extract it even if a datastore is unavailable.

 

Bonus:

It is possible to replace the line:

$TopFolder = get-view($DatacenterFolder.DatastoreFolder) #To get everything in the "Datastores and Datastore Clusters" view

by

$TopFolder = get-view($DatacenterFolder.HostFolder)  #To get everything in the "Hosts and Clusters" view

$TopFolder = get-view($DatacenterFolder.VMFolder) #To get everything in the "VMs and Template" view

 

For the "Networking" view the script will have to be modified to take into account properly dvSwith.
It doesn't work well so far.

$TopFolder = get-view($DatacenterFolder.NetworkFolder)


Viewing all articles
Browse latest Browse all 168455

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>