Going to give an example to make it clearer what I want to do
$AzLogin = @{
Subscription = [string] 'SubscriptionID';
Tenant = [string] 'tenantID';
Credential = [System.Management.Automation.PSCredential] $credsServicePrincipal;
ServicePrincipal = $true;
}
try{
Connect-Azaccount @$AzLogin -errorAction Stop
}catch{
Write-Host "Error: $($_.exception)" -foregroundcolor red
}
This works correctly.
The one I want to do is pass splatted arguments stored in property 'CommonArgs' of object 'CSObject', something like this:
$CSObject =@ {
[PScustomObject]@{CommonArgs=$AzLogin;}
}
try{
Connect-Azaccount @CSObject.commonArgs -errorAction Stop
}catch{
Write-Host "Error: $($_.exception)" -foregroundcolor red
}
You can only splat a variable as a whole, not an expression that returns a property value - as of PowerShell 7.1
A variable used for splatting may only contain a hashtable (containing parameter-name-and-argument pairs, as in your question) or an array (containing positional arguments), not a
[pscustomobject]
- see about_Splatting.Something like the following should work: