Hi everyone!
Running into some difficulties, going against a 4.1 cluster, with 5.1 PowerCLI client and could really use some help here, as this report is already pretty awsome, just need a bit more info.....Here are my custom annotations I'd like to be able to incorporate into my report:
This is the code which I'm hoping to modify - Just starting with one of the annotations 'Owner' for now.. See the last line of the 'For Each' loop, which definately isn't right...
$VCServerName = "sf1"
$VC = Connect-VIServer $VCServerName
$VMFolder = "ITAC_SF1_RandD_DC"
$date = Get-Date -f Mdyyyy_HH_mm
$ExportFilePath = "C:\Users\U219715\Desktop\PowerCLI\Export-VMInfo_RING_$($date).csv"
$Report = @()
$VMs = Get-Folder -Server $VC -Location $VMFolder | Get-VM
$Datastores = Get-Datastore | select Name, Id
$VMHosts = Get-VMHost | select Name, Parent
ForEach ($VM in $VMs) {
$VMView = $VM | Get-View
$VMInfo = {} | Select VMName,Powerstate,OS,Folder,IPAddress,ToolsStatus,VMHost,Cluster,Datastore,NumCPU,MemMb,DiskGb, DiskFree, DiskUsed, Owner
$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.VMHost = $vm.host.name
$VMInfo.Cluster = $vm.host.Parent.Name
$VMInfo.Datastore = ($Datastores | where {$_.ID -match (($vmview.Datastore | Select -First 1) | Select Value).Value} | Select Name).Name
$VMInfo.NumCPU = $vm.NumCPU
$VMInfo.MemMb = [Math]::Round(($vm.MemoryMB),2)
$VMInfo.DiskGb = [Math]::Round((($vm.HardDisks | Measure-Object -Property CapacityKB -Sum).Sum * 1KB / 1GB),2)
$VMInfo.DiskFree = [Math]::Round((($vm.Guest.Disks | Measure-Object -Property FreeSpace -Sum).Sum / 1GB),2)
$VMInfo.DiskUsed = $VMInfo.DiskGb - $VMInfo.DiskFree
$VMInfo.Owner = $vm | Select Name,@{N="Owner";E={$_.CustomFields['Owner']}}
And here is what this code produces at present, which definately isn't right:
Any help would make my day, let me know if I can provide any additional info...
Thankyou Sincerely
Ryan Hammond