2023-10-03 08:18:00 +00:00
|
|
|
#Function to check Block/Allow List External Path
|
2022-09-17 19:22:41 +00:00
|
|
|
|
2023-10-03 08:18:00 +00:00
|
|
|
function Test-ListPath ($ListPath, $UseWhiteList, $WingetUpdatePath) {
|
|
|
|
# URL, UNC or Local Path
|
|
|
|
if ($UseWhiteList) {
|
|
|
|
$ListType = "included_apps.txt"
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$ListType = "excluded_apps.txt"
|
|
|
|
}
|
2023-09-15 14:40:37 +00:00
|
|
|
|
2023-10-03 08:18:00 +00:00
|
|
|
# Get local and external list paths
|
|
|
|
$LocalList = -join ($WingetUpdatePath, "\", $ListType)
|
|
|
|
$ExternalList = -join ($ListPath, "\", $ListType)
|
2023-09-15 14:40:37 +00:00
|
|
|
|
2023-10-03 08:18:00 +00:00
|
|
|
# Check if a list exists
|
|
|
|
if (Test-Path "$LocalList") {
|
|
|
|
$dateLocal = (Get-Item "$LocalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
|
}
|
2023-09-15 14:40:37 +00:00
|
|
|
|
2023-10-03 08:18:00 +00:00
|
|
|
# If path is URL
|
|
|
|
if ($ListPath -like "http*") {
|
|
|
|
$ExternalList = -join ($ListPath, "/", $ListType)
|
2024-04-11 18:40:35 +00:00
|
|
|
|
|
|
|
# Test if $ListPath contains the character "?" (testing for SAS token)
|
|
|
|
if ($Listpath -match "\?") {
|
|
|
|
# Split the URL into two strings at the "?" substring
|
|
|
|
$splitPath = $ListPath.Split("`?")
|
|
|
|
|
|
|
|
# Assign the first string (up to "?") to the variable $resourceURI
|
|
|
|
$resourceURI = $splitPath[0]
|
|
|
|
|
|
|
|
# Assign the second string (after "?" to the end) to the variable $sasToken
|
|
|
|
$sasToken = $splitPath[1]
|
2024-09-02 14:10:21 +00:00
|
|
|
|
2024-04-11 18:40:35 +00:00
|
|
|
# Join the parts and add "/$ListType?" in between the parts
|
|
|
|
$ExternalList = -join ($resourceURI, "/$ListType`?", $sasToken)
|
|
|
|
}
|
|
|
|
|
2023-10-03 08:18:00 +00:00
|
|
|
$wc = New-Object System.Net.WebClient
|
|
|
|
try {
|
|
|
|
$wc.OpenRead("$ExternalList").Close() | Out-Null
|
|
|
|
$dateExternal = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
|
if ($dateExternal -gt $dateLocal) {
|
|
|
|
try {
|
|
|
|
$wc.DownloadFile($ExternalList, $LocalList)
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
$Script:ReachNoPath = $True
|
|
|
|
return $False
|
|
|
|
}
|
|
|
|
return $true
|
2022-09-19 21:10:00 +00:00
|
|
|
}
|
2023-10-03 08:18:00 +00:00
|
|
|
}
|
|
|
|
catch {
|
|
|
|
try {
|
2024-08-31 19:20:14 +00:00
|
|
|
$wc.DownloadFile($ExternalList, $LocalList)
|
|
|
|
$Script:AlwaysDownloaded = $True
|
|
|
|
return $true
|
2023-03-25 05:00:07 +00:00
|
|
|
}
|
2023-10-03 08:18:00 +00:00
|
|
|
catch {
|
|
|
|
$Script:ReachNoPath = $True
|
|
|
|
return $False
|
2023-03-25 05:00:07 +00:00
|
|
|
}
|
2023-10-03 08:18:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
# If path is UNC or local
|
|
|
|
else {
|
|
|
|
if (Test-Path -Path $ExternalList) {
|
|
|
|
try {
|
|
|
|
$dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
|
2023-01-08 17:57:47 +00:00
|
|
|
}
|
2023-10-03 08:18:00 +00:00
|
|
|
catch {
|
|
|
|
$Script:ReachNoPath = $True
|
|
|
|
return $False
|
2023-01-08 17:57:47 +00:00
|
|
|
}
|
2023-10-03 08:18:00 +00:00
|
|
|
if ($dateExternal -gt $dateLocal) {
|
|
|
|
try {
|
|
|
|
Copy-Item $ExternalList -Destination $LocalList -Force
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
$Script:ReachNoPath = $True
|
|
|
|
return $False
|
|
|
|
}
|
|
|
|
return $True
|
2022-09-18 18:25:14 +00:00
|
|
|
}
|
2023-10-03 08:18:00 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$Script:ReachNoPath = $True
|
2024-08-31 19:20:14 +00:00
|
|
|
return $False
|
2023-10-03 08:18:00 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-18 18:25:14 +00:00
|
|
|
}
|