$vcserver="VSPHLAB01" $portvc="443" Add-PSsnapin VMware.VimAutomation.Core Initialize-VIToolkitEnvironment.ps1 connect-VIServer $vcserver -port $portvc $date=get-date $filelocation="C:\ScriptOutput\" + $vcserver + "-DataStore Info-" +(get-date -format d'-'MM'-'yy'')+".csv" $ErrorActionPreference = "SilentlyContinue" function Get-DSDevice($dsImpl) { $ds = Get-View -Id $dsImpl.Id $esx = Get-View $ds.Host[0].Key $hss = Get-View $esx.ConfigManager.StorageSystem foreach($mount in $hss.FileSystemVolumeInfo.MountInfo){ if($mount.volume.name -eq $ds.Info.Name){ switch($mount.Volume.Type){ "VMFS" { foreach($ext in $mount.Volume.Extent){ if($mount.volume.name -eq $ds.Info.Name){ $device =$ext.DiskName } } } } } } $device } $datastores = get-vmhost | Get-Datastore | Sort-Object Name $myColCurrent = @() foreach ($store in $datastores){ $myObj = "" | Select-Object Name, CapacityGB, UsedGB, PercFree, FileSystem, Accessible $myObj.Name = $store.Namek $myObj.CapacityGB = "{0:n2}" -f ($store.capacityMB/1kb) $myObj.UsedGB = "{0:N2}" -f (($store.CapacityMB - $store.FreeSpaceMB)/1kb) $myObj.PercFree = "{0:N}" -f (100 * $store.FreeSpaceMB/$store.CapacityMB) $myObj.FileSystem = $store.Type $temp = Get-View -Id $store.Id #$myObj.ID = Get-DSDevice $store $myObj.Accessible = $store.Accessible $myColCurrent += $myObj } $myColCurrent | Export-csv $filelocation -noTypeInformation -UseCulture disconnect-viserver -confirm:$false