Small optical code improvements

pull/311/head
Fabian Seitz 2023-03-31 17:56:07 +02:00
parent 31f2314812
commit c23f3d6883
32 changed files with 167 additions and 177 deletions

View File

@ -4,7 +4,7 @@ Configure Winget to daily update installed apps.
.DESCRIPTION .DESCRIPTION
Install powershell scripts and scheduled task to daily run Winget upgrade and notify connected users. Install powershell scripts and scheduled task to daily run Winget upgrade and notify connected users.
Possible to exclude apps from auto-update Posibility to exclude apps from auto-update
https://github.com/Romanitho/Winget-AutoUpdate https://github.com/Romanitho/Winget-AutoUpdate
.PARAMETER Silent .PARAMETER Silent

View File

@ -1,6 +1,6 @@
<# <#
.SYNOPSIS .SYNOPSIS
Handle user interaction from shortcuts and show a Toast Handle user interaction from shortcuts and show a Toast notification
.DESCRIPTION .DESCRIPTION
Act on shortcut run (DEFAULT: Check for updated Apps) Act on shortcut run (DEFAULT: Check for updated Apps)

View File

@ -3,7 +3,7 @@
Uninstall Winget-AutoUpdate Uninstall Winget-AutoUpdate
.DESCRIPTION .DESCRIPTION
Uninstall Winget-AutoUpdate (DEFAULT: clean old install) Uninstalls Winget-AutoUpdate (DEFAULT: clean old install)
https://github.com/Romanitho/Winget-AutoUpdate https://github.com/Romanitho/Winget-AutoUpdate
.PARAMETER NoClean .PARAMETER NoClean

View File

@ -1,4 +1,4 @@
#Send Notif Script #Send Notify Script
#get xml notif config #get xml notif config
$WAUinstalledPath = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\" -Name InstallLocation $WAUinstalledPath = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\" -Name InstallLocation

View File

@ -1,6 +1,6 @@
<# LOAD FUNCTIONS #> <# LOAD FUNCTIONS #>
#Get Working Dir #Get the Working Dir
$Script:WorkingDir = $PSScriptRoot $Script:WorkingDir = $PSScriptRoot
#Get Functions #Get Functions
Get-ChildItem "$WorkingDir\functions" | ForEach-Object { . $_.FullName } Get-ChildItem "$WorkingDir\functions" | ForEach-Object { . $_.FullName }
@ -289,12 +289,10 @@ if (Test-Network) {
if ($IsSystem) { if ($IsSystem) {
#User check routine from: https://stackoverflow.com/questions/23219718/powershell-script-to-see-currently-logged-in-users-domain-and-machine-status #User check routine from: https://stackoverflow.com/questions/23219718/powershell-script-to-see-currently-logged-in-users-domain-and-machine-status
$explorerprocesses = @(Get-WmiObject -Query "Select * FROM Win32_Process WHERE Name='explorer.exe'" -ErrorAction SilentlyContinue) $explorerprocesses = @(Get-WmiObject -Query "Select * FROM Win32_Process WHERE Name='explorer.exe'" -ErrorAction SilentlyContinue)
If ($explorerprocesses.Count -eq 0) If ($explorerprocesses.Count -eq 0) {
{
Write-Log "No explorer process found / Nobody interactively logged on..." Write-Log "No explorer process found / Nobody interactively logged on..."
} }
Else Else {
{
#Run WAU in user context if the user task exist #Run WAU in user context if the user task exist
$UserScheduledTask = Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue $UserScheduledTask = Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue
if ($UserScheduledTask) { if ($UserScheduledTask) {

View File

@ -1,4 +1,4 @@
#Function to configure prefered scope option as Machine #Function to configure the prefered scope option as Machine
function Add-ScopeMachine ($SettingsPath) { function Add-ScopeMachine ($SettingsPath) {
if (Test-Path $SettingsPath) { if (Test-Path $SettingsPath) {

View File

@ -1,4 +1,4 @@
#Function for creating shortcuts #Function to create shortcuts
function Add-Shortcut ($Target, $Shortcut, $Arguments, $Icon, $Description) { function Add-Shortcut ($Target, $Shortcut, $Arguments, $Icon, $Description) {
$WScriptShell = New-Object -ComObject WScript.Shell $WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($Shortcut) $Shortcut = $WScriptShell.CreateShortcut($Shortcut)

View File

@ -1,4 +1,4 @@
#Function to get AZCopy if it doesn't exist and update it if it does #Function to get AZCopy, if it doesn't exist and update it, if it does
Function Get-AZCopy ($WingetUpdatePath) { Function Get-AZCopy ($WingetUpdatePath) {

View File

@ -1,4 +1,4 @@
#Get App Info #Get the winget App Information
Function Get-AppInfo ($AppID) { Function Get-AppInfo ($AppID) {
#Get AppID Info #Get AppID Info

View File

@ -1,4 +1,4 @@
#Function to get Black List apps #Function to get the Block List apps
function Get-ExcludedApps { function Get-ExcludedApps {

View File

@ -1,4 +1,4 @@
#Function to get White List apps #Function to get the allow List apps
function Get-IncludedApps { function Get-IncludedApps {

View File

@ -1,4 +1,4 @@
#Function to get locale file for Notification. #Function to get the locale file for notifications
Function Get-NotifLocale { Function Get-NotifLocale {

View File

@ -1,4 +1,4 @@
#Function to get Domain/Local Policies (GPO) #Function to get the Domain/Local Policies (GPO)
Function Get-Policies { Function Get-Policies {
#Get WAU Policies and set the Configurations Registry Accordingly #Get WAU Policies and set the Configurations Registry Accordingly

View File

@ -1,4 +1,4 @@
#Function to get latest WAU available version on Github #Function to get the latest WAU available version on Github
function Get-WAUAvailableVersion { function Get-WAUAvailableVersion {

View File

@ -1,4 +1,4 @@
#Function to get Winget Command regarding execution context (User, System...) #Function to get the winget command regarding execution context (User, System...)
Function Get-WingetCmd { Function Get-WingetCmd {

View File

@ -1,4 +1,4 @@
#Function to get outdated app list, in formatted array #Function to get the outdated app list, in formatted array
function Get-WingetOutdatedApps { function Get-WingetOutdatedApps {
class Software { class Software {

View File

@ -1,6 +1,6 @@
function Get-WingetSystemApps { function Get-WingetSystemApps {
#Json File where to export system installed apps #Json File, where to export system installed apps
$jsonFile = "$WorkingDir\winget_system_apps.txt" $jsonFile = "$WorkingDir\winget_system_apps.txt"
#Get list of installed Winget apps to json file #Get list of installed Winget apps to json file

View File

@ -1,4 +1,4 @@
#Function rotate the logs #Function to rotate the logs
function Invoke-LogRotation ($LogFile, $MaxLogFiles, $MaxLogSize) { function Invoke-LogRotation ($LogFile, $MaxLogFiles, $MaxLogSize) {
<# <#

View File

@ -1,4 +1,4 @@
#Function to check if Mods Directory is secured. #Function to check if the mods directory is secured.
#Security: Mods directory must be protected (Users could create scripts of their own - then they'll run in System Context)! #Security: Mods directory must be protected (Users could create scripts of their own - then they'll run in System Context)!
#Check if Local Users have write rights in Mods directory or not (and take action if necessary): #Check if Local Users have write rights in Mods directory or not (and take action if necessary):

View File

@ -1,4 +1,4 @@
#Function to make actions post WAU update #Function to make actions after WAU update
function Invoke-PostUpdateActions { function Invoke-PostUpdateActions {

View File

@ -1,4 +1,4 @@
#Function to send notifications to user #Function to send the notifications to user
function Start-NotifTask { function Start-NotifTask {

View File

@ -1,4 +1,4 @@
#Function to check Black/White List External Path #Function to check Block/Allow List External Path
function Test-ListPath ($ListPath, $UseWhiteList, $WingetUpdatePath) { function Test-ListPath ($ListPath, $UseWhiteList, $WingetUpdatePath) {
# URL, UNC or Local Path # URL, UNC or Local Path

View File

@ -1,4 +1,4 @@
#Function to check if modification exists in 'mods' directory #Function to check if modification exists within 'mods' directory
function Test-Mods ($app) { function Test-Mods ($app) {

View File

@ -1,4 +1,4 @@
#Function to check Mods External Path #Function to check mods External Path
function Test-ModsPath ($ModsPath, $WingetUpdatePath, $AzureBlobSASURL) { function Test-ModsPath ($ModsPath, $WingetUpdatePath, $AzureBlobSASURL) {
# URL, UNC or Local Path # URL, UNC or Local Path

View File

@ -1,4 +1,4 @@
#Function to check connectivity #Function to check the connectivity
function Test-Network { function Test-Network {

View File

@ -1,4 +1,4 @@
#Function to check if there's a Pending Reboot #Function to check if there is a Pending Reboot
function Test-PendingReboot { function Test-PendingReboot {

View File

@ -1,4 +1,4 @@
#Function to Update an App #Function to update an App
Function Update-App ($app) { Function Update-App ($app) {

View File

@ -1,4 +1,4 @@
#Function to Update WAU #Function to update WAU
function Update-WAU { function Update-WAU {

View File

@ -1,4 +1,4 @@
#Write Log Function #Write to Log Function
function Write-Log ($LogMsg, $LogColor = "White") { function Write-Log ($LogMsg, $LogColor = "White") {

View File

@ -1,6 +1,6 @@
<# ARRAYS/VARIABLES #> <# ARRAYS/VARIABLES #>
#App to Run (as SYSTEM) #App to Run (as SYSTEM)
#$RunWait = $False if it shouldn't be waited for completion. Example: #$RunWait = $False if it shouldn't be waited for completion. For example:
#$RunSystem = "$PSScriptRoot\bins\MsiZap.exe" #$RunSystem = "$PSScriptRoot\bins\MsiZap.exe"
#$RunSwitch = "tw! {GUID}" #$RunSwitch = "tw! {GUID}"
$RunSystem = "" $RunSystem = ""

View File

@ -1,4 +1,4 @@
#Common shared functions for mods handling #Common shared functions to handle the mods
function Invoke-ModsApp ($Run, $RunSwitch, $RunWait, $User) { function Invoke-ModsApp ($Run, $RunSwitch, $RunWait, $User) {
if (Test-Path "$Run") { if (Test-Path "$Run") {
@ -20,40 +20,35 @@ function Invoke-ModsApp ($Run, $RunSwitch, $RunWait, $User) {
function Stop-ModsProc ($Proc) { function Stop-ModsProc ($Proc) {
foreach ($process in $Proc) foreach ($process in $Proc) {
{
Stop-Process -Name $process -Force -ErrorAction SilentlyContinue | Out-Null Stop-Process -Name $process -Force -ErrorAction SilentlyContinue | Out-Null
} }
Return Return
} }
function Wait-ModsProc ($Wait) { function Wait-ModsProc ($Wait) {
foreach ($process in $Wait) foreach ($process in $Wait) {
{
Get-Process $process -ErrorAction SilentlyContinue | Foreach-Object { $_.WaitForExit() } Get-Process $process -ErrorAction SilentlyContinue | Foreach-Object { $_.WaitForExit() }
} }
Return Return
} }
function Install-WingetID ($WingetIDInst) { function Install-WingetID ($WingetIDInst) {
foreach ($app in $WingetIDInst) foreach ($app in $WingetIDInst) {
{
& $Winget install --id $app --accept-package-agreements --accept-source-agreements -h & $Winget install --id $app --accept-package-agreements --accept-source-agreements -h
} }
Return Return
} }
function Uninstall-WingetID ($WingetIDUninst) { function Uninstall-WingetID ($WingetIDUninst) {
foreach ($app in $WingetIDUninst) foreach ($app in $WingetIDUninst) {
{
& $Winget uninstall --id $app -e --accept-source-agreements -h & $Winget uninstall --id $app -e --accept-source-agreements -h
} }
Return Return
} }
function Uninstall-ModsApp ($AppUninst) { function Uninstall-ModsApp ($AppUninst) {
foreach ($app in $AppUninst) foreach ($app in $AppUninst) {
{
$InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall" $InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
foreach ($obj in $InstalledSoftware) { foreach ($obj in $InstalledSoftware) {
if ($obj.GetValue('DisplayName') -like $App) { if ($obj.GetValue('DisplayName') -like $App) {
@ -169,8 +164,7 @@ function Uninstall-ModsApp ($AppUninst) {
Return Return
} }
function Remove-ModsLnk ($Lnk) { function Remove-ModsLnk ($Lnk) {
foreach ($link in $Lnk) foreach ($link in $Lnk) {
{
Remove-Item -Path "${env:Public}\Desktop\$link.lnk" -Force -ErrorAction SilentlyContinue | Out-Null Remove-Item -Path "${env:Public}\Desktop\$link.lnk" -Force -ErrorAction SilentlyContinue | Out-Null
} }
Return Return
@ -203,8 +197,7 @@ function Remove-ModsReg ($DelKey, $DelValue) {
} }
function Remove-ModsFile ($DelFile) { function Remove-ModsFile ($DelFile) {
foreach ($file in $DelFile) foreach ($file in $DelFile) {
{
if (Test-Path "$file") { if (Test-Path "$file") {
Remove-Item -Path $file -Force -Recurse -ErrorAction SilentlyContinue | Out-Null Remove-Item -Path $file -Force -Recurse -ErrorAction SilentlyContinue | Out-Null
} }
@ -234,8 +227,7 @@ function Edit-ModsFile ($File, $FindText, $ReplaceText) {
} }
function Grant-ModsPath ($GrantPath) { function Grant-ModsPath ($GrantPath) {
foreach ($path in $GrantPath) foreach ($path in $GrantPath) {
{
if (Test-Path "$path") { if (Test-Path "$path") {
$NewAcl = Get-Acl -Path $path $NewAcl = Get-Acl -Path $path
$identity = New-Object System.Security.Principal.SecurityIdentifier S-1-5-11 $identity = New-Object System.Security.Principal.SecurityIdentifier S-1-5-11