auto format

pull/681/head
Romain 2024-09-02 16:10:21 +02:00
parent 0f15be36f3
commit 941ea6f2dc
17 changed files with 49 additions and 67 deletions

View File

@ -17,4 +17,4 @@
'PSUseShouldProcessForStateChangingFunctions', 'PSUseShouldProcessForStateChangingFunctions',
'PSUseDeclaredVarsMoreThanAssignments' 'PSUseDeclaredVarsMoreThanAssignments'
) )
} }

View File

@ -98,4 +98,4 @@ if ($WAUConfig.WAU_RunGPOManagement -eq 1) {
$WAUConfig.PSObject.Properties | Where-Object { $_.Name -like "WAU_*" } | Select-Object Name, Value | Out-File -Encoding default -FilePath $GPOLogFile -Append $WAUConfig.PSObject.Properties | Where-Object { $_.Name -like "WAU_*" } | Select-Object Name, Value | Out-File -Encoding default -FilePath $GPOLogFile -Append
} }
Exit 0 Exit 0

View File

@ -29,4 +29,4 @@ function Add-ScopeMachine {
} }
$ConfigFile | ConvertTo-Json -Depth 100 | Out-File $SettingsPath -Encoding utf8 -Force $ConfigFile | ConvertTo-Json -Depth 100 | Out-File $SettingsPath -Encoding utf8 -Force
} }

View File

@ -21,4 +21,4 @@ Function Confirm-Installation ($AppName, $AppVer) {
else { else {
return $false return $false
} }
} }

View File

@ -47,4 +47,4 @@ Function Get-AZCopy ($WingetUpdatePath) {
$AZCopyCurrentVersion = $AZCopyVersionRegex.Match($AZCopyCurrentVersion).Value $AZCopyCurrentVersion = $AZCopyVersionRegex.Match($AZCopyCurrentVersion).Value
Write-ToLog "AZCopy version $AZCopyCurrentVersion installed" Write-ToLog "AZCopy version $AZCopyCurrentVersion installed"
} }
} }

View File

@ -38,4 +38,4 @@ function Get-WAUAvailableVersion {
#Return version #Return version
return $WAUAvailableVersion return $WAUAvailableVersion
} }

View File

@ -23,4 +23,4 @@ Function Get-WAUConfig {
#Return config #Return config
return $WAUConfig return $WAUConfig
} }

View File

@ -20,4 +20,4 @@ Function Get-WingetCmd {
return $WingetCmd return $WingetCmd
} }

View File

@ -96,4 +96,4 @@ function Install-Prerequisites {
} }
} }

View File

@ -46,4 +46,4 @@ function Invoke-DirProtect ($ModsPath) {
catch { catch {
return $false return $false
} }
} }

View File

@ -32,7 +32,7 @@ function Test-ListPath ($ListPath, $UseWhiteList, $WingetUpdatePath) {
# Assign the second string (after "?" to the end) to the variable $sasToken # Assign the second string (after "?" to the end) to the variable $sasToken
$sasToken = $splitPath[1] $sasToken = $splitPath[1]
# Join the parts and add "/$ListType?" in between the parts # Join the parts and add "/$ListType?" in between the parts
$ExternalList = -join ($resourceURI, "/$ListType`?", $sasToken) $ExternalList = -join ($resourceURI, "/$ListType`?", $sasToken)
} }

View File

@ -13,16 +13,18 @@ function Test-Network {
$ncsiHost = Get-ItemPropertyValue -Path $NlaRegKey -Name ActiveWebProbeHost $ncsiHost = Get-ItemPropertyValue -Path $NlaRegKey -Name ActiveWebProbeHost
$ncsiPath = Get-ItemPropertyValue -Path $NlaRegKey -Name ActiveWebProbePath $ncsiPath = Get-ItemPropertyValue -Path $NlaRegKey -Name ActiveWebProbePath
$ncsiContent = Get-ItemPropertyValue -Path $NlaRegKey -Name ActiveWebProbeContent $ncsiContent = Get-ItemPropertyValue -Path $NlaRegKey -Name ActiveWebProbeContent
} catch { }
catch {
$ncsiHost = "www.msftconnecttest.com" $ncsiHost = "www.msftconnecttest.com"
$ncsiPath = "connecttest.txt" $ncsiPath = "connecttest.txt"
$ncsiContent = "Microsoft Connect Test" $ncsiContent = "Microsoft Connect Test"
} }
While ($timeout -lt 1800) { While ($timeout -lt 1800) {
try { try {
$ncsiResponse = Invoke-WebRequest -Uri "http://$($ncsiHost)/$($ncsiPath)" -UseBasicParsing -UserAgent ([Microsoft.PowerShell.Commands.PSUserAgent]::Chrome) $ncsiResponse = Invoke-WebRequest -Uri "http://$($ncsiHost)/$($ncsiPath)" -UseBasicParsing -UserAgent ([Microsoft.PowerShell.Commands.PSUserAgent]::Chrome)
} catch { }
catch {
$ncsiResponse = $false $ncsiResponse = $false
} }

View File

@ -130,4 +130,4 @@ Function Update-App ($app) {
} }
} }

View File

@ -26,7 +26,7 @@ function Write-ToLog {
#If header requested #If header requested
if ($IsHeader) { if ($IsHeader) {
$Log = "#"*65 + "`n#`t$(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern) - $LogMsg`n" + "#"*65 $Log = "#" * 65 + "`n#`t$(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern) - $LogMsg`n" + "#" * 65
} }
else { else {
$Log = "$(Get-Date -UFormat "%T") - $LogMsg" $Log = "$(Get-Date -UFormat "%T") - $LogMsg"

View File

@ -93,7 +93,7 @@ if ($Proc) {
Stop-ModsProc $Proc Stop-ModsProc $Proc
} }
if ($Svc) { if ($Svc) {
Stop-ModsSvc $Svc Stop-ModsSvc $Svc
} }
if ($Wait) { if ($Wait) {
Wait-ModsProc $Wait Wait-ModsProc $Wait
@ -135,4 +135,4 @@ if ($RunUser) {
Invoke-ModsApp $RunUser "" "" $User Invoke-ModsApp $RunUser "" "" $User
} }
<# EXTRAS #> <# EXTRAS #>

View File

@ -26,10 +26,10 @@ function Stop-ModsProc ($Proc) {
Return Return
} }
function Stop-ModsSvc ($Svc) { function Stop-ModsSvc ($Svc) {
foreach ($service in $Svc) { foreach ($service in $Svc) {
Stop-Service -Name $service -Force -ErrorAction SilentlyContinue | Out-Null Stop-Service -Name $service -Force -ErrorAction SilentlyContinue | Out-Null
} }
Return Return
} }
function Wait-ModsProc ($Wait) { function Wait-ModsProc ($Wait) {
@ -53,93 +53,74 @@ function Uninstall-WingetID ($WingetIDUninst) {
Return Return
} }
function Uninstall-ModsApp ($AppUninst, $AllVersions) function Uninstall-ModsApp ($AppUninst, $AllVersions) {
{ foreach ($app in $AppUninst) {
foreach ($app in $AppUninst)
{
# we start from scanning the x64 node in registry, if something was found, then we set x64=TRUE # we start from scanning the x64 node in registry, if something was found, then we set x64=TRUE
[bool]$app_was_x64 = Process-installedSoftware -app $app -x64 $true; [bool]$app_was_x64 = Process-installedSoftware -app $app -x64 $true;
# if nothing was found in x64 node, then we repeat that action in x86 node # if nothing was found in x64 node, then we repeat that action in x86 node
if (!$app_was_x64) if (!$app_was_x64) {
{
Process-installedSoftware -app $app | Out-Null; Process-installedSoftware -app $app | Out-Null;
} }
} }
Return Return
} }
Function Process-installedSoftware() Function Process-installedSoftware() {
{
[OutputType([Bool])] [OutputType([Bool])]
Param( Param(
[parameter(Mandatory=$true)] [string]$app, [parameter(Mandatory = $true)] [string]$app,
[parameter(Mandatory=$false)][bool] $x64 = $false [parameter(Mandatory = $false)][bool] $x64 = $false
) )
if($true -eq $x64) if ($true -eq $x64) {
{
[string]$path = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"; [string]$path = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall";
} }
else else {
{
[string]$path = "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"; [string]$path = "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
} }
[bool]$app_was_found = $false; [bool]$app_was_found = $false;
[Microsoft.Win32.RegistryKey[]]$InstalledSoftware = Get-ChildItem $path; [Microsoft.Win32.RegistryKey[]]$InstalledSoftware = Get-ChildItem $path;
foreach ($obj in $InstalledSoftware) foreach ($obj in $InstalledSoftware) {
{ if ($obj.GetValue('DisplayName') -like $App) {
if ($obj.GetValue('DisplayName') -like $App)
{
$UninstallString = $obj.GetValue('UninstallString') $UninstallString = $obj.GetValue('UninstallString')
$CleanedUninstallString = $UninstallString.Trim([char]0x0022) $CleanedUninstallString = $UninstallString.Trim([char]0x0022)
if ($UninstallString -like "MsiExec.exe*") if ($UninstallString -like "MsiExec.exe*") {
{
$ProductCode = Select-String "{.*}" -inputobject $UninstallString $ProductCode = Select-String "{.*}" -inputobject $UninstallString
$ProductCode = $ProductCode.matches.groups[0].value $ProductCode = $ProductCode.matches.groups[0].value
#MSI x64 Installer #MSI x64 Installer
$Exec = Start-Process "C:\Windows\System32\msiexec.exe" -ArgumentList "/x$ProductCode REBOOT=R /qn" -PassThru -Wait $Exec = Start-Process "C:\Windows\System32\msiexec.exe" -ArgumentList "/x$ProductCode REBOOT=R /qn" -PassThru -Wait
#Stop Hard Reboot (if bad MSI!) #Stop Hard Reboot (if bad MSI!)
if ($Exec.ExitCode -eq 1641) if ($Exec.ExitCode -eq 1641) {
{
Start-Process "C:\Windows\System32\shutdown.exe" -ArgumentList "/a" Start-Process "C:\Windows\System32\shutdown.exe" -ArgumentList "/a"
} }
} }
else else {
{
$QuietUninstallString = $obj.GetValue('QuietUninstallString') $QuietUninstallString = $obj.GetValue('QuietUninstallString')
if ($QuietUninstallString) if ($QuietUninstallString) {
{
$QuietUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $QuietUninstallString $QuietUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $QuietUninstallString
$Command = $QuietUninstallString.matches.groups[1].value $Command = $QuietUninstallString.matches.groups[1].value
$Parameter = $QuietUninstallString.matches.groups[2].value $Parameter = $QuietUninstallString.matches.groups[2].value
#All EXE x64 Installers (already defined silent uninstall) #All EXE x64 Installers (already defined silent uninstall)
Start-Process $Command -ArgumentList $Parameter -Wait Start-Process $Command -ArgumentList $Parameter -Wait
} }
else else {
{ if ((Test-Path $CleanedUninstallString)) {
if ((Test-Path $CleanedUninstallString))
{
$NullSoft = Select-String -Path $CleanedUninstallString -Pattern "Nullsoft" $NullSoft = Select-String -Path $CleanedUninstallString -Pattern "Nullsoft"
} }
if ($NullSoft) if ($NullSoft) {
{
#NSIS x64 Installer #NSIS x64 Installer
Start-Process $UninstallString -ArgumentList "/S" -Wait Start-Process $UninstallString -ArgumentList "/S" -Wait
} }
else else {
{ if ((Test-Path $CleanedUninstallString)) {
if ((Test-Path $CleanedUninstallString))
{
$Inno = Select-String -Path $CleanedUninstallString -Pattern "Inno Setup" $Inno = Select-String -Path $CleanedUninstallString -Pattern "Inno Setup"
} }
if ($Inno) if ($Inno) {
{
#Inno x64 Installer #Inno x64 Installer
Start-Process $UninstallString -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-" -Wait Start-Process $UninstallString -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-" -Wait
} }
else else {
{
Write-Host "$(if($true -eq $x64) {'x64'} else {'x86'}) Uninstaller unknown, trying the UninstallString from registry..." Write-Host "$(if($true -eq $x64) {'x64'} else {'x86'}) Uninstaller unknown, trying the UninstallString from registry..."
$NativeUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $UninstallString $NativeUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $UninstallString
$Command = $NativeUninstallString.matches.groups[1].value $Command = $NativeUninstallString.matches.groups[1].value
@ -151,8 +132,7 @@ Function Process-installedSoftware()
} }
} }
$app_was_found = $true $app_was_found = $true
if (!$AllVersions) if (!$AllVersions) {
{
break break
} }
} }

View File

@ -16,11 +16,11 @@ This all-purpose mod will be overridden by any specific:
<# MAIN #> <# MAIN #>
if ($($app.Id) -eq "Microsoft.SQLServerManagementStudio") { if ($($app.Id) -eq "Microsoft.SQLServerManagementStudio") {
if ($ConfirmInstall -eq $false) { if ($ConfirmInstall -eq $false) {
try { try {
Write-ToLog "...succesfully done something" "Green" Write-ToLog "...succesfully done something" "Green"
} }
catch { catch {
Write-ToLog "...failed to do something" "Red" Write-ToLog "...failed to do something" "Red"
} }
} }
} }