Update App Update Scripts/App - .NET 8 - Update.ps1

This commit is contained in:
2025-08-05 14:48:01 +00:00
parent cfc3f17238
commit 7c9f71a675
+127 -128
View File
@@ -1,129 +1,128 @@
<# <#
Author: Gabe Kerntke Author: Gabe Kerntke
Company: UFS LLC Date: 07-14-2025
Date: 07-14-2025
.Synopsis
.Synopsis Script to update .NET 8
Script to update .NET 8
.Modified
.Modified 2025-07-14 (GabeK) - Original script created
2025-07-14 (GabeK) - Original script created
.PARAMETER VersionPattern
.PARAMETER VersionPattern Regex pattern to grab all h3 headers on the $URL page
Regex pattern to grab all h3 headers on the $URL page
.PARAMETER downloadLinkPattern
.PARAMETER downloadLinkPattern Regex pattern as a wildcard
Regex pattern as a wildcard #>
#>
[CmdletBinding()]
[CmdletBinding()] Param(
Param( [Parameter(Mandatory = $false)]
[Parameter(Mandatory = $false)] $File_Name_Extension = "exe",
$File_Name_Extension = "exe", [Parameter(Mandatory = $false)]
[Parameter(Mandatory = $false)] $Install_Parameters = "/s",
$Install_Parameters = "/s", [Parameter(Mandatory = $false)]
[Parameter(Mandatory = $false)] $URL = "https://dotnet.microsoft.com/en-us/download/dotnet/8.0",
$URL = "https://dotnet.microsoft.com/en-us/download/dotnet/8.0", [Parameter(Mandatory = $false)]
[Parameter(Mandatory = $false)] $htmlContent = (Invoke-WebRequest -UseBasicParsing $URL).Content,
$htmlContent = (Invoke-WebRequest -UseBasicParsing $URL).Content, [Parameter(Mandatory = $false)]
[Parameter(Mandatory = $false)] $VersionPattern = '<h3[^>]*?>(.*?)</h3>',
$VersionPattern = '<h3[^>]*?>(.*?)</h3>', [Parameter(Mandatory = $false)]
[Parameter(Mandatory = $false)] $downloadLinkPattern = 'href="(/en-us/download/dotnet/thank-you/[^"]+?(\d+\.\d+\.\d+)([^"]+?))"'
$downloadLinkPattern = 'href="(/en-us/download/dotnet/thank-you/[^"]+?(\d+\.\d+\.\d+)([^"]+?))"' )
)
#Region Functions
#Region Functions Function Get-Online_Version {
Function Get-Online_Version { $FilterContent = [regex]::Matches($htmlContent, $VersionPattern, 'Singleline') | Select-Object -ExpandProperty Value | Select-Object -First 15
$FilterContent = [regex]::Matches($htmlContent, $VersionPattern, 'Singleline') | Select-Object -ExpandProperty Value | Select-Object -First 15 $SortContent = $FilterContent -replace '<[^>]+>' -replace '.NET'
$SortContent = $FilterContent -replace '<[^>]+>' -replace '.NET' $AppVersions = $SortContent | Where-Object { $_ -like "*$Version_Name*" } | Select-Object -First 1
$AppVersions = $SortContent | Where-Object { $_ -like "*$Version_Name*" } | Select-Object -First 1 $Online_Version = $AppVersions -replace "[^\d*\.?\d*$/]" , ''
$Online_Version = $AppVersions -replace "[^\d*\.?\d*$/]" , '' Return $Online_Version
Return $Online_Version }
}
Function Get-Download_URL {
Function Get-Download_URL { $regex = [regex]::new($downloadLinkPattern) # Create a Regex object
$regex = [regex]::new($downloadLinkPattern) # Create a Regex object $match = $regex.Matches($htmlContent) | Select-Object -ExpandProperty Value | Where-Object { $_ -like "*Windows*" -and $_ -like "*x64*" -and $_ -like "*installer*" } | Select-Object -First 15
$match = $regex.Matches($htmlContent) | Select-Object -ExpandProperty Value | Where-Object { $_ -like "*Windows*" -and $_ -like "*x64*" -and $_ -like "*installer*" } | Select-Object -First 15 $sort = $match -replace 'href="/' , "" -replace '"' , "" | Where-Object { $_ -like "*$Download_Name*" } | Select-Object -First 1
$sort = $match -replace 'href="/' , "" -replace '"' , "" | Where-Object { $_ -like "*$Download_Name*" } | Select-Object -First 1 $DownloadURL = (Invoke-WebRequest -UseBasicParsing "https://dotnet.microsoft.com/$sort").Links.href -like "*.exe" | Select-Object -First 1
$DownloadURL = (Invoke-WebRequest -UseBasicParsing "https://dotnet.microsoft.com/$sort").Links.href -like "*.exe" | Select-Object -First 1 Return $DownloadURL
Return $DownloadURL }
}
Function Update-App {
Function Update-App { #Get currently installed version
#Get currently installed version $B = Get-Software | Where-Object { $_.DisplayName -like "*$App_Name*" } | Select-Object -ExpandProperty DisplayName | Select-Object -First 1
$B = Get-Software | Where-Object { $_.DisplayName -like "*$App_Name*" } | Select-Object -ExpandProperty DisplayName | Select-Object -First 1 $Local_Version = $B -replace "(x64)" , '' -replace ".NET", '' -replace "[^\d*\.?\d*$/]" , ''
$Local_Version = $B -replace "(x64)" , '' -replace ".NET", '' -replace "[^\d*\.?\d*$/]" , '' Invoke-WebRequest -UseBasicParsing "https://scripts.gabesville.com/Gabesville/Powershell-Scripts/raw/branch/main/Functions%20Scripts/Functions.ps1" -outfile "C:\Temp\Script Cache\Functions.ps1"
Invoke-WebRequest -UseBasicParsing "https://scripts.gabesville.com/Gabesville/Powershell-Scripts/raw/branch/main/Functions%20Scripts/Functions.ps1" -outfile "C:\Temp\Script Cache\Functions.ps1" . "C:\Temp\Script Cache\Functions.ps1"
. "C:\Temp\Script Cache\Functions.ps1"
#Comparing version already installed to what is online
#Comparing version already installed to what is online If ([version]$Local_Version -lt [version]$Online_Version) {
If ([version]$Local_Version -lt [version]$Online_Version) { Test-Probe_Online
Test-Probe_Online Install-App
Install-App }
} Else { Write-Host "$App_Name already on latest version (Installed version: $Local_Version)" }
Else { Write-Host "$App_Name already on latest version (Installed version: $Local_Version)" } }
}
Function Install-ASP_NET_CORE {
Function Install-ASP_NET_CORE { $App_Name = "ASP.NET Core"
$App_Name = "ASP.NET Core" $Version_Name = "ASP Core Runtime"
$Version_Name = "ASP Core Runtime" $Download_Name = "aspnetcore"
$Download_Name = "aspnetcore" $EPCache_Folder = "3rd Party Patches\$App_Name"
$EPCache_Folder = "3rd Party Patches\$App_Name" $Online_Version = Get-Online_Version
$Online_Version = Get-Online_Version $File_Name = "$App_Name-$Online_Version.$File_Name_Extension"
$File_Name = "$App_Name-$Online_Version.$File_Name_Extension" $DownloadURL = Get-Download_URL
$DownloadURL = Get-Download_URL Update-App
Update-App }
}
Function Install-Desktop_Runtime {
Function Install-Desktop_Runtime { $App_Name = "Desktop Runtime"
$App_Name = "Desktop Runtime" $Version_Name = "Desktop Runtime"
$Version_Name = "Desktop Runtime" $Download_Name = "desktop"
$Download_Name = "desktop" $EPCache_Folder = "3rd Party Patches\$App_Name"
$EPCache_Folder = "3rd Party Patches\$App_Name" $Online_Version = Get-Online_Version
$Online_Version = Get-Online_Version $File_Name = "$App_Name-$Online_Version.$File_Name_Extension"
$File_Name = "$App_Name-$Online_Version.$File_Name_Extension" $DownloadURL = Get-Download_URL
$DownloadURL = Get-Download_URL Update-App
Update-App }
}
Function Install-Net_Runtime {
Function Install-Net_Runtime { $App_Name = ".NET Runtime"
$App_Name = ".NET Runtime" $Version_Name = "Runtime [0-9]"
$Version_Name = "Runtime [0-9]" $Download_Name = "runtime-[0-9]"
$Download_Name = "runtime-[0-9]" $EPCache_Folder = "3rd Party Patches\$App_Name"
$EPCache_Folder = "3rd Party Patches\$App_Name" $Online_Version = Get-Online_Version
$Online_Version = Get-Online_Version $File_Name = "$App_Name-$Online_Version.$File_Name_Extension"
$File_Name = "$App_Name-$Online_Version.$File_Name_Extension" $DownloadURL = Get-Download_URL
$DownloadURL = Get-Download_URL Update-App
Update-App }
}
Function Install-Net_SDK {
Function Install-Net_SDK { $App_Name = ".NET SDK"
$App_Name = ".NET SDK" $Version_Name = "SDK"
$Version_Name = "SDK" $Download_Name = "sdk"
$Download_Name = "sdk" $EPCache_Folder = "3rd Party Patches\$App_Name"
$EPCache_Folder = "3rd Party Patches\$App_Name" $Online_Version = Get-Online_Version
$Online_Version = Get-Online_Version $File_Name = "$App_Name-$Online_Version.$File_Name_Extension"
$File_Name = "$App_Name-$Online_Version.$File_Name_Extension" $DownloadURL = Get-Download_URL
$DownloadURL = Get-Download_URL Update-App
Update-App }
}
#Region Script Start
#Region Script Start If ((Test-Path "C:\Temp\Script Cache") -eq $False) { New-Item -ItemType directory -Path "C:\Temp\Script Cache" }
If ((Test-Path "C:\Temp\Script Cache") -eq $False) { New-Item -ItemType directory -Path "C:\Temp\Script Cache" } Invoke-WebRequest -UseBasicParsing "https://scripts.gabesville.com/Gabesville/Powershell-Scripts/raw/branch/main/Functions%20Scripts/Functions.ps1" -outfile "C:\Temp\Script Cache\Functions.ps1"
Invoke-WebRequest -UseBasicParsing "https://scripts.gabesville.com/Gabesville/Powershell-Scripts/raw/branch/main/Functions%20Scripts/Functions.ps1" -outfile "C:\Temp\Script Cache\Functions.ps1" . "C:\Temp\Script Cache\Functions.ps1"
. "C:\Temp\Script Cache\Functions.ps1"
#Check to see if program is installed
#Check to see if program is installed $Applist = Get-Software | Sort-Object -Descending
$Applist = Get-Software | Sort-Object -Descending
If ($Applist.DisplayName -like "*Windows Desktop Runtime*" -or $Applist.DisplayName -like "*.NET Runtime*" -or $Applist.DisplayName -like "*ASP.NET Core*" -or $Applist.DisplayName -like "*.NET SDK*") {
If ($Applist.DisplayName -like "*Windows Desktop Runtime*" -or $Applist.DisplayName -like "*.NET Runtime*" -or $Applist.DisplayName -like "*ASP.NET Core*" -or $Applist.DisplayName -like "*.NET SDK*") { If ($Applist.DisplayName -like "*ASP.NET Core*") { Install-ASP_NET_CORE }
If ($Applist.DisplayName -like "*ASP.NET Core*") { Install-ASP_NET_CORE }
If ($Applist.DisplayName -like "*Windows Desktop Runtime*") { Install-Desktop_Runtime }
If ($Applist.DisplayName -like "*Windows Desktop Runtime*") { Install-Desktop_Runtime }
If ($Applist.DisplayName -like "*.NET Runtime*") { Install-Net_Runtime }
If ($Applist.DisplayName -like "*.NET Runtime*") { Install-Net_Runtime }
If ($Applist.DisplayName -like "*.NET SDK*") { Install-Net_SDK }
If ($Applist.DisplayName -like "*.NET SDK*") { Install-Net_SDK } }
} Else { Write-Host "No .NET apps installed." }
Else { Write-Host "No .NET apps installed." }
#Region Script End #Region Script End