PowerShell/docs/new-symlink.md

88 lines
2.3 KiB
Markdown
Raw Normal View History

2024-11-08 12:38:20 +01:00
The *new-symlink.ps1* Script
===========================
2022-11-17 20:02:26 +01:00
2024-11-08 12:35:11 +01:00
This PowerShell script creates a new symbolic link file, linking to a target.
2021-10-17 14:33:27 +02:00
2023-07-29 10:04:38 +02:00
Parameters
----------
2021-10-17 14:33:27 +02:00
```powershell
2024-11-08 12:35:11 +01:00
/home/markus/Repos/PowerShell/scripts/new-symlink.ps1 [[-symlink] <String>] [[-target] <String>] [<CommonParameters>]
2023-05-26 12:20:18 +02:00
-symlink <String>
2024-11-08 12:35:11 +01:00
Specifies the path to the new symlink file
2023-05-26 12:20:18 +02:00
Required? false
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
2021-10-17 14:33:27 +02:00
2023-05-26 12:20:18 +02:00
-target <String>
2024-11-08 12:35:11 +01:00
Specifies the path to the target
2023-05-26 12:20:18 +02:00
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
2021-10-17 14:33:27 +02:00
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
2023-07-29 10:04:38 +02:00
Example
-------
2023-05-26 12:20:18 +02:00
```powershell
2024-11-08 12:35:11 +01:00
PS> ./new-symlink.ps1 C:\User\Markus\Windows C:\Windows
✅ New symlink file 'C:\User\Markus\Windows' created, linking to: C:\Windows
2023-05-26 12:20:18 +02:00
```
2023-07-29 10:04:38 +02:00
Notes
-----
2023-05-26 12:20:18 +02:00
Author: Markus Fleschutz | License: CC0
2023-07-29 10:04:38 +02:00
Related Links
-------------
2023-05-26 12:20:18 +02:00
https://github.com/fleschutz/PowerShell
2023-07-29 10:04:38 +02:00
Script Content
--------------
2022-11-17 20:05:34 +01:00
```powershell
2022-11-17 20:02:26 +01:00
<#
.SYNOPSIS
2024-11-08 12:35:11 +01:00
Creates a new symlink
2022-11-17 20:02:26 +01:00
.DESCRIPTION
2024-11-08 12:35:11 +01:00
This PowerShell script creates a new symbolic link file, linking to a target.
2022-11-17 20:02:26 +01:00
.PARAMETER symlink
2024-11-08 12:35:11 +01:00
Specifies the path to the new symlink file
2022-11-17 20:02:26 +01:00
.PARAMETER target
2024-11-08 12:35:11 +01:00
Specifies the path to the target
2022-11-17 20:02:26 +01:00
.EXAMPLE
2024-11-08 12:35:11 +01:00
PS> ./new-symlink.ps1 C:\User\Markus\Windows C:\Windows
✅ New symlink file 'C:\User\Markus\Windows' created, linking to: C:\Windows
2022-11-17 20:02:26 +01:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
2023-05-26 12:20:18 +02:00
param([string]$symlink = "", [string]$target = "")
2022-11-17 20:02:26 +01:00
try {
2024-11-08 12:35:11 +01:00
if ($symlink -eq "" ) { $symlink = Read-Host "Enter new symlink filename" }
if ($target -eq "" ) { $target = Read-Host "Enter path to target" }
2022-11-17 20:02:26 +01:00
2024-11-08 12:35:11 +01:00
New-Item -path "$symlink" -itemType SymbolicLink -value "$target"
2022-11-17 20:02:26 +01:00
2024-11-08 12:35:11 +01:00
"✅ New symlink file '$symlink' created, linking to: $target"
2022-11-17 20:02:26 +01:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
2022-11-17 20:05:34 +01:00
```
2022-11-17 20:02:26 +01:00
2024-11-20 11:52:20 +01:00
*(generated by convert-ps2md.ps1 as of 11/20/2024 11:51:57)*