Reputation: 11677
For instance, I can type gci hkcu:
and get a list of registry entries back, or I could type gci c:\
and get a directory listing.
Assuming $list
holds the result of one of these queries, how can I tell what I'm dealing with?
I could, of course, just perform something like $list[0].GetType()
and parse the result, but that's not very robust, and besides, what would I do with an empty list? (Which means I'm probably asking the wrong question, since I think I need to know the answer before I actually call gci
.)
Upvotes: 2
Views: 163
Reputation: 11677
While trying to code around the issue, I stumbled upon the answer:
(Get-ItemProperty $path).PSProvider.Name
This will return one of the providers listed in Get-PSProvider
, and they are (typically) unchanging.
Upvotes: 4
Reputation: 301137
You can do the below maybe:
$path = "HKCU:"
$qualifier = (split-path $path -Qualifier).Trim(":")
get-psdrive | ?{ $_.Name -eq $qualifier } | select provider
If the path is relative use resolve-path $path
Also you don't have to use gci
on the path. you can just use gi
:
(gi hkcu:).gettype()
Upvotes: 3
Reputation: 19203
The easiest way is to handle what is passed into gci, rather than attempting to handle the output. Then all you have to do is look before the :
, or worst case check the "local" directory.
Upvotes: 0