Newbie to PowerCLI & PowerNSX here.
So far managed to scramble around the pieces with different For loop, need help in merging it in single for loop and single output CSV file. For GuestToolStatus ExtendedData.GuestToolStatus didnt work.
$vmList = Get-Content -Path "C:\VM-List.txt"
$VMCustomReport = "C:\Report1-VMInfo.csv"
$VMToolStatusReport = "C:\Report2-VMToolsStatus.csv"
$VMSecurityTagReport = "C:\Report3-VMSecurityTag.csv"
$VMCustomInfo = @()
$VMToolStatusInfo =@()
$VMSecurityTagInfo =@()
foreach ( $vmName in $vmList )
{
$vm = Get-VM -Name $vmName -ErrorAction SilentlyContinue
if ($vm)
{
$VMCustomInfo += ($vm | Select-Object Name , Guest ,
@{ N = "IP" ; E = {$vm.Guest.IPAddress}} ,
@{ N = "ToolsVersion" ; E = { $vm.Guest.ToolsVersion }} ,
@{ N = "Host" ; E = { $vm.VMHost}} ,
@{ N = "Cluster" ; E = { Get-Cluster -VM $vm }}
)
}
}
$VMCustomInfo | Export-Csv $VMCustomReport
#_________________________________________________________________________________________________________________
foreach ( $vmName in $vmList )
{
$vm = Get-VM -Name $vmName -ErrorAction SilentlyContinue
if ($vm)
{
$VMToolStatusInfo += ( $vm | Get-View | Select-Object @{ N = "VM Name " ; E = { $_.Name }} ,
@{ N = "VMTools Status" ; E = {$_.Guest.ToolsStatus}}
)
}
}
$VMToolStatusInfo | Export-Csv $VMToolStatusReport
#_________________________________________________________________________________________________________________
foreach ( $vmName in $vmList )
{
$vm = Get-VM -Name $vmName -ErrorAction SilentlyContinue
if ($vm)
{
$VMSecurityTagInfo += ( Get-VM -Name $vm | Get-NsxSecurityTagAssignment | Select-Object VirtualMachine , @{ N = "Security-Tag" ; E = { $_.securitytag.name}} )
}
}
$VMSecurityTagInfo | Export-Csv $VMSecurityTagReport