Merge pull request #2 from Romanitho/dev
Renaming few things to match Winget-AutoUpdatepull/3/head v1.3.2
|
@ -11,7 +11,7 @@ https://github.com/Romanitho/Winget-AutoUpdate
|
||||||
Install Winget-AutoUpdate and prerequisites silently
|
Install Winget-AutoUpdate and prerequisites silently
|
||||||
|
|
||||||
.PARAMETER WingetUpdatePath
|
.PARAMETER WingetUpdatePath
|
||||||
Specify Winget-AutoUpdate installation localtion. Default: C:\ProgramData\winget-update\
|
Specify Winget-AutoUpdate installation localtion. Default: C:\ProgramData\Winget-AutoUpdate\
|
||||||
|
|
||||||
.PARAMETER DoNotUpdate
|
.PARAMETER DoNotUpdate
|
||||||
Do not run Winget-autoupdate after installation. By default, Winget-AutoUpdate is run just after installation.
|
Do not run Winget-autoupdate after installation. By default, Winget-AutoUpdate is run just after installation.
|
||||||
|
@ -23,7 +23,7 @@ Do not run Winget-autoupdate after installation. By default, Winget-AutoUpdate i
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$False)] [Alias('S')] [Switch] $Silent = $false,
|
[Parameter(Mandatory=$False)] [Alias('S')] [Switch] $Silent = $false,
|
||||||
[Parameter(Mandatory=$False)] [Alias('Path')] [String] $WingetUpdatePath = "$env:ProgramData\winget-update",
|
[Parameter(Mandatory=$False)] [Alias('Path')] [String] $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate",
|
||||||
[Parameter(Mandatory=$False)] [Switch] $DoNotUpdate = $false
|
[Parameter(Mandatory=$False)] [Switch] $DoNotUpdate = $false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -78,11 +78,19 @@ function Check-Prerequisites{
|
||||||
|
|
||||||
function Install-WingetAutoUpdate{
|
function Install-WingetAutoUpdate{
|
||||||
try{
|
try{
|
||||||
|
#Check if previous version location exists and delete
|
||||||
|
$OldWingetUpdatePath = $WingetUpdatePath.Replace("\Winget-AutoUpdate","\winget-update")
|
||||||
|
if (Test-Path ($OldWingetUpdatePath)){
|
||||||
|
Remove-Item $OldWingetUpdatePath -Force -Recurse
|
||||||
|
}
|
||||||
|
Get-ScheduledTask -TaskName "Winget Update" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
|
||||||
|
Get-ScheduledTask -TaskName "Winget Update Notify" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
|
||||||
|
|
||||||
#Copy files to location
|
#Copy files to location
|
||||||
if (!(Test-Path $WingetUpdatePath)){
|
if (!(Test-Path $WingetUpdatePath)){
|
||||||
New-Item -ItemType Directory -Force -Path $WingetUpdatePath
|
New-Item -ItemType Directory -Force -Path $WingetUpdatePath
|
||||||
}
|
}
|
||||||
Copy-Item -Path "$PSScriptRoot\winget-update\*" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
|
Copy-Item -Path "$PSScriptRoot\Winget-AutoUpdate\*" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
Copy-Item -Path "$PSScriptRoot\excluded_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
|
Copy-Item -Path "$PSScriptRoot\excluded_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
# Set dummy regkeys for notification name and icon
|
# Set dummy regkeys for notification name and icon
|
||||||
|
@ -98,7 +106,7 @@ function Install-WingetAutoUpdate{
|
||||||
|
|
||||||
# Set up the task, and register it
|
# Set up the task, and register it
|
||||||
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings -Trigger $taskTrigger2,$taskTrigger1
|
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings -Trigger $taskTrigger2,$taskTrigger1
|
||||||
Register-ScheduledTask -TaskName 'Winget Update' -InputObject $task -Force
|
Register-ScheduledTask -TaskName 'Winget-AutoUpdate' -InputObject $task -Force
|
||||||
|
|
||||||
# Settings for the scheduled task for Notifications
|
# Settings for the scheduled task for Notifications
|
||||||
$taskAction = New-ScheduledTaskAction –Execute "wscript.exe" -Argument "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\winget-notify.ps1`"`""
|
$taskAction = New-ScheduledTaskAction –Execute "wscript.exe" -Argument "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\winget-notify.ps1`"`""
|
||||||
|
@ -107,7 +115,7 @@ function Install-WingetAutoUpdate{
|
||||||
|
|
||||||
# Set up the task, and register it
|
# Set up the task, and register it
|
||||||
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings
|
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings
|
||||||
Register-ScheduledTask -TaskName 'Winget Update Notify' -InputObject $task -Force
|
Register-ScheduledTask -TaskName 'Winget-AutoUpdate-Notify' -InputObject $task -Force
|
||||||
|
|
||||||
Write-host "`nInstallation succeeded!" -ForegroundColor Green
|
Write-host "`nInstallation succeeded!" -ForegroundColor Green
|
||||||
Start-sleep 1
|
Start-sleep 1
|
||||||
|
@ -138,7 +146,7 @@ function Start-WingetAutoUpdate{
|
||||||
if ($RunWinget -eq "y"){
|
if ($RunWinget -eq "y"){
|
||||||
try{
|
try{
|
||||||
Write-host "Running Winget-AutoUpdate..." -ForegroundColor Yellow
|
Write-host "Running Winget-AutoUpdate..." -ForegroundColor Yellow
|
||||||
Get-ScheduledTask -TaskName "Winget Update" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
|
Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
catch{
|
catch{
|
||||||
Write-host "Failed to run Winget-AutoUpdate..." -ForegroundColor Red
|
Write-host "Failed to run Winget-AutoUpdate..." -ForegroundColor Red
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
|
@ -1,34 +1,34 @@
|
||||||
<local>
|
<local>
|
||||||
<outputs>
|
<outputs>
|
||||||
<output id="0">
|
<output id="0">
|
||||||
<!--Check network connection-->
|
<!--Check network connection-->
|
||||||
<title>Vérifiez votre connexion réseau</title>
|
<title>Vérifiez votre connexion réseau</title>
|
||||||
<!--Unable to check for software updates at this time!-->
|
<!--Unable to check for software updates at this time!-->
|
||||||
<message>Impossible de vérifier les mises à jours logicielles pour le moment !</message>
|
<message>Impossible de vérifier les mises à jours logicielles pour le moment !</message>
|
||||||
</output>
|
</output>
|
||||||
<output id="1">
|
<output id="1">
|
||||||
<!--No internet connction-->
|
<!--No internet connction-->
|
||||||
<title>Aucune connexion réseau</title>
|
<title>Aucune connexion réseau</title>
|
||||||
<!--Updates could not be verified-->
|
<!--Updates could not be verified-->
|
||||||
<message>Les mises à jour logicielles n'ont pas pu être vérifiées !</message>
|
<message>Les mises à jour logicielles n'ont pas pu être vérifiées !</message>
|
||||||
</output>
|
</output>
|
||||||
<output id="2">
|
<output id="2">
|
||||||
<!--{App} will be updated-->
|
<!--{App} will be updated-->
|
||||||
<title>{0} va être mis à jour !</title>
|
<title>{0} va être mis à jour !</title>
|
||||||
<!--{v1.0} to {v2.0}-->
|
<!--{v1.0} to {v2.0}-->
|
||||||
<message>{0} vers {1}</message>
|
<message>{0} vers {1}</message>
|
||||||
</output>
|
</output>
|
||||||
<output id="3">
|
<output id="3">
|
||||||
<!--{App} updated-->
|
<!--{App} updated-->
|
||||||
<title>{0} a été mis à jour.</title>
|
<title>{0} a été mis à jour.</title>
|
||||||
<!--Installed version: {v1.0}-->
|
<!--Installed version: {v1.0}-->
|
||||||
<message>Version installée : {0}</message>
|
<message>Version installée : {0}</message>
|
||||||
</output>
|
</output>
|
||||||
<output id="4">
|
<output id="4">
|
||||||
<!--{App} could not be updated-->
|
<!--{App} could not be updated-->
|
||||||
<title>{0} n'a pas pu être mis à jour !</title>
|
<title>{0} n'a pas pu être mis à jour !</title>
|
||||||
<!--Please contact support-->
|
<!--Please contact support-->
|
||||||
<message>Contacter le support.</message>
|
<message>Contacter le support.</message>
|
||||||
</output>
|
</output>
|
||||||
</outputs>
|
</outputs>
|
||||||
</local>
|
</local>
|
|
@ -1,21 +1,21 @@
|
||||||
#Send Notif Script
|
#Send Notif Script
|
||||||
|
|
||||||
#get xml notif config
|
#get xml notif config
|
||||||
[xml]$NotifConf = Get-Content "$env:ProgramData\winget-update\notif.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
|
[xml]$NotifConf = Get-Content "$env:ProgramData\Winget-AutoUpdate\notif.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
|
||||||
if (!($NotifConf)) {break}
|
if (!($NotifConf)) {break}
|
||||||
|
|
||||||
#Load Assemblies
|
#Load Assemblies
|
||||||
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
|
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
|
||||||
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
|
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
|
||||||
|
|
||||||
#Prepare XML
|
#Prepare XML
|
||||||
$ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::New()
|
$ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::New()
|
||||||
$ToastXml.LoadXml($NotifConf.OuterXml)
|
$ToastXml.LoadXml($NotifConf.OuterXml)
|
||||||
|
|
||||||
#Specify Launcher App ID
|
#Specify Launcher App ID
|
||||||
$LauncherID = "Windows.SystemToast.Winget.Notification"
|
$LauncherID = "Windows.SystemToast.Winget.Notification"
|
||||||
|
|
||||||
#Prepare and Create Toast
|
#Prepare and Create Toast
|
||||||
$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML)
|
$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML)
|
||||||
$ToastMessage.Tag = $NotifConf.toast.tag
|
$ToastMessage.Tag = $NotifConf.toast.tag
|
||||||
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($LauncherID).Show($ToastMessage)
|
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($LauncherID).Show($ToastMessage)
|
|
@ -1,304 +1,304 @@
|
||||||
<# FUNCTIONS #>
|
<# FUNCTIONS #>
|
||||||
|
|
||||||
function Init {
|
function Init {
|
||||||
#Var
|
#Var
|
||||||
$Script:WorkingDir = $PSScriptRoot
|
$Script:WorkingDir = $PSScriptRoot
|
||||||
|
|
||||||
#Logs initialisation
|
#Logs initialisation
|
||||||
$LogPath = "$WorkingDir\logs"
|
$LogPath = "$WorkingDir\logs"
|
||||||
if (!(Test-Path $LogPath)){
|
if (!(Test-Path $LogPath)){
|
||||||
New-Item -ItemType Directory -Force -Path $LogPath
|
New-Item -ItemType Directory -Force -Path $LogPath
|
||||||
}
|
}
|
||||||
|
|
||||||
#Log file
|
#Log file
|
||||||
$Script:LogFile = "$LogPath\updates.log"
|
$Script:LogFile = "$LogPath\updates.log"
|
||||||
|
|
||||||
#Log Header
|
#Log Header
|
||||||
$Log = "##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format 'dd/MM/yyyy')`n##################################################"
|
$Log = "##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format 'dd/MM/yyyy')`n##################################################"
|
||||||
$Log | Write-host
|
$Log | Write-host
|
||||||
$Log | out-file -filepath $LogFile -Append
|
$Log | out-file -filepath $LogFile -Append
|
||||||
|
|
||||||
#Get locale file for Notification
|
#Get locale file for Notification
|
||||||
#Default en-US
|
#Default en-US
|
||||||
$DefaultLocale = "$WorkingDir\locale\en-US.xml"
|
$DefaultLocale = "$WorkingDir\locale\en-US.xml"
|
||||||
#Get OS locale
|
#Get OS locale
|
||||||
$Locale = Get-WinSystemLocale
|
$Locale = Get-WinSystemLocale
|
||||||
#Test if OS locale config file exists
|
#Test if OS locale config file exists
|
||||||
$LocaleFile = "$WorkingDir\locale\$($locale.Name).xml"
|
$LocaleFile = "$WorkingDir\locale\$($locale.Name).xml"
|
||||||
if(Test-Path $LocaleFile){
|
if(Test-Path $LocaleFile){
|
||||||
[xml]$Script:NotifLocale = Get-Content $LocaleFile -Encoding UTF8 -ErrorAction SilentlyContinue
|
[xml]$Script:NotifLocale = Get-Content $LocaleFile -Encoding UTF8 -ErrorAction SilentlyContinue
|
||||||
$LocaleNotif = "Notification Langugage : $($locale.Name)"
|
$LocaleNotif = "Notification Langugage : $($locale.Name)"
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
[xml]$Script:NotifLocale = Get-Content $DefaultLocale -Encoding UTF8 -ErrorAction SilentlyContinue
|
[xml]$Script:NotifLocale = Get-Content $DefaultLocale -Encoding UTF8 -ErrorAction SilentlyContinue
|
||||||
$LocaleNotif = "Notification Langugage : en-US"
|
$LocaleNotif = "Notification Langugage : en-US"
|
||||||
}
|
}
|
||||||
Write-Log $LocaleNotif "Cyan"
|
Write-Log $LocaleNotif "Cyan"
|
||||||
}
|
}
|
||||||
|
|
||||||
function Write-Log ($LogMsg,$LogColor = "White") {
|
function Write-Log ($LogMsg,$LogColor = "White") {
|
||||||
#Get log
|
#Get log
|
||||||
$Log = "$(Get-Date -UFormat "%T") - $LogMsg"
|
$Log = "$(Get-Date -UFormat "%T") - $LogMsg"
|
||||||
#Echo log
|
#Echo log
|
||||||
$Log | Write-host -ForegroundColor $LogColor
|
$Log | Write-host -ForegroundColor $LogColor
|
||||||
#Write log to file
|
#Write log to file
|
||||||
$Log | out-file -filepath $LogFile -Append
|
$Log | out-file -filepath $LogFile -Append
|
||||||
}
|
}
|
||||||
|
|
||||||
function Start-NotifTask ($Title,$Message,$MessageType,$Balise) {
|
function Start-NotifTask ($Title,$Message,$MessageType,$Balise) {
|
||||||
|
|
||||||
#Add XML variables
|
#Add XML variables
|
||||||
[xml]$ToastTemplate = @"
|
[xml]$ToastTemplate = @"
|
||||||
<toast launch="ms-get-started://redirect?id=apps_action">
|
<toast launch="ms-get-started://redirect?id=apps_action">
|
||||||
<visual>
|
<visual>
|
||||||
<binding template="ToastImageAndText03">
|
<binding template="ToastImageAndText03">
|
||||||
<text id="1">$Title</text>
|
<text id="1">$Title</text>
|
||||||
<text id="2">$Message</text>
|
<text id="2">$Message</text>
|
||||||
<image id="1" src="$WorkingDir\icons\$MessageType.png" />
|
<image id="1" src="$WorkingDir\icons\$MessageType.png" />
|
||||||
</binding>
|
</binding>
|
||||||
</visual>
|
</visual>
|
||||||
<tag>$Balise</tag>
|
<tag>$Balise</tag>
|
||||||
</toast>
|
</toast>
|
||||||
"@
|
"@
|
||||||
|
|
||||||
#Save XML File
|
#Save XML File
|
||||||
$ToastTemplateLocation = "$env:ProgramData\winget-update\"
|
$ToastTemplateLocation = "$env:ProgramData\Winget-AutoUpdate\"
|
||||||
if (!(Test-Path $ToastTemplateLocation)){
|
if (!(Test-Path $ToastTemplateLocation)){
|
||||||
New-Item -ItemType Directory -Force -Path $ToastTemplateLocation
|
New-Item -ItemType Directory -Force -Path $ToastTemplateLocation
|
||||||
}
|
}
|
||||||
$ToastTemplate.Save("$ToastTemplateLocation\notif.xml")
|
$ToastTemplate.Save("$ToastTemplateLocation\notif.xml")
|
||||||
|
|
||||||
#Send Notification to user. First, check if script is run as admin (or system)
|
#Send Notification to user. First, check if script is run as admin (or system)
|
||||||
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
|
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
|
||||||
if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)){
|
if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)){
|
||||||
#Run Notify scheduled task to notify conneted users
|
#Run Notify scheduled task to notify conneted users
|
||||||
Get-ScheduledTask -TaskName "Winget Update Notify" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
|
Get-ScheduledTask -TaskName "Winget Update Notify" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
#else, run as user
|
#else, run as user
|
||||||
else{
|
else{
|
||||||
Start-Process powershell.exe -ArgumentList "-ExecutionPolicy Bypass -File `"$WorkingDir\winget-notify.ps1`"" -NoNewWindow -Wait
|
Start-Process powershell.exe -ArgumentList "-ExecutionPolicy Bypass -File `"$WorkingDir\winget-notify.ps1`"" -NoNewWindow -Wait
|
||||||
}
|
}
|
||||||
|
|
||||||
#Wait for notification to display
|
#Wait for notification to display
|
||||||
Start-Sleep 3
|
Start-Sleep 3
|
||||||
}
|
}
|
||||||
|
|
||||||
function Test-Network {
|
function Test-Network {
|
||||||
#init
|
#init
|
||||||
$timeout = 0
|
$timeout = 0
|
||||||
$ping = $false
|
$ping = $false
|
||||||
|
|
||||||
#test connectivity during 30 min then timeout
|
#test connectivity during 30 min then timeout
|
||||||
Write-Log "Checking internet connection..." "Yellow"
|
Write-Log "Checking internet connection..." "Yellow"
|
||||||
while (!$ping -and $timeout -lt 1800){
|
while (!$ping -and $timeout -lt 1800){
|
||||||
try{
|
try{
|
||||||
Invoke-RestMethod -Uri "https://api.github.com/zen"
|
Invoke-RestMethod -Uri "https://api.github.com/zen"
|
||||||
Write-Log "Connected !" "Green"
|
Write-Log "Connected !" "Green"
|
||||||
$ping = $true
|
$ping = $true
|
||||||
return $ping
|
return $ping
|
||||||
}
|
}
|
||||||
catch{
|
catch{
|
||||||
Start-Sleep 10
|
Start-Sleep 10
|
||||||
$timeout += 10
|
$timeout += 10
|
||||||
Write-Log "Checking internet connection. $($timeout)s." "Yellow"
|
Write-Log "Checking internet connection. $($timeout)s." "Yellow"
|
||||||
#Send Notif if no connection for 5 min
|
#Send Notif if no connection for 5 min
|
||||||
if ($timeout -eq 300){
|
if ($timeout -eq 300){
|
||||||
Write-Log "Notify 'No connection'" "Yellow"
|
Write-Log "Notify 'No connection'" "Yellow"
|
||||||
$Title = $NotifLocale.local.outputs.output[0].title
|
$Title = $NotifLocale.local.outputs.output[0].title
|
||||||
$Message = $NotifLocale.local.outputs.output[0].message
|
$Message = $NotifLocale.local.outputs.output[0].message
|
||||||
$MessageType = "warning"
|
$MessageType = "warning"
|
||||||
$Balise = "connection"
|
$Balise = "connection"
|
||||||
Start-NotifTask $Title $Message $MessageType $Balise
|
Start-NotifTask $Title $Message $MessageType $Balise
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Write-Log "Timeout. No internet connection !" "Red"
|
Write-Log "Timeout. No internet connection !" "Red"
|
||||||
#Send Notif if no connection for 30 min
|
#Send Notif if no connection for 30 min
|
||||||
$Title = $NotifLocale.local.outputs.output[1].title
|
$Title = $NotifLocale.local.outputs.output[1].title
|
||||||
$Message = $NotifLocale.local.outputs.output[1].message
|
$Message = $NotifLocale.local.outputs.output[1].message
|
||||||
$MessageType = "error"
|
$MessageType = "error"
|
||||||
$Balise = "connection"
|
$Balise = "connection"
|
||||||
Start-NotifTask $Title $Message $MessageType $Balise
|
Start-NotifTask $Title $Message $MessageType $Balise
|
||||||
return $ping
|
return $ping
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-WingetOutdated {
|
function Get-WingetOutdated {
|
||||||
class Software {
|
class Software {
|
||||||
[string]$Name
|
[string]$Name
|
||||||
[string]$Id
|
[string]$Id
|
||||||
[string]$Version
|
[string]$Version
|
||||||
[string]$AvailableVersion
|
[string]$AvailableVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
#Get WinGet Location
|
#Get WinGet Location
|
||||||
$WingetCmd = Get-Command winget.exe -ErrorAction SilentlyContinue
|
$WingetCmd = Get-Command winget.exe -ErrorAction SilentlyContinue
|
||||||
if ($WingetCmd){
|
if ($WingetCmd){
|
||||||
$script:upgradecmd = $WingetCmd.Source
|
$script:upgradecmd = $WingetCmd.Source
|
||||||
}
|
}
|
||||||
elseif (Test-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\AppInstallerCLI.exe"){
|
elseif (Test-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\AppInstallerCLI.exe"){
|
||||||
#WinGet < 1.17
|
#WinGet < 1.17
|
||||||
$script:upgradecmd = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\AppInstallerCLI.exe" | Select-Object -ExpandProperty Path
|
$script:upgradecmd = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\AppInstallerCLI.exe" | Select-Object -ExpandProperty Path
|
||||||
}
|
}
|
||||||
elseif (Test-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe"){
|
elseif (Test-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe"){
|
||||||
#WinGet > 1.17
|
#WinGet > 1.17
|
||||||
$script:upgradecmd = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe" | Select-Object -ExpandProperty Path
|
$script:upgradecmd = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe" | Select-Object -ExpandProperty Path
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
Write-Log "Winget not installed !"
|
Write-Log "Winget not installed !"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
#Run winget to list apps and accept source agrements (necessary on first run)
|
#Run winget to list apps and accept source agrements (necessary on first run)
|
||||||
& $upgradecmd list --accept-source-agreements | Out-Null
|
& $upgradecmd list --accept-source-agreements | Out-Null
|
||||||
|
|
||||||
#Get list of available upgrades on winget format
|
#Get list of available upgrades on winget format
|
||||||
$upgradeResult = & $upgradecmd upgrade | Out-String
|
$upgradeResult = & $upgradecmd upgrade | Out-String
|
||||||
|
|
||||||
#Start Convertion of winget format to an array. Check if "-----" exists
|
#Start Convertion of winget format to an array. Check if "-----" exists
|
||||||
if (!($upgradeResult -match "-----")){
|
if (!($upgradeResult -match "-----")){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
#Split winget output to lines
|
#Split winget output to lines
|
||||||
$lines = $upgradeResult.Split([Environment]::NewLine).Replace("¦ ","")
|
$lines = $upgradeResult.Split([Environment]::NewLine).Replace("¦ ","")
|
||||||
|
|
||||||
# Find the line that starts with "------"
|
# Find the line that starts with "------"
|
||||||
$fl = 0
|
$fl = 0
|
||||||
while (-not $lines[$fl].StartsWith("-----")){
|
while (-not $lines[$fl].StartsWith("-----")){
|
||||||
$fl++
|
$fl++
|
||||||
}
|
}
|
||||||
|
|
||||||
#Get header line
|
#Get header line
|
||||||
$fl = $fl - 2
|
$fl = $fl - 2
|
||||||
|
|
||||||
#Get header titles
|
#Get header titles
|
||||||
$index = $lines[$fl] -split '\s+'
|
$index = $lines[$fl] -split '\s+'
|
||||||
|
|
||||||
# Line $i has the header, we can find char where we find ID and Version
|
# Line $i has the header, we can find char where we find ID and Version
|
||||||
$idStart = $lines[$fl].IndexOf($index[1])
|
$idStart = $lines[$fl].IndexOf($index[1])
|
||||||
$versionStart = $lines[$fl].IndexOf($index[2])
|
$versionStart = $lines[$fl].IndexOf($index[2])
|
||||||
$availableStart = $lines[$fl].IndexOf($index[3])
|
$availableStart = $lines[$fl].IndexOf($index[3])
|
||||||
$sourceStart = $lines[$fl].IndexOf($index[4])
|
$sourceStart = $lines[$fl].IndexOf($index[4])
|
||||||
|
|
||||||
# Now cycle in real package and split accordingly
|
# Now cycle in real package and split accordingly
|
||||||
$upgradeList = @()
|
$upgradeList = @()
|
||||||
For ($i = $fl + 2; $i -le $lines.Length; $i++){
|
For ($i = $fl + 2; $i -le $lines.Length; $i++){
|
||||||
$line = $lines[$i]
|
$line = $lines[$i]
|
||||||
if ($line.Length -gt ($sourceStart+5) -and -not $line.StartsWith('-')){
|
if ($line.Length -gt ($sourceStart+5) -and -not $line.StartsWith('-')){
|
||||||
$software = [Software]::new()
|
$software = [Software]::new()
|
||||||
$software.Name = $line.Substring(0, $idStart).TrimEnd()
|
$software.Name = $line.Substring(0, $idStart).TrimEnd()
|
||||||
$software.Id = $line.Substring($idStart, $versionStart - $idStart).TrimEnd()
|
$software.Id = $line.Substring($idStart, $versionStart - $idStart).TrimEnd()
|
||||||
$software.Version = $line.Substring($versionStart, $availableStart - $versionStart).TrimEnd()
|
$software.Version = $line.Substring($versionStart, $availableStart - $versionStart).TrimEnd()
|
||||||
$software.AvailableVersion = $line.Substring($availableStart, $sourceStart - $availableStart).TrimEnd()
|
$software.AvailableVersion = $line.Substring($availableStart, $sourceStart - $availableStart).TrimEnd()
|
||||||
#check if Avalaible Version is > than Current Version (block "unknow" versions loop)
|
#check if Avalaible Version is > than Current Version (block "unknow" versions loop)
|
||||||
if ([version]$software.AvailableVersion -gt [version]$software.Version){
|
if ([version]$software.AvailableVersion -gt [version]$software.Version){
|
||||||
$upgradeList += $software
|
$upgradeList += $software
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $upgradeList
|
return $upgradeList
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-ExcludedApps{
|
function Get-ExcludedApps{
|
||||||
if (Test-Path "$WorkingDir\excluded_apps.txt"){
|
if (Test-Path "$WorkingDir\excluded_apps.txt"){
|
||||||
return Get-Content -Path "$WorkingDir\excluded_apps.txt"
|
return Get-Content -Path "$WorkingDir\excluded_apps.txt"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
<# MAIN #>
|
<# MAIN #>
|
||||||
|
|
||||||
#Run initialisation
|
#Run initialisation
|
||||||
Init
|
Init
|
||||||
|
|
||||||
#Check network connectivity
|
#Check network connectivity
|
||||||
if (Test-Network){
|
if (Test-Network){
|
||||||
|
|
||||||
#Get exclude apps list
|
#Get exclude apps list
|
||||||
$toSkip = Get-ExcludedApps
|
$toSkip = Get-ExcludedApps
|
||||||
|
|
||||||
#Get outdated Winget packages
|
#Get outdated Winget packages
|
||||||
Write-Log "Checking available updates..." "yellow"
|
Write-Log "Checking available updates..." "yellow"
|
||||||
$outdated = Get-WingetOutdated
|
$outdated = Get-WingetOutdated
|
||||||
|
|
||||||
#Log list of app to update
|
#Log list of app to update
|
||||||
foreach ($app in $outdated){
|
foreach ($app in $outdated){
|
||||||
#List available updates
|
#List available updates
|
||||||
$Log = "Available update : $($app.Name). Current version : $($app.Version). Available version : $($app.AvailableVersion)."
|
$Log = "Available update : $($app.Name). Current version : $($app.Version). Available version : $($app.AvailableVersion)."
|
||||||
$Log | Write-host
|
$Log | Write-host
|
||||||
$Log | out-file -filepath $LogFile -Append
|
$Log | out-file -filepath $LogFile -Append
|
||||||
}
|
}
|
||||||
|
|
||||||
#Count good update installs
|
#Count good update installs
|
||||||
$InstallOK = 0
|
$InstallOK = 0
|
||||||
|
|
||||||
#For each app, notify and update
|
#For each app, notify and update
|
||||||
foreach ($app in $outdated){
|
foreach ($app in $outdated){
|
||||||
|
|
||||||
if (-not ($toSkip -contains $app.Id)){
|
if (-not ($toSkip -contains $app.Id)){
|
||||||
|
|
||||||
#Send available update notification
|
#Send available update notification
|
||||||
Write-Log "Updating $($app.Name) from $($app.Version) to $($app.AvailableVersion)..." "Cyan"
|
Write-Log "Updating $($app.Name) from $($app.Version) to $($app.AvailableVersion)..." "Cyan"
|
||||||
$Title = $NotifLocale.local.outputs.output[2].title -f $($app.Name)
|
$Title = $NotifLocale.local.outputs.output[2].title -f $($app.Name)
|
||||||
$Message = $NotifLocale.local.outputs.output[2].message -f $($app.Version), $($app.AvailableVersion)
|
$Message = $NotifLocale.local.outputs.output[2].message -f $($app.Version), $($app.AvailableVersion)
|
||||||
$MessageType = "info"
|
$MessageType = "info"
|
||||||
$Balise = $($app.Name)
|
$Balise = $($app.Name)
|
||||||
Start-NotifTask $Title $Message $MessageType $Balise
|
Start-NotifTask $Title $Message $MessageType $Balise
|
||||||
|
|
||||||
#Winget upgrade
|
#Winget upgrade
|
||||||
Write-Log "------ Winget - $($app.Name) Upgrade Starts ------" "Gray"
|
Write-Log "------ Winget - $($app.Name) Upgrade Starts ------" "Gray"
|
||||||
& $upgradecmd upgrade --id $($app.Id) --all --accept-package-agreements --accept-source-agreements -h
|
& $upgradecmd upgrade --id $($app.Id) --all --accept-package-agreements --accept-source-agreements -h
|
||||||
Write-Log "----- Winget - $($app.Name) Upgrade Finished -----" "Gray"
|
Write-Log "----- Winget - $($app.Name) Upgrade Finished -----" "Gray"
|
||||||
|
|
||||||
#Check installed version
|
#Check installed version
|
||||||
$checkoutdated = Get-WingetOutdated
|
$checkoutdated = Get-WingetOutdated
|
||||||
$FailedToUpgrade = $false
|
$FailedToUpgrade = $false
|
||||||
foreach ($checkapp in $checkoutdated){
|
foreach ($checkapp in $checkoutdated){
|
||||||
if ($($checkapp.Id) -eq $($app.Id)) {
|
if ($($checkapp.Id) -eq $($app.Id)) {
|
||||||
$FailedToUpgrade = $true
|
$FailedToUpgrade = $true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Notify installation
|
#Notify installation
|
||||||
if ($FailedToUpgrade -eq $false){
|
if ($FailedToUpgrade -eq $false){
|
||||||
#Send success updated app notification
|
#Send success updated app notification
|
||||||
Write-Log "$($app.Name) updated to $($app.AvailableVersion) !" "Green"
|
Write-Log "$($app.Name) updated to $($app.AvailableVersion) !" "Green"
|
||||||
|
|
||||||
#Send Notif
|
#Send Notif
|
||||||
$Title = $NotifLocale.local.outputs.output[3].title -f $($app.Name)
|
$Title = $NotifLocale.local.outputs.output[3].title -f $($app.Name)
|
||||||
$Message = $NotifLocale.local.outputs.output[3].message -f $($app.AvailableVersion)
|
$Message = $NotifLocale.local.outputs.output[3].message -f $($app.AvailableVersion)
|
||||||
$MessageType = "success"
|
$MessageType = "success"
|
||||||
$Balise = $($app.Name)
|
$Balise = $($app.Name)
|
||||||
Start-NotifTask $Title $Message $MessageType $Balise
|
Start-NotifTask $Title $Message $MessageType $Balise
|
||||||
|
|
||||||
$InstallOK += 1
|
$InstallOK += 1
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#Send failed updated app notification
|
#Send failed updated app notification
|
||||||
Write-Log "$($app.Name) update failed." "Red"
|
Write-Log "$($app.Name) update failed." "Red"
|
||||||
|
|
||||||
#Send Notif
|
#Send Notif
|
||||||
$Title = $NotifLocale.local.outputs.output[4].title -f $($app.Name)
|
$Title = $NotifLocale.local.outputs.output[4].title -f $($app.Name)
|
||||||
$Message = $NotifLocale.local.outputs.output[4].message
|
$Message = $NotifLocale.local.outputs.output[4].message
|
||||||
$MessageType = "error"
|
$MessageType = "error"
|
||||||
$Balise = $($app.Name)
|
$Balise = $($app.Name)
|
||||||
Start-NotifTask $Title $Message $MessageType $Balise
|
Start-NotifTask $Title $Message $MessageType $Balise
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
Write-Log "$($app.Name) : Skipped upgrade because it is in the excluded app list" "Gray"
|
Write-Log "$($app.Name) : Skipped upgrade because it is in the excluded app list" "Gray"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($InstallOK -gt 0){
|
if ($InstallOK -gt 0){
|
||||||
Write-Log "$InstallOK apps updated ! No more update." "Green"
|
Write-Log "$InstallOK apps updated ! No more update." "Green"
|
||||||
}
|
}
|
||||||
if ($InstallOK -eq 0){
|
if ($InstallOK -eq 0){
|
||||||
Write-Log "No new update." "Green"
|
Write-Log "No new update." "Green"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#End
|
#End
|
||||||
Write-Log "End of process!" "Cyan"
|
Write-Log "End of process!" "Cyan"
|
||||||
Sleep 3
|
Sleep 3
|
|
@ -1,2 +1,2 @@
|
||||||
@echo off
|
@echo off
|
||||||
powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-executionpolicy bypass -file """%~dp0winget-install-and-update.ps1"" -Silent'" -Verb RunAs
|
powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" -Silent'" -Verb RunAs
|
||||||
|
|