This PowerShell script creates a new symbolic link file, linking to a target.
/home/markus/Repos/PowerShell/scripts/new-symlink.ps1 [[-symlink] <String>] [[-target] <String>] [<CommonParameters>]
-symlink <String>
Specifies the path to the new symlink file
Required? false
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-target <String>
Specifies the path to the target
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
PS> ./new-symlink.ps1 C:\User\Markus\Windows C:\Windows
✅ New symlink file 'C:\User\Markus\Windows' created, linking to: C:\Windows
Author: Markus Fleschutz | License: CC0
https://github.com/fleschutz/PowerShell
<#
.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
}
(generated by convert-ps2md.ps1 as of 11/20/2024 11:51:57)