2

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.)

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Assuming $list holds the result of one of these queries: @($list)[0].PSProvider.Name
3

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()

Comments

0

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.

2 Comments

One issue with this is that this won't work for the following: cd hkcu:; gci.
Ignore my previous comment, I didn't grok your "worst case" line right away.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.