Hi,
I'm running a below script to get the status of ESXi services from multiple vCenters at the same time.
$vcservers = @("test-vcenter", "test-vcenter1"..."test-vcenter12")
Foreach ($vc in $vcservers){
Connect-VIServer $vc
}
Get-VMHost | Get-VMHostService | Where-Object {$_.Key -eq 'TSM' -or $_.Key -eq 'TSM-SSH' -or $_.Key -eq 'ntpd'} | Select-Object -Property VMHost, vcenter, Key, Label, Policy, Running | export-csv -Path c:\ssh.csv -NoTypeInformation -UseCulture
Script gathers the services status from all the vCenters successfully, however 'vcenter' column define in Object doesn't show the respective VC name. Tried couple of logics but no luck.
Can someone please help to modify the script to get the respective vCenter's name in the vcenter column.
Also, is there any option we can define credentials in the same script?
This will show the vCenter
$vcservers = @("test-vcenter", "test-vcenter1"..."test-vcenter12")
Foreach ($vc in $vcservers) {
Connect-VIServer $vc
}
Get-VMHost |
Get-VMHostService |
Where-Object { $_.Key -eq 'TSM' -or $_.Key -eq 'TSM-SSH' -or $_.Key -eq 'ntpd' } |
Select-Object -Property VMHost, @{N = 'vcenter'; E = { ([uri]$_.VMHost.ExtensionData.Client.ServiceUrl).Host} }, Key, Label, Policy, Running |
Export-Csv -Path c:\ssh.csv -NoTypeInformation -UseCulture
I assume you mean credentials for the Connect-VIServer cmdlet?
If yes, and if you are running this in a PS 5.* session on a Windows OS, you could use the New-VICredentialStoreItem cmdlet to maintain a list of hosts, users, and passwords.
If you are running PS in a higher version or on a non-Windows OS, you can use any of the local solutions to securely store and retrieve credentials.
I would never put credentials in a script directly!
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This will show the vCenter
$vcservers = @("test-vcenter", "test-vcenter1"..."test-vcenter12")
Foreach ($vc in $vcservers) {
Connect-VIServer $vc
}
Get-VMHost |
Get-VMHostService |
Where-Object { $_.Key -eq 'TSM' -or $_.Key -eq 'TSM-SSH' -or $_.Key -eq 'ntpd' } |
Select-Object -Property VMHost, @{N = 'vcenter'; E = { ([uri]$_.VMHost.ExtensionData.Client.ServiceUrl).Host} }, Key, Label, Policy, Running |
Export-Csv -Path c:\ssh.csv -NoTypeInformation -UseCulture
I assume you mean credentials for the Connect-VIServer cmdlet?
If yes, and if you are running this in a PS 5.* session on a Windows OS, you could use the New-VICredentialStoreItem cmdlet to maintain a list of hosts, users, and passwords.
If you are running PS in a higher version or on a non-Windows OS, you can use any of the local solutions to securely store and retrieve credentials.
I would never put credentials in a script directly!
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi @LucD ,
Thank you so much for the quick response. This is working as expected now.
Thanks for the suggestions on the Credentials part. Let me try it and see how I can define different credentials for multiple vCenters.
Have a great day ahead
Hi @LucD,
I defined multiple VC's in the script. I observed that VC column is blank for few hosts and there are some duplicate entries for the hosts as well.
Anything I'm missing here?
Are some of your vCenters perhaps in linked mode?
If they are, you could try to add the -AllLinked:$false parameter to the Connect-VIServer cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
No. None of the VC's are in linked mode. Do we need to disconnect VC before it jumps on next VC?
No, if the DefaultVIServerMode (Get/Set-PowerCLIConfiguration) is set to Multiple, all ESXi nodes from the connected vCenters should be returned by the Get-VMHost cmdlet.
You can check if Get-VMHost on it's own also shows duplicates.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference