Last active
November 24, 2023 10:56
-
-
Save kenny-kvibe/9bf8c9cf739822b1d897b58e48df20b8 to your computer and use it in GitHub Desktop.
PowerShell: Shim-Link & Sym-Link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function New-ShimLink { | |
<# | |
.SYNOPSIS | |
Function New-ShimLink | |
Create a Shim Link. | |
.EXAMPLE | |
PS:\> New-ShimLink [LinkTargetPath] [LinkNewPath] | |
PS:\> New-ShimLink "C:\Folder\File1.txt" "C:\Folder\ShimLink1.txt" | |
.PARAMETER LinkTargetPath | |
[String, Pos0, Mandatory, Exists] | |
File/Folder path that will be Shim-Linked | |
.PARAMETER LinkNewPath | |
[String, Pos1, Mandatory] | |
File/Folder path that is the created ShimLink | |
.OUTPUTS | |
A new ShimLink file at "$LinkNewPath" location pointing to "$LinkNewPath". | |
.NOTES | |
Get-Help -Detailed New-ShimLink; | |
& "$Env:ChocolateyInstall\tools\shimgen.exe" --help; | |
Start-Process "https://docs.chocolatey.org/en-us/features/shim"; | |
#> | |
[CmdletBinding()] | |
Param ( | |
[Parameter(Position=0, Mandatory=$True)] | |
[ValidateScript({ Test-Path $_ })] | |
[System.String] | |
$LinkTargetPath, | |
[Parameter(Position=1, Mandatory=$True)] | |
[System.String] | |
$LinkNewPath | |
) | |
End { | |
& "$Env:ChocolateyInstall\tools\shimgen.exe" ` | |
--output="$LinkNewPath" ` | |
--path="$LinkTargetPath" ` | |
--iconpath="$LinkTargetPath"; | |
Return $?; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function New-SymLink { | |
<# | |
.SYNOPSIS | |
Function New-SymLink | |
Create a Symbolic Link. | |
.EXAMPLE | |
PS:\> New-SymLink [LinkTargetPath] [LinkNewPath] | |
PS:\> New-SymLink "C:\Folder\File1.txt" "C:\Folder\SymLink1.txt" | |
.PARAMETER LinkTargetPath | |
[String, Pos0, Mandatory, Exists] | |
File/Folder path that will be Sym-Linked | |
.PARAMETER LinkNewPath | |
[String, Pos1, Mandatory] | |
File/Folder path that is the created SymLink | |
.OUTPUTS | |
A new SymLink file at "$LinkNewPath" location pointing to "$LinkNewPath". | |
.NOTES | |
Get-Help -Detailed New-SymLink; | |
Get-Help -Detailed New-Item; | |
Start-Process "https://go.microsoft.com/fwlink/?LinkID=2096592"; | |
#> | |
[CmdletBinding()] | |
Param ( | |
[Parameter(Position=0, Mandatory=$True)] | |
[ValidateScript({ Test-Path $_ })] | |
[System.String] | |
$LinkTargetPath, | |
[Parameter(Position=1, Mandatory=$True)] | |
[System.String] | |
$LinkNewPath | |
) | |
End { | |
New-Item ` | |
-ItemType 'SymbolicLink' ` | |
-Path "$LinkNewPath" ` | |
-Target "$LinkTargetPath"; | |
Return $?; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment