Cannot dot-source this command
Hi All,
Were recently enabled applocker in our environment. We noticed that a few scripts stop functioning even when run from a location that is approved. Most notably any script with a PARAM section will fail to launch with error
Cannot dot-source this command because it was defined in a different language mode. To invoke this command without importing its contents, omit the '.' operator.
The only happens when calling that script with
powershell -file myscript.ps1
if you run the script with powershell myscript.ps1 it works fine. Replacing the PARAM section with code that uses $ARG instead also prevents the issue.
Removing the PARAM section from the script and just echoing the language mode shows that the script is run in FullLanguage Mode.
What I can't understand is why the use of PARAM will cause this? Does anyone have a clue here?
P.s. from https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe?view=powershell-5.1#-file----filepath-args I do understand that the use of -File is dot-sourcing the script. But it work just fine as long as I dont use PARAM