Skip to content

Cannot bind argument to parameter 'Path' because it is an empty string. #2361

Closed
PowerShell/openssh-portable
#792

Description

@ZvezdomirMilanov

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Steps to reproduce

When installing and running FixHostFilePermissions.ps1 if there is left empty sid in registry error pops up:
Cannot bind argument to parameter 'Path' because it is an empty string.
However it is not an error but a bug in script.
Bracket which closes if $properties on line 51 should be moved between 56 and 57.
When there is empty properties it should not try to join paths.

Expected behavior

When there is empty properties it should not try to join paths.

Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"  -ErrorAction SilentlyContinue | % {
    $properties =  Get-ItemProperty $_.pspath  -ErrorAction SilentlyContinue
    $userProfilePath = ""
    if($properties)
    {
        $userProfilePath =  $properties.ProfileImagePath
        $filePath = Join-Path $userProfilePath .ssh\authorized_keys
    if(Test-Path $filePath -PathType Leaf)
    {
        Repair-AuthorizedKeyPermission -FilePath $filePath @psBoundParameters
    }
   }
}

Actual behavior

Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"  -ErrorAction SilentlyContinue | % {
    $properties =  Get-ItemProperty $_.pspath  -ErrorAction SilentlyContinue
    $userProfilePath = ""
    if($properties)
    {
        $userProfilePath =  $properties.ProfileImagePath
    }
    $filePath = Join-Path $userProfilePath .ssh\authorized_keys
    if(Test-Path $filePath -PathType Leaf)
    {
        Repair-AuthorizedKeyPermission -FilePath $filePath @psBoundParameters
    }
}

Error details

Join-Path : Cannot bind argument to parameter 'Path' because it is an empty string.
At C:\Program Files\OpenSSH\FixHostFilePermissions.ps1:52 char:27
+     $filePath = Join-Path $userProfilePath .ssh\authorized_keys
+                           ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.Join
   PathCommand

Environment data

Can not do that

Version

on all versions it exist

Visuals

No response

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址