param
(
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$True)]
[securestring]
$securityKey
)
powershell.exe -File $PSCommandPath -thisAppDomain @PSBoundParameters
This code throws the following error:
Cannot process argument transformation on parameter 'securityKey'. Cannot convert the "System.Security.SecureString" value of type "System.String" to type "System.Security.SecureString"
If I check the type of securityKey, its is a SecureString before its splatted. I assume its serializing it for some reason. How do I prevent this?
Edit
This use case may look strange so Ill provide some context. I need to ensure a specific version of an assembly is loaded when piping into this script. I'm using the thisAppDomain param to relaunch in a new app domain to attempt to accomplish this. Larger example:
.\FirstScript.ps1 | .\SecondScript.ps1
The secure string is piping in as expected, but is converted to a string when relaunching. This is how I relaunch:
if(-not $thisAppDomain)
{
Write-Host "Invoking script in a new app domain"
powershell.exe -File $PSCommandPath -thisAppDomain @PSBoundParameters
return;
}
-thisAppDomainmight be expecting. What is your powerShell version