2022-09-19 23:02:51 +00:00
|
|
|
#Function to check Black/White List External Path
|
2022-09-17 19:22:41 +00:00
|
|
|
|
|
|
|
function Test-ListPath ($ListPath, $UseWhiteList) {
|
2022-09-19 19:12:00 +00:00
|
|
|
# UNC, Web or Local Path
|
2022-09-18 18:25:14 +00:00
|
|
|
if ($UseWhiteList){
|
|
|
|
$ListType="included"
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$ListType="excluded"
|
|
|
|
}
|
2022-09-19 19:12:00 +00:00
|
|
|
$LocalList = -join($WingetUpdatePath, "\", $ListType, "_apps.txt")
|
2022-09-19 22:54:23 +00:00
|
|
|
if (Test-Path "$LocalList") {
|
|
|
|
$dateLocal = (Get-Item "$LocalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
|
}
|
2022-09-19 23:32:23 +00:00
|
|
|
$ExternalList = -join($ListPath, "\", $ListType, "_apps.txt")
|
2022-09-19 19:12:00 +00:00
|
|
|
$PathInfo=[System.Uri]$ListPath
|
2022-09-18 18:40:22 +00:00
|
|
|
|
2022-09-18 18:25:14 +00:00
|
|
|
if($PathInfo.IsUnc){
|
|
|
|
$PathType="UNC Path"
|
2022-09-19 19:12:00 +00:00
|
|
|
if(Test-Path -Path $ExternalList -PathType leaf){
|
2022-09-19 22:54:23 +00:00
|
|
|
Write-Host "Given path $ListPath type is $PathType and $ExternalList is available..."
|
|
|
|
$dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
|
2022-09-19 19:12:00 +00:00
|
|
|
if ($dateExternal -gt $dateLocal) {
|
2022-09-19 21:10:00 +00:00
|
|
|
Write-Host("$ExternalList is newer than $LocalList")
|
2022-09-19 22:54:23 +00:00
|
|
|
return $true
|
2022-09-18 18:25:14 +00:00
|
|
|
}
|
2022-09-19 19:12:00 +00:00
|
|
|
}
|
2022-09-18 18:25:14 +00:00
|
|
|
else {
|
2022-09-19 22:54:23 +00:00
|
|
|
Write-Host "Given path $ListPath type is $PathType and $ExternalList is not available..."
|
2022-09-18 18:25:14 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-18 18:40:22 +00:00
|
|
|
elseif ($ListPath -like "http*"){
|
|
|
|
$PathType="Web Path"
|
2022-09-19 19:12:00 +00:00
|
|
|
$ExternalList = -join($ListPath, "/", $ListType, "_apps.txt")
|
2022-09-18 18:25:14 +00:00
|
|
|
$wc = New-Object System.Net.WebClient
|
|
|
|
try {
|
2022-09-19 21:10:00 +00:00
|
|
|
$wc.OpenRead("$ExternalList").Close() | Out-Null
|
2022-09-19 22:54:23 +00:00
|
|
|
Write-Host "Given path $ListPath type is $PathType and $ExternalList is available..."
|
2022-09-19 21:45:18 +00:00
|
|
|
$dateExternal = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString("yyyy-MM-dd HH:mm:ss")
|
2022-09-19 21:10:00 +00:00
|
|
|
if ($dateExternal -gt $dateLocal) {
|
|
|
|
Write-Host("$ExternalList is newer than $LocalList")
|
2022-09-19 22:54:23 +00:00
|
|
|
return $true
|
2022-09-19 21:10:00 +00:00
|
|
|
}
|
2022-09-19 19:12:00 +00:00
|
|
|
}
|
|
|
|
catch {
|
2022-09-19 22:54:23 +00:00
|
|
|
Write-Host "Given path $ListPath type is $PathType and $ExternalList is not available..."
|
2022-09-18 18:25:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$PathType="Local Path"
|
2022-09-19 19:12:00 +00:00
|
|
|
if(Test-Path -Path $ExternalList -PathType leaf){
|
2022-09-19 22:54:23 +00:00
|
|
|
Write-Host "Given path $ListPath type is $PathType and $ExternalList is available..."
|
|
|
|
$dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
|
2022-09-19 19:12:00 +00:00
|
|
|
if ($dateExternal -gt $dateLocal) {
|
2022-09-19 21:10:00 +00:00
|
|
|
Write-Host("$ExternalList is newer than $LocalList")
|
2022-09-19 22:54:23 +00:00
|
|
|
return $true
|
2022-09-18 18:25:14 +00:00
|
|
|
}
|
2022-09-19 19:12:00 +00:00
|
|
|
}
|
2022-09-18 18:25:14 +00:00
|
|
|
else {
|
2022-09-19 22:54:23 +00:00
|
|
|
Write-Host "Given path $ListPath type is $PathType and $ExternalList is not available..."
|
2022-09-18 18:25:14 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-19 23:02:51 +00:00
|
|
|
return $false
|
2022-09-18 18:25:14 +00:00
|
|
|
}
|
2022-09-17 19:22:41 +00:00
|
|
|
|
2022-09-19 19:12:00 +00:00
|
|
|
$WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate"
|
2022-09-19 21:10:00 +00:00
|
|
|
$ListPath = "https://www.knifmelti.se"
|
2022-09-19 22:54:23 +00:00
|
|
|
#$ListPath = "D:\Temp"
|
2022-09-19 23:02:51 +00:00
|
|
|
#$ListPath = "\\TempSERVER"
|
2022-09-19 21:10:00 +00:00
|
|
|
#$UseWhiteList = $true
|
2022-09-19 23:32:23 +00:00
|
|
|
|
2022-09-19 19:12:00 +00:00
|
|
|
#White List or Black List in share/online if differs
|
|
|
|
if ($WingetUpdatePath -ne $ListPath){
|
2022-09-19 22:54:23 +00:00
|
|
|
$NoClean = Test-ListPath $ListPath $UseWhiteList
|
2022-09-19 19:12:00 +00:00
|
|
|
}
|
2022-09-19 22:54:23 +00:00
|
|
|
|
|
|
|
Write-Host $NoClean
|