I have this powershell script that calls itself (because stage 1 of the script is to load assemblies in the GAC so i need AppDomain refreshed). How do I pass a switch parameter to self. At the moment I am doing this:
if ($provisionsites -eq $true)
{
powershell $currentDirectory/Deploy.ps1 -reload:$true -env:$env -provisionsites
}
else
{
powershell $currentDirectory/Deploy.ps1 -reload:$true -env:$env
}
It seems too verbose to me. If i try this:
powershell $currentDirectory/Deploy.ps1 -reload:$true -env:$env -provisionsites:$provisionsites
It fails with :
Cannot convert value “System.String” to type
“System.Management.Automat ion.SwitchParameter
Presumably call of
powershell.exeis not needed at all. Replace it with the operator&, i.e. call the script in the same session and avoid parameter transformations and related issues. The issues are resolvable but better be avoided in the first place. That is, doAs for the issues.
$provisionsitesis converted to a string (TrueorFalse, not$trueor$false) before passing in the external application. Thus, the result actual arguments look like-provisionsites:True. Then in a new powershell session it passes such an argument to the scriptDeploy.ps1. It fails because stringsTrueorFalseare not expected, a Boolean value is expected.A possible workaround would be adding escaped
$But consider to remove the call of
powershelland its issues.