mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-15 22:48:17 +02:00
Added new-junction.ps1
This commit is contained in:
parent
32927260bd
commit
9e1156e90e
33
scripts/new-junction.ps1
Normal file
33
scripts/new-junction.ps1
Normal file
@ -0,0 +1,33 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Create a junction
|
||||
.DESCRIPTION
|
||||
This PowerShell script creates a new junction, linking to a target.
|
||||
.PARAMETER junction
|
||||
Specifies the file path to the new junction
|
||||
.PARAMETER target
|
||||
Specifies the file path to the target
|
||||
.EXAMPLE
|
||||
PS> ./new-junction.ps1 D:\Win10 C:\Windows
|
||||
✅ Created new junction 'D:\Windows' linking to: C:\Windows
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$junction = "", [string]$target = "")
|
||||
|
||||
try {
|
||||
if ($junction -eq "" ) { $symlink = Read-Host "Enter new junction filename" }
|
||||
if ($target -eq "" ) { $target = Read-Host "Enter path to target" }
|
||||
|
||||
New-Item -path "$symlink" -itemType Junction -value "$target"
|
||||
if ($lastExitCode -ne "0") { throw "Command 'New-Item' has failed" }
|
||||
|
||||
"✅ Created new junction '$symlink' linking to: $target"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
Loading…
Reference in New Issue
Block a user