Question:
I have a script as below
[string]$newValue = Get-ConfigurationByType $setting.Value
After this line, the value of $newValue is
1 |
"http://ST-$($partner.Alias).vardiaforsakring.se/CardPaymentAgreementCallback.aspx" |
In the loop, I call ExpandString
foreach ($partner in $partners)
{
$partnerSpecificValue =$ExecutionContext.InvokeCommand.ExpandString($newValue)
}
It throws exception
1 2 3 4 5 6 |
Exception calling "ExpandString" with "1" argument(s): "Object reference not set to an instance of an object." At C:\Programs\Drops\Hydra_SE_v1.28\HydraDeploymentFunctions.ps1:342 char:5 + $partnerSpecificValue = $ExecutionContext.InvokeCommand.ExpandString($newVal ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : NullReferenceException |
But when I try to input hard-code string, it returns expected result without exception
1 |
$partnerSpecificValue =$ExecutionContext.InvokeCommand.ExpandString("http://ST-$($partner.Alias).vardiaforsakring.se/CardPaymentAgreementCallback.aspx") |
The value of $partnerSpecificValue is
1 |
http://ST-secure.vardiaforsakring.se/CardPaymentAgreementCallback.aspx |
Does anyone know a workaround to resolve this bug? Thank you very much. I am running PowerShell v4.0 on Windows Server 2012 R2.
Answer:
I have a workaround for this bug.