Hi all I need some insight into the following. I have an existing script that evolved over time (original source WoodITWork.com - It's about time I let the world know what I was thinking...). ...
See more...
Hi all I need some insight into the following. I have an existing script that evolved over time (original source WoodITWork.com - It's about time I let the world know what I was thinking...). The intention is to connect to 10 virtual centers, export a list of vm properties from each vc to 10 different csv files. What i need to add is the vm UUID and DNS name and then assistance with how to name each csv per the virtual center name if possible. $VC = Connect-VIServer $VCServerName #$VMFolder = "Workstations" $ExportFilePath = "C:\PS\Export-VMInfo.csv" $Report = @() #$VMs = Get-Folder $VMFolder | Get-VM $VMs = 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,IPAddress,Cluster,Datastore,NumCPU,MemMb,DiskGb, DiskFree, DiskUsed $VMInfo.VMName = $vm.name $VMInfo.Powerstate = $vm.Powerstate $VMInfo.OS = $vm.Guest.OSFullName $VMInfo.IPAddress = $vm.Guest.IPAddress[0] $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 $Report += $VMInfo } $Report = $Report | Sort-Object VMName IF ($Report -ne "") { $report | Export-Csv $ExportFilePath -NoTypeInformation } The other question is if it's still the most efficient way of useing the syntax getting the data as 4 of the vc's has got 4000+ vm's