Skip to content

Instantly share code, notes, and snippets.

@lipkau
Last active October 16, 2017 15:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lipkau/a7e3051dc264996a6d802d0e658236c1 to your computer and use it in GitHub Desktop.
Save lipkau/a7e3051dc264996a6d802d0e658236c1 to your computer and use it in GitHub Desktop.
Create new folder and naviagte into it #powershell #helperFunction #workflow
function New-Folder
{
<#
.Synopsis
Create a new folder and navigate into it
.Description
Create a new folder and navigate into it
.Notes
Author : Oliver Lipkau <oliver@lipkau.net>
Source : https://gist.github.com/lipkau/a7e3051dc264996a6d802d0e658236c1
.Inputs
System.String
.Parameter Path
Specifies the path of the folder to be created.
Path can be FQDN, UNC, Absolute or Relative.
.Example
New-Folder "C:\temp\myNewFolder"
-----------
Description
Create the folder with the path specifies and Set-Location (alias: 'cd') to that path
#>
[CmdletBinding()]
[OutputType()]
param(
[ValidateNotNullOrEmpty()]
[ValidateScript({(Test-Path $_ -IsValid)})]
[Parameter(ValueFromPipeline=$True,Mandatory=$True)]
[string]$Path
)
Process {
New-Object PSObject -Property @{path=$Path} |
New-Item -ItemType Directory |
Set-Location
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment