new-item extra output

This topic contains 4 replies, has 4 voices, and was last updated by  Rob Simmers 2 years, 9 months ago.

  • Author
  • #28278

    Shane Lindberg

    when using the new-item cmdlet it gives the output of what appears to be get-childitem. Is this normal,

    PS C:\Users\shane> New-Item -type file test.txt
        Directory: C:\Users\shane
    Mode                LastWriteTime     Length Name                                                      
    ----                -------------     ------ ----                                                      
    -a---          8/7/2015   9:30 PM          0 test.txt        

    how would I supress this output?

  • #28279


    The documentation for New-Item (man New-Item) don't seem to provide any way of doing this, so short of piping the command to Out-Null I'm not sure what other options are available- though perhaps others on here do.

    PS C:\Users\shane> New-Item -type file test.txt | Out-Null 
  • #28280

    Shane Lindberg

    Thanks for the answer.

    I feel like it did not give me all the output in the other past times I ran it, only some of the times. I am feeling a bit crazy.

  • #28285

    Richard Siddaway

    New-Item -Type File -Name test1.txt | Out-Null
    [void](New-Item -Type File -Name test2.txt)
    New-Item -Type File -Name test3.txt > $null
    $nf = New-Item -Type File -Name test4.txt

    can all be used to mask output. I prefer the first one

  • #28289

    Rob Simmers

    Another option:

    $null = New-Item -Type File -Name test1.txt -Path C:\temp -Force

You must be logged in to reply to this topic.