forked from fleschutz/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new-symlink.ps1
executable file
·32 lines (28 loc) · 941 Bytes
/
new-symlink.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
<#
.SYNOPSIS
Creates a new symlink
.DESCRIPTION
This PowerShell script creates a new symbolic link file, linking to a target.
.PARAMETER symlink
Specifies the path to the new symlink file
.PARAMETER target
Specifies the path to the target
.EXAMPLE
PS> ./new-symlink.ps1 C:\User\Markus\Windows C:\Windows
✅ New symlink file 'C:\User\Markus\Windows' created, linking to: C:\Windows
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$symlink = "", [string]$target = "")
try {
if ($symlink -eq "" ) { $symlink = Read-Host "Enter new symlink filename" }
if ($target -eq "" ) { $target = Read-Host "Enter path to target" }
New-Item -path "$symlink" -itemType SymbolicLink -value "$target"
"✅ New symlink file '$symlink' created, linking to: $target"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}