Skip to content
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

Fails when used in conjunction with the New-Junction command in PSCX #52

Open
Chirishman opened this issue Jan 26, 2024 · 0 comments
Open

Comments

@Chirishman
Copy link

Chirishman commented Jan 26, 2024

When invoked by the successful output of of the New-Junction command from the PowerShell Community Extensions module (https://github.com/Pscx/Pscx/) this error is thrown

New-Junction -TargetPath D:\Literary\unsorted\webcomic -LiteralPath D:\LitShare\unsorted_webcomic

FileInfo : You cannot call a method on a null-valued expression.
At C:\Users\Chirishman\Documents\WindowsPowerShell\Modules\Get-ChildItemColor\2.2.0\Get-ChildItemColor.psm1:182
char:17
+                 FileInfo $_
+                 ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [FileInfo], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull,FileInfo

Upon debugging the inner exception in FileInfo is:

You cannot call a method on a null-valued expression.
At C:\Users\Administrator\Documents\WindowsPowerShell\Modules\Get-ChildItemColor\2.2.0\FileInfo.ps1:33 char:5
+     $ParentName = $Item.PSParentPath.Replace("Microsoft.PowerShell.Co ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Stepping into FileInfo I find that the PSParentPath property is not present, though the Parent property is there

$_| select *


Mode              : d----l
BaseName          : ebooks
Target            : {D:\Literary\ebooks\}
LinkType          : Junction
Name              : ebooks
FullName          : D:\LitShare\ebooks
Parent            : LitShare
Exists            : True
Root              : D:\
Extension         :
CreationTime      : 1/26/2024 12:28:25 PM
CreationTimeUtc   : 1/26/2024 5:28:25 PM
LastAccessTime    : 1/26/2024 12:28:25 PM
LastAccessTimeUtc : 1/26/2024 5:28:25 PM
LastWriteTime     : 1/26/2024 12:28:25 PM
LastWriteTimeUtc  : 1/26/2024 5:28:25 PM
Attributes        : Directory, ReparsePoint

I believe that this is happening because the New-Junction command is implemented as a DLL and is not automatically appending that extra property

get-command New-Junction |select *


HelpUri             :
DLL                 : C:\Program Files\WindowsPowerShell\Modules\Pscx\3.3.2\Pscx.dll
Verb                : New
Noun                : Junction
HelpFile            : C:\Program Files\WindowsPowerShell\Modules\Pscx\3.3.2\Pscx.dll-Help.xml
PSSnapIn            :
Version             : 3.3.2
ImplementingType    : Pscx.Commands.IO.Ntfs.NewJunctionCommand
Definition          :
                      New-Junction [-LiteralPath] <PscxPathInfo> [-TargetPath] <PscxPathInfo> [-WhatIf] [-Confirm]
                      [<CommonParameters>]

DefaultParameterSet :
OutputType          : {}
Options             : ReadOnly
Name                : New-Junction
CommandType         : Cmdlet
Source              : Pscx
Visibility          : Public
ModuleName          : Pscx
Module              : Pscx
RemotingCapability  : PowerShell
Parameters          : {[LiteralPath, System.Management.Automation.ParameterMetadata], [TargetPath,
                      System.Management.Automation.ParameterMetadata], [Verbose,
                      System.Management.Automation.ParameterMetadata], [Debug,
                      System.Management.Automation.ParameterMetadata]...}
ParameterSets       : {[-LiteralPath] <PscxPathInfo> [-TargetPath] <PscxPathInfo> [-WhatIf] [-Confirm]
                      [<CommonParameters>]}

I think this could be solved by adding a fallback to dropping everything after the last slash in FullName if PSParentPath is missing though I've also reported it on that repo as a bug (Pscx/Pscx#99)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant