Hi All,
I need some help in modifying the below PowerCLi script so it can be executed against multiple Center server?
$VCenter = @('PRDVC01-VM','VC03-VA','VCenter-PROD01')
$AdminUser = 'DOMAIN\Administrator'
$Password = 'XXyyZZ!@#'
Get-VIServer -Server $VCenter -User $AdminUser -Password $Password | Select Name, Version, Build
Thank you in advance.
You could do something like this
You really should stop using Get-VIServer, that cmdlet is very old and not used anymore since Connect-VIServer was introduced.
$AdminUser = 'DOMAIN\Administrator'
$Password = 'XXyyZZ!@#'
Connect-VIServer -Server $VCenter -User $AdminUser -Password $Password
foreach ($vc in $global:defaultviservers) {
Get-VM -PipelineVariable vm |
Get-Snapshot |
Select-Object @{N = 'vCenter'; E = { $vc.Name } },
@{N = 'vCenter Version'; E = { $vc.Version } },
@{N = 'vCenter Build'; E = { $vc.Build } },
@{N = 'VM'; E = { $_.VM.Name } },
Name, Description, Created, SizeGB
}
Disconnect-VIServer -Server * -Confirm:$false -Force
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not too sure what the question/problem is, besides that Get-VIServer is ancient and that you should use Connect-VIServer.
This works
$AdminUser = 'DOMAIN\Administrator'
$Password = 'XXyyZZ!@#'
Connect-VIServer -Server $VCenter -User $AdminUser -Password $Password | Select Name, Version, Build
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Thank you for chiming in this thread, I would like to get the VCenter information by looping through multiple VCenter.
By using the Connect-VIServer to multiple vCenters and using the pipeline you are looping through all vCenters.
Or does the result miss info from vCenters?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
yes, you are right, the below command works.
Get-VIServer -Server $VCenter -User $AdminUser -Password $Password | Select Name, Version, Build
However, if I wanted to check for any available VM Snapshot in each of those VCenters, what will be the command?
Get-Snapshot --> does not work after I put it under the above line.
Do I also need to manually disconnect all VI server connection to preserve memory?
You could do something like this
You really should stop using Get-VIServer, that cmdlet is very old and not used anymore since Connect-VIServer was introduced.
$AdminUser = 'DOMAIN\Administrator'
$Password = 'XXyyZZ!@#'
Connect-VIServer -Server $VCenter -User $AdminUser -Password $Password
foreach ($vc in $global:defaultviservers) {
Get-VM -PipelineVariable vm |
Get-Snapshot |
Select-Object @{N = 'vCenter'; E = { $vc.Name } },
@{N = 'vCenter Version'; E = { $vc.Version } },
@{N = 'vCenter Build'; E = { $vc.Build } },
@{N = 'VM'; E = { $_.VM.Name } },
Name, Description, Created, SizeGB
}
Disconnect-VIServer -Server * -Confirm:$false -Force
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That's great, thank you LucD.
I can now reuse the script for executing some command against multiple VCenters.
