New-Item -ItemType

This topic contains 7 replies, has 4 voices, and was last updated by Profile photo of Greg Tate Greg Tate 4 months, 3 weeks ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #38904
    Profile photo of Greg Tate
    Greg Tate
    Participant

    How can I get a full list of values for the -ItemType parameter in New-Item?

    I realize that directory and file are acceptable values for the filesystem provider. But where in the help can I confirm this information? Or what command can I run to show it.

    #38907
    Profile photo of Liam Kemp
    Liam Kemp
    Participant

    Hey Greg,
    That's a good question, i'm not too sure about how to automatically/quickly get a list of values for a parameter. But in this case, its a short list so tabbing through works ok.
    File
    Directory
    SymbolicLink – I think this is V 5 only
    Junction
    HardLink

    I'd be interested to know if there was an easy way to pull this from powershell though.

    Liam

    #38909
    Profile photo of Paul Frankovich
    Paul Frankovich
    Participant

    If it were an Enum you could easily pull the list but I think Liam points out the only way to find something that appears to just be a ValidateSet.

    #38922
    Profile photo of Greg Tate
    Greg Tate
    Participant

    Thanks for the response guys.
    The tab option is a sufficient enough workaround to satisfy my curiosity.

    This question was asked five years ago on the TechNet forums:
    https://social.technet.microsoft.com/Forums/scriptcenter/en-US/4e35f397-d8ad-406d-8ef0-11210ab9f37e/getting-list-of-itemtype-options-for-the-newitem-cmdlet?forum=ITCG

    A feature request was filed on connect here:
    https://connect.microsoft.com/PowerShell/feedback/details/677346/retrieve-list-of-possible-itemtypes-for-a-provider

    There was a response in January indicating you can also press CTRL+spacebar to retrieve a list of possible values. This is new in PowerShell 5.

    #38926
    Profile photo of Paul Frankovich
    Paul Frankovich
    Participant

    That only works in the ISE, but it is a good start.

    #38927
    Profile photo of Greg Tate
    Greg Tate
    Participant

    I find that it works in the shell as well, at least on 1511.

    Give it a try and see:

    New-item c:\newitem.txt -ItemType CTRL+spacebar

    #38931
    Profile photo of Don Jones
    Don Jones
    Keymaster

    The thing is that New-Item is largely dynamic. What values are valid depends on the PSDrive you're in at the time. So there's no static enumeration. The command does expose tab completion, but it's dependent on the PSProvider providing the valid values. Some will, some won't.

    #38934
    Profile photo of Greg Tate
    Greg Tate
    Participant

    Understood.
    Again, appreciate the replies everyone!

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.