New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while executing FixHostFilePermissions.ps1 #844

Closed
alaksandus opened this Issue Aug 8, 2017 · 24 comments

Comments

Projects
None yet
10 participants
@alaksandus

alaksandus commented Aug 8, 2017

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.

@JonathanHolvey

This comment has been minimized.

Show comment
Hide comment
@JonathanHolvey

JonathanHolvey Aug 9, 2017

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

JonathanHolvey commented Aug 9, 2017

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

@manojampalam

This comment has been minimized.

Show comment
Hide comment
@manojampalam

manojampalam Aug 14, 2017

Collaborator

@bingbing8 is looking into this.

Collaborator

manojampalam commented Aug 14, 2017

@bingbing8 is looking into this.

@bingbing8

This comment has been minimized.

Show comment
Hide comment
@bingbing8

bingbing8 Aug 14, 2017

Collaborator

@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"

Collaborator

bingbing8 commented Aug 14, 2017

@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"

@alaksandus

This comment has been minimized.

Show comment
Hide comment
@alaksandus

alaksandus Aug 15, 2017

@bingbing8 It doesn't matter if I copy/paste or type the text. Same error. My output of get-host and PSVersionTable is below:

PS C:\Program Files\OpenSSH> get-host

Name : ConsoleHost
Version : 5.1.14393.1532
InstanceId : 31db26d8-76a6-463a-aedc-99fffa55cb34
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : nl-NL
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace

PS C:\Program Files\OpenSSH> $PSVersionTable

Name Value


PSVersion 5.1.14393.1532
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.1532
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

alaksandus commented Aug 15, 2017

@bingbing8 It doesn't matter if I copy/paste or type the text. Same error. My output of get-host and PSVersionTable is below:

PS C:\Program Files\OpenSSH> get-host

Name : ConsoleHost
Version : 5.1.14393.1532
InstanceId : 31db26d8-76a6-463a-aedc-99fffa55cb34
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : nl-NL
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace

PS C:\Program Files\OpenSSH> $PSVersionTable

Name Value


PSVersion 5.1.14393.1532
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.1532
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

@bingbing8

This comment has been minimized.

Show comment
Hide comment
@bingbing8

bingbing8 Sep 5, 2017

Collaborator

@alaksandus , Can you paste the command line and output when you invoke the script? Are you just simply running
C:\Program Files\OpenSSH\FixHostFilePermissions.ps1 -confirm:$false

Collaborator

bingbing8 commented Sep 5, 2017

@alaksandus , Can you paste the command line and output when you invoke the script? Are you just simply running
C:\Program Files\OpenSSH\FixHostFilePermissions.ps1 -confirm:$false

@Dchan40

This comment has been minimized.

Show comment
Hide comment
@Dchan40

Dchan40 Sep 6, 2017

I get the same error by pasting that command line.
I get another error with quotation .

powershell.exe : Processing -File '.\FixHostFilePermission.ps1 -Confirm:False' failed: The given path's format is not supported.Specify a valid path for the -File parameter.
At line:1 Char:1

  • powershell.exe -ExecutionPolicy Bypass -File ".\FixHostFilePermission.ps1 -Conf ...
    +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    +CategoryInfo :NotSpecified: (Processing -Fil....File parameter.:String) [], RemoteException
    +FullyQualifiedErrorId :NativeCommandError

Dchan40 commented Sep 6, 2017

I get the same error by pasting that command line.
I get another error with quotation .

powershell.exe : Processing -File '.\FixHostFilePermission.ps1 -Confirm:False' failed: The given path's format is not supported.Specify a valid path for the -File parameter.
At line:1 Char:1

  • powershell.exe -ExecutionPolicy Bypass -File ".\FixHostFilePermission.ps1 -Conf ...
    +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    +CategoryInfo :NotSpecified: (Processing -Fil....File parameter.:String) [], RemoteException
    +FullyQualifiedErrorId :NativeCommandError
@bagajjal

This comment has been minimized.

Show comment
Hide comment
@bagajjal

bagajjal Sep 6, 2017

Collaborator

@Dchan40- you area missing $ before false..
It has to be be -Confirm:$false

Collaborator

bagajjal commented Sep 6, 2017

@Dchan40- you area missing $ before false..
It has to be be -Confirm:$false

@Dchan40

This comment has been minimized.

Show comment
Hide comment
@Dchan40

Dchan40 Sep 7, 2017

The command i key in does have the $.

Dchan40 commented Sep 7, 2017

The command i key in does have the $.

@bagajjal

This comment has been minimized.

Show comment
Hide comment
@bagajjal

bagajjal Sep 7, 2017

Collaborator

wiki URL has $

image

Are you referring to the same URL?

Collaborator

bagajjal commented Sep 7, 2017

wiki URL has $

image

Are you referring to the same URL?

@Dchan40

This comment has been minimized.

Show comment
Hide comment
@Dchan40

Dchan40 Sep 7, 2017

yea, i type exactly the same, except i have include the "" as to bingbing8 advise to add between ".\FixHostFilePermission.ps1 -Confirm:$false" since the original command give me the original posted error.

Dchan40 commented Sep 7, 2017

yea, i type exactly the same, except i have include the "" as to bingbing8 advise to add between ".\FixHostFilePermission.ps1 -Confirm:$false" since the original command give me the original posted error.

@bagajjal

This comment has been minimized.

Show comment
Hide comment
@bagajjal

bagajjal Sep 7, 2017

Collaborator

@Dchan40 - Please post the screen shot if the original command (-Confirm :$false) mentioned in the wiki fails..

Collaborator

bagajjal commented Sep 7, 2017

@Dchan40 - Please post the screen shot if the original command (-Confirm :$false) mentioned in the wiki fails..

@alaksandus

This comment has been minimized.

Show comment
Hide comment
@alaksandus

alaksandus Sep 7, 2017

@bingbing8 I'm executing the command like in the Wiki, so without the full path to the file.
.\FixHostFilePermissions.ps1 -Confirm:$false instead of C:\Program Files\OpenSSH\FixHostFilePermissions.ps1 -confirm:$false

alaksandus commented Sep 7, 2017

@bingbing8 I'm executing the command like in the Wiki, so without the full path to the file.
.\FixHostFilePermissions.ps1 -Confirm:$false instead of C:\Program Files\OpenSSH\FixHostFilePermissions.ps1 -confirm:$false

@thomasgeorgec

This comment has been minimized.

Show comment
Hide comment
@thomasgeorgec

thomasgeorgec Sep 7, 2017

still no solution?
even i got same issue
capture

thomasgeorgec commented Sep 7, 2017

still no solution?
even i got same issue
capture

@thomasgeorgec

This comment has been minimized.

Show comment
Hide comment
@thomasgeorgec

thomasgeorgec Sep 7, 2017

you can leave out "-confirm:$false" part, and type y to all prompts that follow
capture

thomasgeorgec commented Sep 7, 2017

you can leave out "-confirm:$false" part, and type y to all prompts that follow
capture

@bagajjal

This comment has been minimized.

Show comment
Hide comment
@bagajjal

bagajjal Sep 7, 2017

Collaborator

Can you please try this and let us know if it works..

  1. [bool]$f=$false
    .\FixHostFilePermissions.ps1 -Confirm:$f

  2. or
    .\FixHostFilePermissions.ps1 -Confirm:0

looks like powershell is treating $false as string instead of bool so an explicit conversion might be required.

Collaborator

bagajjal commented Sep 7, 2017

Can you please try this and let us know if it works..

  1. [bool]$f=$false
    .\FixHostFilePermissions.ps1 -Confirm:$f

  2. or
    .\FixHostFilePermissions.ps1 -Confirm:0

looks like powershell is treating $false as string instead of bool so an explicit conversion might be required.

@bingbing8

This comment has been minimized.

Show comment
Hide comment
@bingbing8

bingbing8 Sep 7, 2017

Collaborator

@thomasgeorgec, @JonathanHolvey, and @Dchan40, Looks like you run in cmd terminal. This is a powershell issue which has fixed in pscore. please refer to this issue and this PR. If you run the default powershell version on windows, you will still see this.

@alaksandus Did you run the script in powershell prompt or in cmd console? There is known powershell issue when run ps script in other shells than powershell. It should work fine in powershell prompt. Sorry for asking again. Can you paste screenshot include the command and output if you run in powershell prompt?

Collaborator

bingbing8 commented Sep 7, 2017

@thomasgeorgec, @JonathanHolvey, and @Dchan40, Looks like you run in cmd terminal. This is a powershell issue which has fixed in pscore. please refer to this issue and this PR. If you run the default powershell version on windows, you will still see this.

@alaksandus Did you run the script in powershell prompt or in cmd console? There is known powershell issue when run ps script in other shells than powershell. It should work fine in powershell prompt. Sorry for asking again. Can you paste screenshot include the command and output if you run in powershell prompt?

@bingbing8 bingbing8 self-assigned this Sep 8, 2017

@JW0914

This comment has been minimized.

Show comment
Hide comment
@JW0914

JW0914 Sep 13, 2017

[Disregard, see @bingbing8's reply below]

@alaksandus @joeyaiello @JonathanHolvey @Dchan40 @thomasgeorgec Fully reading instructions will prevent issues such as this...

  • 4th Bullet Down: Start Windows Powershell as Administrator
    • Windows requires Admin privileges to alter any directories/files contained within system folders
  • Non-Admin CMD Terminal
    C:\Program Files\OpenSSH>powershell -ExecutionPolicy Bypass -File .\FixHostFilePermissions.ps1 -Confirm:$false
    
    WARNING: Appended Windows PowerShell PSModulePath
    C:\Program Files\OpenSSH\FixHostFilePermissions.ps1 : Cannot convert 'System.String' to the type
    'System.Management.Automation.SwitchParameter' required by parameter 'Confirm'.
        + CategoryInfo          : InvalidArgument: (:) [FixHostFilePermissions.ps1], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : CannotConvertArgument,FixHostFilePermissions.ps1
    
    • Admin CMD Terminal:
      C:\Program Files\OpenSSH>powershell -ExecutionPolicy Bypass -File .\FixHostFilePermissions.ps1 -Confirm:$false
      
      WARNING: Appended Windows PowerShell PSModulePath
        [*] C:\Program Files\OpenSSH\sshd_config
            looks good
      
        [*] C:\Users\James\.ssh\authorized_keys
            looks good
      
         Done.
      
  • Non-Admin PS Terminal:
    PS C:\Program Files\OpenSSH> powershell -ExecutionPolicy Bypass -File .\FixHostFilePermissions.ps1 -Confirm:$false
    
    WARNING: Appended Windows PowerShell PSModulePath
      [*] C:\Program Files\OpenSSH\sshd_config
    Get-Acl : Attempted to perform an unauthorized operation.
    At C:\Program Files\OpenSSH\OpenSSHUtils.psm1:281 char:12
    +     $acl = Get-Acl $FilePath
    +            ~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Get-Acl], UnauthorizedAccessException
        + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetAclCommand
    
    The property 'owner' cannot be found on this object. Verify that the property exists.
    At C:\Program Files\OpenSSH\OpenSSHUtils.psm1:287 char:5
    +     $currentOwnerSid = Get-UserSid -User $acl.owner
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
        + FullyQualifiedErrorId : PropertyNotFoundStrict
    
    The property 'Owner' cannot be found on this object. Verify that the property exists.
    At C:\Program Files\OpenSSH\OpenSSHUtils.psm1:291 char:39
    +         $caption = "Current owner: '$($acl.Owner)'. '$newOwner' shoul ...
    +                                       ~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
        + FullyQualifiedErrorId : PropertyNotFoundStrict
    
    
    Current owner: ''. 'NT AUTHORITY\SYSTEM' should own 'C:\Program Files\OpenSSH\sshd_config'.
    Shall I set the file owner?
    [Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
    
    • Admin PS Terminal:
      PS C:\Program Files\OpenSSH> powershell -ExecutionPolicy Bypass -File .\FixHostFilePermissions.ps1 -Confirm:$false
      
      WARNING: Appended Windows PowerShell PSModulePath
        [*] C:\Program Files\OpenSSH\sshd_config
            looks good
      
        [*] C:\Users\JW0914\.ssh\authorized_keys
            looks good
      
         Done.
      

JW0914 commented Sep 13, 2017

[Disregard, see @bingbing8's reply below]

@alaksandus @joeyaiello @JonathanHolvey @Dchan40 @thomasgeorgec Fully reading instructions will prevent issues such as this...

  • 4th Bullet Down: Start Windows Powershell as Administrator
    • Windows requires Admin privileges to alter any directories/files contained within system folders
  • Non-Admin CMD Terminal
    C:\Program Files\OpenSSH>powershell -ExecutionPolicy Bypass -File .\FixHostFilePermissions.ps1 -Confirm:$false
    
    WARNING: Appended Windows PowerShell PSModulePath
    C:\Program Files\OpenSSH\FixHostFilePermissions.ps1 : Cannot convert 'System.String' to the type
    'System.Management.Automation.SwitchParameter' required by parameter 'Confirm'.
        + CategoryInfo          : InvalidArgument: (:) [FixHostFilePermissions.ps1], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : CannotConvertArgument,FixHostFilePermissions.ps1
    
    • Admin CMD Terminal:
      C:\Program Files\OpenSSH>powershell -ExecutionPolicy Bypass -File .\FixHostFilePermissions.ps1 -Confirm:$false
      
      WARNING: Appended Windows PowerShell PSModulePath
        [*] C:\Program Files\OpenSSH\sshd_config
            looks good
      
        [*] C:\Users\James\.ssh\authorized_keys
            looks good
      
         Done.
      
  • Non-Admin PS Terminal:
    PS C:\Program Files\OpenSSH> powershell -ExecutionPolicy Bypass -File .\FixHostFilePermissions.ps1 -Confirm:$false
    
    WARNING: Appended Windows PowerShell PSModulePath
      [*] C:\Program Files\OpenSSH\sshd_config
    Get-Acl : Attempted to perform an unauthorized operation.
    At C:\Program Files\OpenSSH\OpenSSHUtils.psm1:281 char:12
    +     $acl = Get-Acl $FilePath
    +            ~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Get-Acl], UnauthorizedAccessException
        + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetAclCommand
    
    The property 'owner' cannot be found on this object. Verify that the property exists.
    At C:\Program Files\OpenSSH\OpenSSHUtils.psm1:287 char:5
    +     $currentOwnerSid = Get-UserSid -User $acl.owner
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
        + FullyQualifiedErrorId : PropertyNotFoundStrict
    
    The property 'Owner' cannot be found on this object. Verify that the property exists.
    At C:\Program Files\OpenSSH\OpenSSHUtils.psm1:291 char:39
    +         $caption = "Current owner: '$($acl.Owner)'. '$newOwner' shoul ...
    +                                       ~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
        + FullyQualifiedErrorId : PropertyNotFoundStrict
    
    
    Current owner: ''. 'NT AUTHORITY\SYSTEM' should own 'C:\Program Files\OpenSSH\sshd_config'.
    Shall I set the file owner?
    [Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
    
    • Admin PS Terminal:
      PS C:\Program Files\OpenSSH> powershell -ExecutionPolicy Bypass -File .\FixHostFilePermissions.ps1 -Confirm:$false
      
      WARNING: Appended Windows PowerShell PSModulePath
        [*] C:\Program Files\OpenSSH\sshd_config
            looks good
      
        [*] C:\Users\JW0914\.ssh\authorized_keys
            looks good
      
         Done.
      
@bingbing8

This comment has been minimized.

Show comment
Hide comment
@bingbing8

bingbing8 Sep 13, 2017

Collaborator

@JW0914 , You might use latest powershell version from git. This issue is due to a powershell issue and this PR fixed it in pscore on git. but not fixed in Windows builtin powershell yet. I can repro it with Admin Cmd Terminal on windows 10. but there is nothing we can fix in our script.

Collaborator

bingbing8 commented Sep 13, 2017

@JW0914 , You might use latest powershell version from git. This issue is due to a powershell issue and this PR fixed it in pscore on git. but not fixed in Windows builtin powershell yet. I can repro it with Admin Cmd Terminal on windows 10. but there is nothing we can fix in our script.

@DarwinJS

This comment has been minimized.

Show comment
Hide comment
@DarwinJS

DarwinJS Sep 13, 2017

Collaborator

@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 ?

Collaborator

DarwinJS commented Sep 13, 2017

@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 ?

@JW0914

This comment has been minimized.

Show comment
Hide comment
@JW0914

JW0914 Sep 13, 2017

@bingbing8 I'm using PS 6 and wasn't aware of that, thanks =]

@DarwinJS The first two PowerShell script outputs were from a command terminal (cmd), whereas the latter two were from a PowerShell terminal.

In regards to syntax, I allow execution of remotely signed scripts, and have PowerShell added to PATH so I simply execute .\FixHostFilePermissions.ps1 from a PS terminal.

  • I used the commands in my above post as that was what was being used by users with the issue, and wasn't aware, until bingbing8's reply, that I wasn't having the issue because I'm using PS 6

JW0914 commented Sep 13, 2017

@bingbing8 I'm using PS 6 and wasn't aware of that, thanks =]

@DarwinJS The first two PowerShell script outputs were from a command terminal (cmd), whereas the latter two were from a PowerShell terminal.

In regards to syntax, I allow execution of remotely signed scripts, and have PowerShell added to PATH so I simply execute .\FixHostFilePermissions.ps1 from a PS terminal.

  • I used the commands in my above post as that was what was being used by users with the issue, and wasn't aware, until bingbing8's reply, that I wasn't having the issue because I'm using PS 6
@bingbing8

This comment has been minimized.

Show comment
Hide comment
@bingbing8

bingbing8 Sep 13, 2017

Collaborator

@thomasgeorgec, @JonathanHolvey, @alaksandus, and @Dchan40, please work around the issue as pointed above by @DarwinJS if you are not using pscore from git.

Collaborator

bingbing8 commented Sep 13, 2017

@thomasgeorgec, @JonathanHolvey, @alaksandus, and @Dchan40, please work around the issue as pointed above by @DarwinJS if you are not using pscore from git.

@thomasgeorgec

This comment has been minimized.

Show comment
Hide comment
@thomasgeorgec

thomasgeorgec Sep 14, 2017

@bingbing8 , @JW0914 , thank you very much. I worked around the manual way :)

thomasgeorgec commented Sep 14, 2017

@bingbing8 , @JW0914 , thank you very much. I worked around the manual way :)

@bingbing8 bingbing8 added this to the Sep-2017-End milestone Sep 18, 2017

@bingbing8

This comment has been minimized.

Show comment
Hide comment
@bingbing8

bingbing8 Sep 18, 2017

Collaborator

close this discussion since this is not an issue in our script.

Collaborator

bingbing8 commented Sep 18, 2017

close this discussion since this is not an issue in our script.

@petrkra

This comment has been minimized.

Show comment
Hide comment
@petrkra

petrkra Feb 1, 2018

It's simple:
Can not be used ""
You must use ''

the correct syntax is:

powershell.exe -ExecutionPolicy Bypass -Command '. .\FixHostFilePermissions.ps1 -Confirm:$false'

then everything will go right :-)

petrkra commented Feb 1, 2018

It's simple:
Can not be used ""
You must use ''

the correct syntax is:

powershell.exe -ExecutionPolicy Bypass -Command '. .\FixHostFilePermissions.ps1 -Confirm:$false'

then everything will go right :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment