mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-23 10:28:23 +02:00
Updated new-junction.ps1
This commit is contained in:
parent
e36021f3b2
commit
72b8c58768
@ -2,30 +2,30 @@
|
|||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Create a junction
|
Create a junction
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script creates a new junction, linking to a target.
|
This PowerShell script creates a new junction, linking to a target folder. The target folder can reside on another disk.
|
||||||
.PARAMETER junction
|
.PARAMETER junction
|
||||||
Specifies the file path to the new junction
|
Specifies the path and filename of the new junction
|
||||||
.PARAMETER target
|
.PARAMETER targetDir
|
||||||
Specifies the file path to the target
|
Specifies the path to the target directory
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./new-junction.ps1 D:\Win10 C:\Windows
|
PS> ./new-junction.ps1 C:\User\Joe\D_drive D:
|
||||||
✅ Created new junction 'D:\Windows' linking to: C:\Windows
|
✅ Created a new junction 'C:\User\Joe\D_drive', linking to 📂D:
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
Author: Markus Fleschutz | License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([string]$junction = "", [string]$target = "")
|
param([string]$junction = "", [string]$targetDir = "")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($junction -eq "" ) { $symlink = Read-Host "Enter new junction filename" }
|
if ($junction -eq "" ) { $symlink = Read-Host "Enter path and filename of the new junction" }
|
||||||
if ($target -eq "" ) { $target = Read-Host "Enter path to target" }
|
if ($targetDir -eq "" ) { $target = Read-Host "Enter the path to the target directory" }
|
||||||
|
|
||||||
New-Item -path "$symlink" -itemType Junction -value "$target"
|
New-Item -path "$symlink" -itemType Junction -value "$targetDir"
|
||||||
if ($lastExitCode -ne 0) { throw "Command 'New-Item' has failed" }
|
if ($lastExitCode -ne 0) { throw "Command 'New-Item' has failed" }
|
||||||
|
|
||||||
"✅ Created new junction '$symlink' linking to: $target"
|
"✅ Created a new junction '$symlink', linking to 📂$targetDir"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Loading…
Reference in New Issue
Block a user