Hi all,
I have been loving learning PowerCLI.
I am having problems adding info to a script that I had help with. The line I am having problems with is,
Add-Member -InputObject $reportedvm -MemberType noteProperty -name GuestOs -value $VM.Guest.OSFullName
I will add the whole script bellow. If someone could explain to me what I am doing wrong. I am just getting blanks for that colum in my CSV. I am assuming that the variable $VM does not have the property info I am looking for. I am not sure if I need to do a join or something else to get this info.
Here is the script as a whole.
$reportedvms=New-Object System.Collections.ArrayList
$vms = get-view -viewtype virtualmachine |Sort-Object -Property { $_.Config.Hardware.Device | where {$_ -is [VMware.Vim.VirtualEthernetCard]} | Measure-Object | select -ExpandProperty Count} -Descending
foreach($vm in $vms){
$reportedvm = New-Object PSObject
Add-Member -Inputobject $reportedvm -MemberType noteProperty -name Guest -value $vm.Name
Add-Member -InputObject $reportedvm -MemberType noteProperty -name UUID -value $($vm.Config.Uuid)
Add-Member -InputObject $reportedvm -MemberType noteProperty -name GuestOs -value $VM.Guest.OSFullName
Add-Member -InputObject $reportedvm -MemberType noteProperty -name ToolsVersion -value $VM.Config.Tools.ToolsVersion
Add-Member -InputObject $reportedvm -MemberType noteProperty -name ToolsUpdate -value $VM.Guest.ToolsStatus
$networkcards=$vm.guest.net
$i=0
foreach($ntwkcard in $networkcards){
Add-Member -InputObject $reportedvm -MemberType NoteProperty -Name "networkcard${i}.Network" -Value $ntwkcard.Network
Add-Member -InputObject $reportedvm -MemberType NoteProperty -Name "networkcard${i}.IpAddress" -Value $($ntwkcard.IpAddress|?{$_ -like "*.*"})
$i++
}
$reportedvms.add($reportedvm)|Out-Null
}
$reportedvms | Export-Csv C:\temp\vm_nic_report.csv