question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PSDriveInfo is null for Get-Item -Path <provider qualified path>

See original GitHub issue

Prerequisites

Steps to reproduce

I’m implementing a custom cmdlet provider and stumbled upon an issue with provider qualified path:

  • When getting an item with a rooted path like drive:/path/to/item the provider instance has assigned a PSDriveInfo instance on invocation by the base provider.
  • When getting an item with a provider qualified path: provider\qualified::drive:/path/to/item the provider is invoked without having a PSDriveInfo instance assigned.

Within the provider I can compensate by parsing the drive name from the path and fetch the drive info from the session state: SessionState.Drive.Get("drive").

Also this changes the returned item which can be observed by the user:

  • Get-item C:\ | fl * shows a PSDrive property.
  • 'Get-item “Microsoft.PowerShell.Core\FileSystem::c:\ | fl *” doesn’t show a PSDrive property.

I’ve debugged this with the code base for v7.2.6 and it look to me that LocationGlobber.GetProviderPath(..) should return the drive info in this case as well or should be called a second time with the provider name removed from the paths maybe?

Expected behavior

PS> (get-item "Microsoft.PowerShell.Core\FileSystem::c:\").PSDrive -eq $null
False

Actual behavior

PS> (get-item "Microsoft.PowerShell.Core\FileSystem::c:\").PsDrive -eq $null
True

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.6
PSEdition                      Core
GitCommitId                    7.2.6
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
wgrosscommented, Aug 29, 2022

I see, thank you!

0reactions
iSazonovcommented, Aug 30, 2022

This is definitely a departure from basic PowerShell concepts. Fixing this was declined in #5785.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AccessDBProviderSample06 - PowerShell
This sample shows how to overwrite content methods to support calls to the Clear-Content , Get-Content , and Set-Content cmdlets. These methods ...
Read more >
Powershell Provider - GetItem Path Error - Custom File as ...
I am trying to create my custom Powershell Provider that is derived from NavigationCmdletProvider. I have overridden PSDriveInfo to read and ...
Read more >
Exchange 2016 CU6 craches
Guys,After trying to update the Exchange 2016 to CU6 its keep craching everytime.the below error is and hope someone can ad.
Read more >
Exchange 2013 CU16 and CU17 failed cannot find path \ ...
Like this one, it states that it cannot find the path to the folder "grammars" ... PSDriveInfo drive, ContainerCmdletProvider provider, S.
Read more >
Professional Windows PowerShell Programming: Snapins, ...
Snapins, Cmdlets, Hosts and Providers Arul Kumaravel. the path values passed to ItemExists() may be fully qualified or drive qualified.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found