People,
How can I perform multiple VCenter connections using splatting?
Script:
$paramConnectVIServer1 = @{
Server = 'VCSA01'
User = 'DOMAIN\Admin1'
Password = 'Pass1'
}
$paramConnectVIServer2 = @{
Server = 'VCSA02'
User = 'DOMAIN\Admin2'
Password = 'Pass2'
}
$paramConnectVIServerN = @{
Server = 'VCSA0N'
User = 'DOMAIN\AdminN'
Password = 'PassN'
}
Connect-VIServer @paramConnectVIServer1, @paramConnectVIServer2, @paramConnectVIServerN
Error:
At line:19 char:18
+ Connect-VIServer @paramConnectVIServer1, @paramConnectVIServer2, @p ...
+ ~~~~~~~~~~~~~~~~~~~~~~
Splatted variables like '@paramConnectVIServer1' cannot be part of a comma-separated list of arguments.
At line:19 char:43
+ ... nect-VIServer @paramConnectVIServer1, @paramConnectVIServer2, @para ...
+ ~~~~~~~~~~~~~~~~~~~~~~
Splatted variables like '@paramConnectVIServer2' cannot be part of a comma-separated list of arguments.
At line:19 char:68
+ ... ramConnectVIServer1, @paramConnectVIServer2, @paramConnectVIServerN
+ ~~~~~~~~~~~~~~~~~~~~~~
Splatted variables like '@paramConnectVIServerN' cannot be part of a comma-separated list of arguments.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : SplattingNotPermittedInArgumentList
Thank you in advance.
Are you sure there are multiple entries in $global:DefaultVIServers?
If the DefaultVIServerMode from Set-PowerCLIConfiguration is not set to Multiple, you can only have 1 open connection.
You can check your current setting with Get-PowerCLIConfiguration.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I'm afraid you can't.
It has nothing to do with splatting.
The Connect-VIServer cmlet allows an array of strings on the Server parameter.
But the Credential parameter only allows 1 object.
So unless the credentials for all the vCenters are the same, it will not work.
Another option is to do 1 connection to all these vCenters with the SaveCredentials switch (does not work in PSv7).
Then subsequent connects can be done without the Credential parameter.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi @LucD,
Thank you for the explanation.
I'm trying to execute your code below:
$report = foreach ($vc in $global:DefaultVIServers)
{
Get-VMHost -Server $vc |
Select-Object Name, Version, Build, State, Powerstate,
@{ N = 'vCenter'; E = { ([uri]$vc.ServiceUri.AbsoluteUri).Host } },
@{ N = "Datacenter"; E = { (Get-datacenter -VMHost $_).name } },
@{ N = "Cluster"; E = { $_.Parent.Name } },
@{ N = "Model"; E = { (Get-EsxCli -VMHost $_.Name).hardware.platform.get().ProductName } },
@{ N = "Serial"; E = { (Get-EsxCli -VMHost $_.Name).hardware.platform.get().SerialNumber } },
@{ N = "NTPServer"; E = { $_ | Get-VMHostNtpServer } },
@{ N = "SyslogServer"; E = { $_ | Get-VMHostSysLogServer } }
}
$report
Include vCenter name in the Esxi report - VMware Technology Network VMTN
But somehow it only gathers the VCenter from the last connection?
Are you sure there are multiple entries in $global:DefaultVIServers?
If the DefaultVIServerMode from Set-PowerCLIConfiguration is not set to Multiple, you can only have 1 open connection.
You can check your current setting with Get-PowerCLIConfiguration.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference