2023-09-15 14:33:51 +00:00
|
|
|
# Function to check Block/Allow List External Path
|
2022-09-17 19:22:41 +00:00
|
|
|
|
2023-09-15 14:38:54 +00:00
|
|
|
function Test-ListPath
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
# URL, UNC or Local Path
|
|
|
|
[CmdletBinding()]
|
|
|
|
param
|
|
|
|
(
|
2023-09-15 14:38:54 +00:00
|
|
|
[string]
|
|
|
|
$ListPath,
|
|
|
|
[string]
|
|
|
|
$UseWhiteList,
|
|
|
|
[string]
|
|
|
|
$WingetUpdatePath
|
2023-09-15 14:33:51 +00:00
|
|
|
)
|
|
|
|
|
2023-09-15 14:38:54 +00:00
|
|
|
if ($UseWhiteList)
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
$ListType = 'included_apps.txt'
|
|
|
|
}
|
2023-09-15 14:38:54 +00:00
|
|
|
else
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
$ListType = 'excluded_apps.txt'
|
|
|
|
}
|
2023-09-15 14:38:54 +00:00
|
|
|
|
2023-09-15 14:33:51 +00:00
|
|
|
# Get local and external list paths
|
|
|
|
$LocalList = -join ($WingetUpdatePath, '\', $ListType)
|
|
|
|
$ExternalList = -join ($ListPath, '\', $ListType)
|
2023-09-15 14:38:54 +00:00
|
|
|
|
2023-09-15 14:33:51 +00:00
|
|
|
# Check if a list exists
|
2023-09-15 14:38:54 +00:00
|
|
|
if (Test-Path -Path $LocalList -ErrorAction SilentlyContinue)
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
$dateLocal = (Get-Item -Path $LocalList).LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss')
|
|
|
|
}
|
2023-09-15 14:38:54 +00:00
|
|
|
|
2023-09-15 14:33:51 +00:00
|
|
|
# If path is URL
|
2023-09-15 14:38:54 +00:00
|
|
|
if ($ListPath -like 'http*')
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
$ExternalList = -join ($ListPath, '/', $ListType)
|
|
|
|
$wc = (New-Object -TypeName System.Net.WebClient)
|
2023-09-15 14:38:54 +00:00
|
|
|
|
|
|
|
try
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
$null = $wc.OpenRead($ExternalList).Close()
|
|
|
|
$dateExternal = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString('yyyy-MM-dd HH:mm:ss')
|
2023-09-15 14:38:54 +00:00
|
|
|
|
|
|
|
if ($dateExternal -gt $dateLocal)
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
2023-09-15 14:38:54 +00:00
|
|
|
try
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
$wc.DownloadFile($ExternalList, $LocalList)
|
2022-09-19 21:10:00 +00:00
|
|
|
}
|
2023-09-15 14:38:54 +00:00
|
|
|
catch
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
$Script:ReachNoPath = $True
|
|
|
|
return $False
|
2023-03-25 05:00:07 +00:00
|
|
|
}
|
2023-09-15 14:33:51 +00:00
|
|
|
return $True
|
|
|
|
}
|
|
|
|
}
|
2023-09-15 14:38:54 +00:00
|
|
|
catch
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
2023-09-15 14:38:54 +00:00
|
|
|
try
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
$content = $wc.DownloadString(('{0}' -f $ExternalList))
|
2023-09-15 14:38:54 +00:00
|
|
|
|
|
|
|
if ($null -ne $content -and $content -match '\w\.\w')
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
$wc.DownloadFile($ExternalList, $LocalList)
|
|
|
|
return $True
|
2023-03-25 05:00:07 +00:00
|
|
|
}
|
2023-09-15 14:38:54 +00:00
|
|
|
else
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
$Script:ReachNoPath = $True
|
|
|
|
return $False
|
2023-01-08 17:57:47 +00:00
|
|
|
}
|
2023-09-15 14:33:51 +00:00
|
|
|
}
|
2023-09-15 14:38:54 +00:00
|
|
|
catch
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
$Script:ReachNoPath = $True
|
|
|
|
return $False
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-09-15 14:38:54 +00:00
|
|
|
else
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
# If path is UNC or local
|
2023-09-15 14:38:54 +00:00
|
|
|
if (Test-Path -Path $ExternalList)
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
2023-09-15 14:38:54 +00:00
|
|
|
try
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
$dateExternal = (Get-Item -Path ('{0}' -f $ExternalList)).LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss')
|
|
|
|
}
|
2023-09-15 14:38:54 +00:00
|
|
|
catch
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
$Script:ReachNoPath = $True
|
|
|
|
return $False
|
|
|
|
}
|
2023-09-15 14:38:54 +00:00
|
|
|
|
|
|
|
if ($dateExternal -gt $dateLocal)
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
2023-09-15 14:38:54 +00:00
|
|
|
try
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
Copy-Item -Path $ExternalList -Destination $LocalList -Force
|
2023-01-08 17:57:47 +00:00
|
|
|
}
|
2023-09-15 14:38:54 +00:00
|
|
|
catch
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
$Script:ReachNoPath = $True
|
|
|
|
return $False
|
2022-09-18 18:25:14 +00:00
|
|
|
}
|
2023-09-15 14:33:51 +00:00
|
|
|
return $True
|
|
|
|
}
|
|
|
|
}
|
2023-09-15 14:38:54 +00:00
|
|
|
else
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
$Script:ReachNoPath = $True
|
|
|
|
}
|
2023-09-15 14:38:54 +00:00
|
|
|
|
2023-09-15 14:33:51 +00:00
|
|
|
return $False
|
|
|
|
}
|
2022-09-18 18:25:14 +00:00
|
|
|
}
|