I'm looking for a PowerCLI script that helps to determine the current status of the vmtools and vm hardware version which the servers list can grab from the input file, can some one help please - thanks
Do you mean like this?
$vcNames = 'vc1','vc2','vc3'
Connect-VIServer -Server $vcNames
$vmNames = (Get-Content -Path .\vmnames.txt) -join '|'
Get-View -ViewType VirtualMachine -Filter @{'Name'=$vmNames} |
Select Name,
@{N='vCenter';E={([uri]$_.Client.ServiceUrl).Host}},
@{N="HW Version";E={$_.Config.version}},
@{N='VMware Toos Status';E={$_.Guest.ToolsStatus}},
@{N="VMware Tools version";E={$_.Config.Tools.ToolsVersion}} |
Group-Object -Property vCenter | %{
$_.Group |
Export-Csv -Path ".\$($_.Name)-$(Get-Date -Format 'ddMMyyyy-HHmm').csv" -NoTypeInformation -UseCulture
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this.
The input file should have 1 name per line.
$vmNames = (Get-Content -Path .\vmnames.txt) -join '|'
Get-View -ViewType VirtualMachine -Filter @{'Name'=$vmNames} |
Select Name,
@{N="HW Version";E={$_.Config.version}},
@{N='VMware Toos Status';E={$_.Guest.ToolsStatus}},
@{N="VMware Tools version";E={$_.Config.Tools.ToolsVersion}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks LucD, forgot to mention that, I need to connect multiple vCenters before I run this script and also that output should be saved in .csv format with the running date, time to be captured in the file name. (example: vcentername-03032018-10:30am.csv)
And is the list of names in the input file over multiple vCenters?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Do you mean like this?
$vcNames = 'vc1','vc2','vc3'
Connect-VIServer -Server $vcNames
$vmNames = (Get-Content -Path .\vmnames.txt) -join '|'
Get-View -ViewType VirtualMachine -Filter @{'Name'=$vmNames} |
Select Name,
@{N='vCenter';E={([uri]$_.Client.ServiceUrl).Host}},
@{N="HW Version";E={$_.Config.version}},
@{N='VMware Toos Status';E={$_.Guest.ToolsStatus}},
@{N="VMware Tools version";E={$_.Config.Tools.ToolsVersion}} |
Group-Object -Property vCenter | %{
$_.Group |
Export-Csv -Path ".\$($_.Name)-$(Get-Date -Format 'ddMMyyyy-HHmm').csv" -NoTypeInformation -UseCulture
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes, the list of servers that I'm going add to the input file are from different vCenters.
See my last code snippet
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
excellent, thanks much and that helps.
However, if any server that is not available in any vCenter that has connected to, it should list out as 'Not Found". Can you please add that step as well.
That requires a slightly different logic in the code, try like this
$vcNames = 'vc1','vc2','vc3'
Connect-VIServer -Server $vcNames
$report = foreach($vmName in (Get-Content -Path .\vmnames.txt)){
Try{
$vm = Get-VM -Name $vmName -ErrorAction Stop
New-Object PSObject -Property @{
Name = $vmName
vCenter = ([uri]$vm.ExtensionData.Client.ServiceUrl).Host
'VMware Tools Status' = $vm.ExtensionData.Guest.ToolsStatus
'VMware Tools version' = $vm.ExtensionData.Config.Tools.ToolsVersion
}
}
Catch{
New-Object PSObject -Property @{
Name = $vmName
vCenter = 'Not found'
'VMware Tools Status' = ''
'VMware Tools version' = ''
}
}
}
$report |
Group-Object -Property vCenter | %{
$_.Group |
Export-Csv -Path ".\$($_.Name)-$(Get-Date -Format 'ddMMyyyy-HHmm').csv" -NoTypeInformation -UseCulture
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
sorry, the logic not working.
It is creating 3 different files with the each vCenter name that I connect and also creating a file as "not found".
can you look at the script again and correct it
Euh, isn't that what you asked in the beginning, a file per vCenter?
And since we now introduced 'not found', that would be an additional file.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, that is possible, but can you perhaps create a new thread for this.
Your question is quite different from the original one in this thread.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Please don't hijack existing threads for your question, you can just open a new thread.
And don't cross-post, repeating your question in multiple threads in the same community will not give you a reply faster.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
$vcNames = 'vc1','vc2','vc3'
Connect-VIServer -Server $vcNames
$report = foreach($vmName in (Get-Content -Path .\vmnames.txt)){
Try{
$vm = Get-VM -Name $vmName -ErrorAction Stop
New-Object PSObject -Property @{
Name = $vmName
vCenter = ([uri]$vm.ExtensionData.Client.ServiceUrl).Host
'VMware Tools Status' = $vm.ExtensionData.Guest.ToolsStatus
'VMware Tools version' = $vm.ExtensionData.Config.Tools.ToolsVersion
}
}
Catch{
New-Object PSObject -Property @{
Name = $vmName
vCenter = 'Not found'
'VMware Tools Status' = ''
'VMware Tools version' = ''
}
}
}
$report |
Group-Object -Property vCenter | %{
$_.Group |
Export-Csv -Path ".\$($_.Name)-$(Get-Date -Format 'ddMMyyyy-HHmm').csv" -NoTypeInformation -UseCulture
}
I require Guest OS version as well