Skip to content

Instantly share code, notes, and snippets.

@erinxocon
Created July 4, 2020 05:01
Show Gist options
  • Save erinxocon/1783b7a6f65abe0c081354ddfb839d81 to your computer and use it in GitHub Desktop.
Save erinxocon/1783b7a6f65abe0c081354ddfb839d81 to your computer and use it in GitHub Desktop.
function New-Link {
param (
[Parameter(HelpMessage = "make a symbolic link", ParameterSetName = "switch")]
[Alias("symbolic")]
[switch]
$s,
[Parameter(HelpMessage = "make a hard link", ParameterSetName = "switch")]
[Alias("physical", "hard")]
[switch]
$P,
[Parameter(HelpMessage = "make a junction", ParameterSetName = "switch")]
[Alias("junction")]
[switch]
$j,
[Parameter(Mandatory = $true, Position = 0, HelpMessage = "The name of the link to access the target")]
[ValidateNotNullOrEmpty()]
[string]
$link_name,
[Parameter(Mandatory = $true, Position = 1, HelpMessage = "The taget the link directs to.")]
[ValidateNotNullOrEmpty()]
[string]
$target
)
if ($s) {
New-Item -Path $link_name -ItemType SymbolicLink -Value $target
}
elseif ($P) {
New-Item -ItemType HardLink -Name $link_name -Target $target
}
elseif ($j) {
New-Item -ItemType Junction -Name $link_name -Target $target
}
}
Set-Alias -name ln -Value New-Link
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment