VMware Cloud Community
Assaro_Delamar
Contributor
Contributor
Jump to solution

Receive All Datastores connected to ESXi

Hello, I am currently using the Get-VMHost Cmdlet to receive a Host and use the DatastoreIDList to receive all Datastores connected to said Host. However, Powershell keeps telling me that this feature will be removed and to use something else. I have so far not found a suitable replacement.

This is my Code for that:

$ESXi = Get-VMHost -Server $settings.vCenter -Name $settings.ESXi
$DatastoreIds = $ESXi.DatastoreIdList
    $VMdatastore = $null
    foreach ($DatastoreId in $DatastoreIds) {
        $datastore = Get-Datastore -Server $settings.vCenter -Id $DatastoreId
        $Tags = Get-TagAssignment -Entity $datastore -Category $TagCategoryName
        if ($Tags.Tag.Name -ccontains $TagName){
            $VMdatastore = $datastore
            Write-ToLog -_LogFileName $fileName -_LogMessage "Found Datastore $($datastore.Name) with Tag $($TagName)"
            break;
        }
    }

 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

That message is just a warning, and it has been there for a long time.

As an alternative use the Get-Datastore cmdlet with the RelatedObject parameter.
Pass the object returned by Get-VMHost on that parameter.


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

View solution in original post

1 Reply
LucD
Leadership
Leadership
Jump to solution

That message is just a warning, and it has been there for a long time.

As an alternative use the Get-Datastore cmdlet with the RelatedObject parameter.
Pass the object returned by Get-VMHost on that parameter.


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