Hi all,
I am looking for a way to export to csv/xls all VM info:
Is this possible?
Yes, but if it is only a list of servers, you would really only need a txt file with each one on a new line
$servers=Get-Content ./serverlist.txt
FOREACH ($server in $servers)
{
Connect-viserver $server
Get-VM | Select-Object -Property @{N="Datastore";E={[string]::Join(",",($_ | Get-Datastore))}},@{N="VM";E={$_.Name}}, ProvisionedSpaceGB,VMHost,@{N="Folder";E={$_.Folder.Name}}
Disconnect-viserver $server -confirm:$false
}
Atleast assuming I understand your request I think this is what you are looking for....
LucD, I tried running the following script:
$report = foreach($vm in (Get-View -ViewType VirtualMachine -Property Name,Parent,ResourcePool,Config.Hardware.Device)){$t = Get-View $vm.Parent -Property Name,Parent$path = $t.Namewhile($t.GetType().Name -eq "Folder"){$t = Get-View $t.Parentif($t.Name -ne "vm"){$path = $t.Name + "/" + $path}}$t = Get-View $vm.ResourcePool -Property Name,Parentwhile($t.getType().Name -ne "ClusterComputeResource"){$t = Get-View $t.Parent -Property Name,Parent}$cluster = $t.Namewhile($t.getType().Name -ne "Datacenter"){$t = Get-View $t.Parent -Property Name,Parent}$datacenter = $t.Name$vm.Config.Hardware.Device | where {$_.GetType().Name -eq "VirtualDisk"} |Select @{N="VM";E={$vm.Name}},@{N="Folder";E={$path}},@{N="Cluster";E={$cluster}},@{N="Datacenter";E={$datacenter}},@{N="Disk";E={$_.DeviceInfo.Label}},@{N="Disk datastore";E={$_.Backing.Filename.Split(']')[0].TrimStart('[')}},@{N="Disk capacity";E={$_.CapacityInKB}},@{N="Disk type";E={if($_.Backing.GetType().Name -match "flat"){"Flat" }else{$_.Backing.CompatibilityMode}}}}$report | Export-Csv ("C:\PS-Logs\VM-Disks-{0:yyyyMMdd}.csv" -f (get-date)) -NoTypeInformation -UseCulture
and it takes forever and ends up using 3.5 GB of RAM. I have to kill the process as it runs for hours and hours... Am I doing something wrong?
Afaics you aren't doing anything wrong.
But perhaps you are running the script against a huge environment ?
How many VMs are we talking about ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, it is pretty huge:
To make it go faster or just confirm it works the way you want it to.. You could just change the first line slightly
$report = foreach($vm in (Get-View -ViewType VirtualMachine -Property Name,Parent,ResourcePool,Config.Hardware.Device){
to
$report= foreach($vm in (get-cluster "ClusterName" | Get-VM)){
Then it will just run it for the one cluster
When I run it through powerCLI, I get the following:
Unexpected token 'in' in expression or statement. At D:\Scripts\vmdk-info.ps1:1 char:25 + $report = foreach($vm in( <<<< get-cluster "BNC Viger Blade - Cluster 1" | Get-VM)){
Any idea why it is doing this? If I run it from my system, I have no problem (I run it through PowerGui Script Editor on my system)