36 lines
920 B
PowerShell
36 lines
920 B
PowerShell
|
function Test-IsSymlinkValid {
|
||
|
<#
|
||
|
.SYNOPSIS
|
||
|
Used to test if an existing Symbolic Link path is linked to a filepath that is still on disk.
|
||
|
|
||
|
.PARAMETER Path
|
||
|
Path to test
|
||
|
#>
|
||
|
[CmdletBinding()]
|
||
|
[OutputType([System.Boolean])]
|
||
|
param(
|
||
|
[Parameter(Mandatory = $true)]
|
||
|
[string]$Path
|
||
|
)
|
||
|
|
||
|
$loglead = (Get-LogLeadName)
|
||
|
|
||
|
if(Test-Path -Path $Path) {
|
||
|
$pathItem = Get-Item -Path $Path
|
||
|
} else {
|
||
|
Write-Warning "$loglead : Path is not found. Returning False."
|
||
|
return $false
|
||
|
}
|
||
|
|
||
|
$isPathSymlink = ($pathItem.LinkType -eq "SymbolicLink")
|
||
|
|
||
|
# Test if it's even a Symbolic Link.
|
||
|
if(!($isPathSymlink)) {
|
||
|
Write-Warning "$loglead : Path is not a SymbolicLink type. Returning False."
|
||
|
return $false
|
||
|
}
|
||
|
|
||
|
# Check to see if the Target of the Symlink is real and on disk.
|
||
|
$isValid = (Test-Path -Path $pathItem.Target)
|
||
|
return $isValid
|
||
|
}
|