I'm seeing some inconsistent behaviour in PowerShell Core 7.3 with variables of type [System.IO.DirectoryInfo] - the following works as expected:
$dir = [System.IO.DirectoryInfo]'c:\deploy'
$dir.BaseName # returns 'deploy'
$dir.Name # returns 'deploy'
$dir.Parent.Name # returns 'c:\'
But where the assignment is a UNC share, the behaviour isn't as expected:
$target = [System.IO.DirectoryInfo]'\\sharedhost\Deploy'
$target.Name # returns '\\sharedhost\Deploy'
$target.BaseName # returns '\\sharedhost\Deploy'
$target.Parent.Name # returns nothing, checking shows that Parent is null
I would expect $target.Parent to be 'sharedhost' as that's the parent of the Deploy folder, but instead it returns $null.
I suppose I could temporarily map a drive to that share and use that mapping but that's a faff and besides drive-mapping might not be a robust option.
Can anyone please explain why DirectoryInfo doesn't appear to work as expected with UNC paths?
Thanks to the answer from @stackprotector, I've realised that I need to distinguish between local paths and UNC paths which must be treated differently.
Casting a full path name to type [URI] means that I can check if a path is a URI:
Thanks again for all the feedback and help.