Powershell silent mkdir

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.

5

3 Answers

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

4

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
1

Make a function

function silentMkdir { $sink = mkdir $args }

Make an alias in the current shell only that uses that function

Set-Alias -Name mkdir -Value silentMkdir -Scope Private

PS: I'm new to Powershell but this seemed to work. Without the -Scope Private mkdir will be changed for scripts called from this shell. With -Scope Private that issue seems to go away.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like