VMware Cloud Community
AlbertWT
Virtuoso
Virtuoso
Jump to solution

Unable to execute multiple Splat for multi VCenter connection ?

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.

/* Please feel free to provide any comments or input you may have. */
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

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

AlbertWT
Virtuoso
Virtuoso
Jump to solution

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?

/* Please feel free to provide any comments or input you may have. */
0 Kudos
AlbertWT
Virtuoso
Virtuoso
Jump to solution

No, the credentials are all different.
/* Please feel free to provide any comments or input you may have. */
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
AlbertWT
Virtuoso
Virtuoso
Jump to solution

yes, that's fix the issue 🙂 thanks LucD
/* Please feel free to provide any comments or input you may have. */
0 Kudos