I have the script below...
$result = @()
$vms = Get-view -ViewType VirtualMachine
foreach ($vm in $vms) {
if($vm.config.hardware.NumCoresPerSocket -ne $null){
$cores = $vm.config.hardware.NumCoresPerSocket
}
else{
$cores = 1
}
$obj = new-object psobject
$obj | Add-Member -MemberType NoteProperty -Name ServerName -Value ($vm.Name)
$obj | Add-Member -MemberType NoteProperty -Name CPUs -Value ($vm.config.hardware.NumCPU)
$obj | Add-Member -MemberType NoteProperty -Name Sockets -Value ($vm.config.hardware.NumCPU/$cores)
$obj | Add-Member -MemberType NoteProperty -Name CPUPersocket -Value $cores
$obj | Add-Member -MemberType NoteProperty -Name RAMAssigned -Value $VM.MemoryGB
$result += $obj
}
$result | Out-File c:\temp\cputest.txt
It runs but Memory is not populating. I must calling the value/property wrong.
Also, how can I format the output to CSV?
Thanks
Something like this you mean?
The short ID is
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Since you use Get-View to retrieve the VMs, you are working with the vSphere object VirtualMachine.
In contrast, the Get-VM cmdlet returns a .NET object VirtualMachine, which is not the same.
The Value should be done like this for a vSphere object.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
OK, thanks!
The values returned correctly......
ServerName : goofy
CPUs : 2
Sockets : 2
CPUPersocket : 1
RAMAssigned : 6
ServerName : pluto
CPUs : 4
Sockets : 4
CPUPersocket : 1
RAMAssigned : 8
Changed my output to below for a CSV....
$result | Export-Csv -Path c:\temp\cputest.txt -NoTypeInformation
Now one more item, how do I get the OS profile that is set for the VM?
$obj | Add-Member -MemberType NoteProperty -Name OSProfile -Value ?????
Thanks
Something like this you mean?
The short ID is
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Dude, I would have never guessed the "$vm.Config.GuestFullName" calls for the Operating System type for the VM..........lmao.
Thanks again!
