Get-ChildItemColor
Get-ChildItemColor copied to clipboard
Fails when used in conjunction with the New-Junction command in PSCX
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 (https://github.com/Pscx/Pscx/issues/99)