Functions/Profile/Start-ProfileDrive.ps1
<# .SYNOPSIS Create a new PSDrive and add alias functions. .DESCRIPTION Create a new PSDrive which points to the provided path and create alias functions to easily switch to the PSDrives. .PARAMETER Name The name for the new PSDrive. .PARAMETER Path The target path of the PSDrive. .PARAMETER Alias A list of aliases which will be used to create quick access functions. .PARAMETER Description The description for the new PSDrive. .INPUTS None. .OUTPUTS None. .EXAMPLE Start-ProfileDrive -Name 'Temp' -Path 'C:\Temp' Create a new PSDrive named Temp which points to the folder C:\Temp. .EXAMPLE Start-ProfileDrive -Name 'PowerShell' -Path "$HOME\Documents\WindowsPowerShell" -Alias 'PS', 'PowerShell' Create a new PSDrive named PowerShell which points to the users PowerShell folder. In addition create two alias functions called PowerShell: and PS: to easily switch to the new PSDrive. .NOTES Author : Claudio Spizzi License : MIT License .LINK https://github.com/claudiospizzi/Spizzi.Profile #> function Start-ProfileDrive { [CmdletBinding()] param ( [Parameter(Mandatory = $true, Position = 0)] [System.String] $Name, [Parameter(Mandatory = $true, Position = 1)] [ValidateScript({ Test-Path -Path $_ })] [System.String] $Path, [Parameter(Mandatory = $false, Position = 2)] [System.String[]] $Alias, [Parameter(Mandatory = $false, Position = 3)] [System.String] $Description = '' ) try { $PSDrive = @{ PSProvider = 'FileSystem' Scope = 'Global' Name = $Name Root = $Path Description = $Description } New-PSDrive @PSDrive -ErrorAction Stop | Out-Null foreach ($AliasName in $Alias) { Set-Item -Path "Function:Global:$AliasName`:" -Value "Set-Location -Path '$Name`:'" -ErrorAction Stop } } catch { Write-Warning -Message "Unable to create the '$Name' profile drive: $_" } } |