Public/Manager.Links.ps1
function Set-DirSymbolicLinkWithSync{ <# .DESCRIPTION Set a directory symbolic link from the path to the target. Then, get a result as $path\rightarrow target$, which means the path is a symbolic link to the target. .PARAMETER Path The path to be set. .PARAMETER Target The target path. .PARAMETER BackupDir The backup directory path. .OUTPUTS None. #> [CmdletBinding(SupportsShouldProcess)] param( [Parameter(Mandatory)] [string]$Path, [Parameter(Mandatory)] [string]$Target, [Parameter(Mandatory)] [string]$BackupDir ) Assert-IsWindowsAndAdmin if ($PSCmdlet.ShouldProcess("Set a directory symbolic link from $Path to $Source, as $Path->$Target",'','')){ Move-Target2Source4SoftLink -Target $Path -Source $Target -BackupDir $BackupDir $link = New-Item -ItemType SymbolicLink -Path $Path -Target $Target Write-Log ($link | Select-Object LinkType, FullName, Target) } } function Set-FileSymbolicLinkWithSync{ <# .DESCRIPTION Set a file symbolic link from the path to the target. Then, get a result as $path\rightarrow target$, which means the path is a symbolic link to the target. .PARAMETER Path The path to be set. .PARAMETER Target The target path. .PARAMETER BackupDir The backup directory path. .OUTPUTS None. #> [CmdletBinding(SupportsShouldProcess)] param( [Parameter(Mandatory)] [string]$Path, [Parameter(Mandatory)] [string]$Target, [Parameter(Mandatory)] [string]$BackupDir ) Assert-IsWindowsAndAdmin if ($PSCmdlet.ShouldProcess("Set a file symbolic link from $Path to $Source, as $Path->$Target",'','')){ Move-Target2Source4SoftLink -Target $Path -Source $Target -BackupDir $BackupDir $link = New-Item -ItemType SymbolicLink -Path $Path -Target $Target Write-Log ($link | Select-Object LinkType, FullName, Target) } } function Set-DirJunctionWithSync{ <# .DESCRIPTION Set a junction point from the path to the target. Then, get a result as $path\rightarrow target$, which means the path is a junction point to the target. .PARAMETER Path The path to be set. .PARAMETER Target The target path. .PARAMETER BackupDir The backup directory path. .OUTPUTS None. #> [CmdletBinding(SupportsShouldProcess)] param( [Parameter(Mandatory)] [string]$Path, [Parameter(Mandatory)] [string]$Target, [Parameter(Mandatory)] [string]$BackupDir ) Assert-IsWindowsAndAdmin if ($PSCmdlet.ShouldProcess("Set a junction point from $Path to $Source, as $Path->$Target",'','')){ Move-Target2Source4SoftLink -Target $Path -Source $Target -BackupDir $BackupDir $link = New-Item -ItemType Junction -Path $Path -Target $Target Write-Log ($link | Select-Object LinkType, FullName, Target) } } |