Powershell silent mkdir

18,770

Solution 1

PetSerAl is correct, added to by SimonS
Out-Null is your best bet but as SimonS stated > $null is quicker

Solution 2

Just to add another solution: mkdir returns an object and if I just execute the code below, I don't have any output. Further more, I can use $dir to make my own output if needed

$dir = mkdir c:\foo\bar

As a side note, I've tested this PowerShell Version

PS> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      15063  1155
Share:
18,770

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin almost 2 years

    Is there a way to use mkdir (aka md) in powershell without verbose output? Currently, the output is as follows:

    PS C:\Users\myusername> mkdir foobar
    
    
        Directory: C:\Users\myusername
    
    
    Mode                LastWriteTime     Length Name
    ----                -------------     ------ ----
    d----        2016-12-07   9:35 AM            foobar
    PS C:\Users\myusername>
    

    Unless there's an error to report, I'd like it to be silent, as in

    PS C:\Users\myusername> mkdir foobar
    PS C:\Users\myusername>
    

    Is there a way to do this? I'm using Powershell version 2.

  • Admin
    Admin over 7 years
    Thanks! I would have marked PetSerAl's answer as correct, but since I can't this one gets the kudos.
  • FizxMike
    FizxMike about 6 years
    nope, doesn't work in PS for win 10.
  • FizxMike
    FizxMike about 6 years
    Instead, this seems to fail silently: [system.io.directory]::CreateDirectory("C:\test")
  • Lachie White
    Lachie White about 6 years
    @FizxMike sorry just seen this, works for me on a pretty regular basis on windows 10.
  • Honza P.
    Honza P. over 4 years
    This one seems to me as cool, clean and practical solution. Thanks.