From 9e1156e90e7dc48f7bf4d41398234dc9a62a548f Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Mon, 20 Jan 2025 11:06:54 +0100 Subject: [PATCH] Added new-junction.ps1 --- scripts/new-junction.ps1 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 scripts/new-junction.ps1 diff --git a/scripts/new-junction.ps1 b/scripts/new-junction.ps1 new file mode 100644 index 00000000..81447c1a --- /dev/null +++ b/scripts/new-junction.ps1 @@ -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 +}