What I'm trying to get is the following;
Complete inventory with WWN names,
All instances running,
CPU type,
Number of CPU's per host and VM,
Number of cores and I want the output to go to my local drive (c:/scripts/reports.
Below is a sample of what I have and I'm just looking to ass the list I have above added to the script.
$VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) {
ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) {
ForEach ($VM in ($Cluster | Get-VM | Sort-Object -Property Name)) {
ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name)) {
"" | Select-Object -Property @{N="VM";E={$VM.Name}}, @{N="Datacenter";E={$Datacenter.name}}, @{N="Cluster";E={$Cluster.Name}}, @{N="Hard Disk";E={$HardDisk.Name}}, @{N="Datastore";E={$HardDisk.FileName.Split("]")[0].TrimStart("[")}}, @{N="VMConfigFile";E={$VM.ExtensionData.Config.Files.VmPathName}}, @{N="VMDKpath";E={$HardDisk.FileName}}, @{N="VMDK Size";E={($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB}}, @{N="Drive Size";E={$HardDisk.CapacityGB}}
}
}
}
}
$VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path "C:\scripts\xxxxxx.csv"
This is the first part of your question, in fact all extra properties minus the WWN.
The reason why the WWN is missing, is that it will take an enormous amount of time to fetch that info with the regular cmdlets.
I'm looking for an alternative faster method.
$VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) {
ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) {
ForEach ($VM in ($Cluster | Get-VM | Sort-Object -Property Name)) {
ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name)) {
"" | Select-Object -Property @{N="VM";E={$VM.Name}},
@{N="VM CPU#";E={$vm.ExtensionData.Config.Hardware.NumCPU/$vm.ExtensionData.Config.Hardware.NumCoresPerSocket}},
@{N="VM CPU Core#";E={$vm.NumCPU}},
@{N="Datacenter";E={$Datacenter.name}},
@{N="Cluster";E={$Cluster.Name}},
@{N="Host";E={$vm.VMHost.Name}},
@{N="Host CPU#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},
@{N="Host CPU Core#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuCores/$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},
@{N="Hard Disk";E={$HardDisk.Name}},
@{N="Datastore";E={$HardDisk.FileName.Split("]")[0].TrimStart("[")}},
@{N="VMConfigFile";E={$VM.ExtensionData.Config.Files.VmPathName}},
@{N="VMDKpath";E={$HardDisk.FileName}},
@{N="VMDK Size";E={($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB}},
@{N="Drive Size";E={$HardDisk.CapacityGB}}
}
}
}
}
$VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path "c:\scripts\reports\report.csv"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD.
For the WWN part, have a look at Re: VM to Datastore to Storage Array mapping - Script
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
Can you modify and add some more info >>> VM memory, guest OS, guest IP address & MAC.
thanks in advance.
Hi LucD. The script about was what you originally helped me with. I will like to add a line to show the LUN ID's for each storage LUN on each hosts and also add a line for WWN names of the hosts as well. Below is the script.
Thanks.
$VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) {
ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) {
ForEach ($VM in ($Cluster | Get-VM | Sort-Object -Property Name)) {
ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name)) {
"" | Select-Object -Property @{N="VM";E={$VM.Name}},
@{N="VM CPU#";E={$vm.ExtensionData.Config.Hardware.NumCPU/$vm.ExtensionData.Config.Hardware.NumCoresPerSocket}},
@{N="VM CPU Core#";E={$vm.NumCPU}},
@{N="Datacenter";E={$Datacenter.name}},
@{N="Cluster";E={$Cluster.Name}},
@{N="Host";E={$vm.VMHost.Name}},
@{N="Host CPU#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},
@{N="Host CPU Core#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuCores/$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},
@{N="Hard Disk";E={$HardDisk.Name}},
@{N="Datastore";E={$HardDisk.FileName.Split("]")[0].TrimStart("[")}},
@{N="VMConfigFile";E={$VM.ExtensionData.Config.Files.VmPathName}},
@{N="VMDKpath";E={$HardDisk.FileName}},
@{N="VMDK Size";E={($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB}},
@{N="Drive Size";E={$HardDisk.CapacityGB}}
}
}
}
}
$VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path "c:\scripts\reports\report.csv"