functions/explorer/New-PSUDirectory.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function New-PSUDirectory
{
<#
    .SYNOPSIS
        Creates a folder and moves the current path to it.
     
    .DESCRIPTION
        Creates a folder and moves the current path to it.
     
    .PARAMETER Path
        Name of the folder to create and move to.
     
    .EXAMPLE
        PS C:\> mcd Test
     
        creates folder C:\Test, then moves the current location to it.
     
    .NOTES
        Author: Donovan Brown
        Source: http://donovanbrown.com/post/How-to-create-and-navigate-a-directory-with-a-single-command
     
        Thank you for sharing and granting permission to use this convenience :)
#>

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        $Path
    )
    
    New-Item -Path $Path -ItemType Directory
    
    Set-Location -Path $Path
}

Import-PSUAlias -Name "mcd" -Command "New-PSUDirectory"