PowerShell PowerCLI Get-VIPermission

Used to get the datastore's connected to each VM.

            
    #Load-PowerCLI
    & 'C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'

    #Connect to vCenter
    Connect-VIServer MyVCenterName

    #Get List of ESXi Hosts
    $Hosts=Get-VMHost | Select -ExpandProperty Name

    #Loop through and get each VM's datastore 
    Foreach($Item in $Hosts){

    Get-VMHost $Item | Get-VM | Select Name,@{N="Datastore";E={[string]::Join(',',(Get-Datastore -Id $_.DatastoreIdList | Select -ExpandProperty Name))}},@{N="VMHost";E={$Item}} |Export-Csv C:\VM-Report1.csv -NoTypeInformation -UseCulture -Append

    }                
        

2020 | Scott W. Head  |  Sr. Systems Admin | Certified Microsoft Windows Server Administrator