new-item extra output

This topic contains 4 replies, has 4 voices, and was last updated by Profile photo of Rob Simmers Rob Simmers 1 year, 9 months ago.

  • Author
    Posts
  • #28278
    Profile photo of Shane Lindberg
    Shane Lindberg
    Participant

    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
    Profile photo of Vasken
    Vasken
    Participant

    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
    Profile photo of Shane Lindberg
    Shane Lindberg
    Participant

    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
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    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
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    Another option:

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

You must be logged in to reply to this topic.