Author Posts

August 7, 2015 at 6:34 pm

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?

August 7, 2015 at 6:45 pm

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 

August 7, 2015 at 7:11 pm

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.

August 8, 2015 at 5:12 am

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

August 8, 2015 at 6:38 am

Another option:

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