How can I export free space on a datastore and used space on a datastore in my script below - PowerCLi
This line works to pull the datastore itself but I am not sure how to get the free space and used space on the datastore itself.
$VMInfo.Datastore = ($Datastores|where {$_.ID -match (($vmview.Datastore |Select-First1) |SelectValue).Value} |SelectName).Name
===============================================================================
"@
filterGet-FolderPath {
$_|Get-View|% {
$row=""|selectName,Path
$row.Name =$_.Name
$current=Get-View$_.Parent
# $path = $_.Name # Uncomment out this line if you do want the VM Name to appear at the end of the path
$path=""
do {
$parent=$current
if($parent.Name -ne"vm"){$path=$parent.Name +"\"+$path}
$current=Get-View$current.Parent
} while ($current.Parent -ne$null)
$row.Path =$path
$row
}
}
$VCServerName="spvcenter11.reyesholdings.com"
$VC=Connect-VIServer$VCServerName-userRH\-password
$VMFolder="RFS"
$ExportFilePath="C:\users\wkieca\desktop\True-Up2018\Export-spvcenter11.csv"
$Report= @()
$VMs=Get-VM
$Datastores=Get-Datastore|selectName,Id
$VMHosts=Get-VMHost|selectName,Parent
ForEach ($VMin$VMs) {
$VMView=$VM|Get-View
$VMInfo= {} |SelectVMName,Powerstate,OS,Folder,IPAddress,ToolsStatus,ToolsVersion,Host,Cluster,Datastore,NumCPU,MemMb,DiskGb,DiskFree,DiskUsed,BusinessUnit
$VMInfo.VMName =$vm.name
$VMInfo.Powerstate =$vm.Powerstate
$VMInfo.OS =$vm.Guest.OSFullName
$VMInfo.Folder = ($vm|Get-Folderpath).Path
$VMInfo.IPAddress =$vm.Guest.IPAddress[0]
$VMInfo.ToolsStatus =$VMView.Guest.ToolsStatus
$VMInfo.ToolsVersion =$VMView.Guest.ToolsVersion
$VMInfo.Host =$vm.VMHost.Name
$VMInfo.Cluster =$vm.host.Parent.Name
$VMInfo.Datastore = ($Datastores|where {$_.ID -match (($vmview.Datastore |Select-First1) |SelectValue).Value} |SelectName).Name
$VMInfo.NumCPU =$vm.NumCPU
$VMInfo.MemMb =[Math]::Round(($vm.MemoryMB),2)
$VMInfo.DiskGb =[Math]::Round((($vm.HardDisks |Measure-Object-PropertyCapacityKB-Sum).Sum *1KB/1GB),2)
$VMInfo.DiskFree =[Math]::Round((($vm.Guest.Disks |Measure-Object-PropertyFreeSpace-Sum).Sum /1GB),2)
$VMInfo.DiskUsed =$VMInfo.DiskGb -$VMInfo.DiskFree
$VMInfo.BusinessUnit =$vm.CustomFields.Item("Business Unit")
$Report+=$VMInfo
}
$Report=$Report|Sort-ObjectVMName
IF ($Report-ne"") { $report|Export-Csv$ExportFilePath-NoTypeInformation
} $VC=Disconnect-VIServer-Confirm:$False