ps/Modules/Alkami.PowerShell.Common/Public/Test-IsSymlink.ps1

43 lines
1.1 KiB
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
function Test-IsSymlink {
<#
.SYNOPSIS
Test if a given file is a symlink
.PARAMETER Path
[string] The path to test
#>
[CmdletBinding()]
[OutputType([System.Boolean])]
param(
[Parameter(Mandatory = $true)]
[string]$Path
)
$loglead = (Get-LogLeadName)
if ([string]::IsNullOrWhiteSpace($Path)) {
Write-Warning "$logLead : Path supplied was null or empty. Can not be a symlink."
return $false
}
if (@('DirectoryInfo','FileInfo') -contains $Path.GetType().Name) {
$Path = $Path.FullName
}
if (!(Test-Path $Path)) {
return $false
}
$Path = Resolve-Path $Path
$item = (Get-Item $Path)
# If the item is a Junction, SymbolicLink or a ReparsePoint, consider it a Symlink for
# the purposes of this function. (Junction and ReparsePoint are older and not found on modern Windows)
$returnItem = (
($item.Attributes.ToString() -match "ReparsePoint") `
-or $item.IsJunction `
-or $item.IsSymbolicLink `
-or (@('SymbolicLink','Junction') -contains $item.LinkType))
return $returnItem
}