wingetautoupdate/Winget-AutoUpdate/functions/Test-ListPath.ps1

55 lines
1.8 KiB
PowerShell
Raw Normal View History

2022-09-17 19:22:41 +00:00
#Function to check Black/White List Path
function Test-ListPath ($ListPath, $UseWhiteList) {
2022-09-18 18:25:14 +00:00
# UNC or Local Path
if ($UseWhiteList){
$ListType="included"
}
else {
$ListType="excluded"
}
$Path = $ListPath
$PathInfo=[System.Uri]$Path
2022-09-18 18:40:22 +00:00
2022-09-18 18:25:14 +00:00
if($PathInfo.IsUnc){
$PathType="UNC Path"
2022-09-18 18:40:22 +00:00
$ListPath = -join($Path, "\", "$ListType", "_apps.txt")
2022-09-18 18:25:14 +00:00
if(Test-Path -Path $ListPath -PathType leaf){
Write-Output "Given path $Path type is $PathType and $ListPath is available..."
}
else {
Write-Output "Given path $Path type is $PathType and $ListPath is not available..."
}
}
2022-09-18 18:40:22 +00:00
elseif ($ListPath -like "http*"){
$PathType="Web Path"
$ListPath = -join($Path, "/", "$ListType", "_apps.txt")
2022-09-18 18:25:14 +00:00
$wc = New-Object System.Net.WebClient
try {
2022-09-18 18:40:22 +00:00
$wc.OpenRead("$ListPath") | Out-Null
Write-Output "Given path $Path type is $PathType and $ListPath is available..."
2022-09-18 18:25:14 +00:00
} catch {
2022-09-18 18:40:22 +00:00
Write-Output "Given path $Path type is $PathType and $ListPath is not available..."
2022-09-18 18:25:14 +00:00
}
}
else {
$PathType="Local Path"
2022-09-18 18:40:22 +00:00
$ListPath = -join($Path, "\", "$ListType", "_apps.txt")
2022-09-18 18:25:14 +00:00
if(Test-Path -Path $ListPath -PathType leaf){
Write-Output "Given path $Path type is $PathType and $ListPath is available..."
}
else {
Write-Output "Given path $Path type is $PathType and $ListPath is not available..."
}
}
2022-09-17 19:22:41 +00:00
2022-09-18 18:25:14 +00:00
}
2022-09-17 19:22:41 +00:00
2022-09-18 18:40:22 +00:00
# $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate"
# $ListPath = "https://www.knifmelti.se"
# $UseWhiteList = $true
# #White List or Black List in share/online if differs
# if ($WingetUpdatePath -ne $ListPath){
# Test-ListPath $ListPath $UseWhiteList
# }