举个例子,让我更清楚我想做什么
$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
}
这可以正常工作。
我想做的是传递存储在对象'CSObject'的属性'CommonArgs'中的splatted参数,如下所示:
$CSObject =@ {
[PScustomObject]@{CommonArgs=$AzLogin;}
}
try{
Connect-Azaccount @CSObject.commonArgs -errorAction Stop
}catch{
Write-Host "Error: $($_.exception)" -foregroundcolor red
}