SolvedWin32 OpenSSH Error while executing FixHostFilePermissions.ps1

Please answer the following

"OpenSSH for Windows" version
v0.0.18.0

Server OperatingSystem
Windows 10 IoT LTSB 2016 (aka 1607)

What is failing
I followed the instructions for installing: https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH

But I get an error while executing .\FixHostFilePermissions.ps1 -Confirm:$false

Expected output
All permissions set correctly. With the -Confirm:$false switch I expect no user interaction.

Actual output
C:\Program Files\OpenSSH\FixHostFilePermissions.ps1 : Cannot convert 'System.String' to the type 'System.Management.Aut
omation.SwitchParameter' required by parameter 'Confirm'.
+ CategoryInfo : InvalidArgument: (:) [FixHostFilePermissions.ps1], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CannotConvertArgument,FixHostFilePermissions.ps1

Additional information
If I remove -Confirm:$false and execute the script it works well, but I have to confirm every step.

25 Answers

✔️Accepted Answer

@JW0914 - You might want to try -command syntax to call the file like this:

Powershell.exe -ExecutionPolicy Bypass -Command ". .\FixHostFilePermissions.ps1 -Confirm:$false"

Note the first "." is a call operator.

In your actual execution scenario what is calling Powershell.exe ?

Other Answers:

I had the same error yesterday, and got around it by leaving off the option -Confirm:$false from the end of the command.

@JonathanHolvey and @alaksandus I don't repro the issue when run the script from pwoershell prompt window. Not sure why your output does not include the command actually run. From your message, looks like powershell treat $false as type of system.string. My guess is you may invoke the script using quotes. If that is the case, you need to escape $, for example,
iex ".\FixHostFilePermissions.ps1 -Confirm:`$False"

More Issues: