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
@ -111,7 +111,7 @@ param(
[Parameter(Mandatory = $False)] [DateTime] $UpdatesAtTime = ("06am"), [Parameter(Mandatory = $False)] [DateTime] $UpdatesAtTime = ("06am"),
[Parameter(Mandatory = $False)] [Switch] $BypassListForUsers = $false, [Parameter(Mandatory = $False)] [Switch] $BypassListForUsers = $false,
[Parameter(Mandatory = $False)] [Switch] $InstallUserContext = $false, [Parameter(Mandatory = $False)] [Switch] $InstallUserContext = $false,
[Parameter(Mandatory = $False)] [ValidateRange(0,99)] [int32] $MaxLogFiles = 3, [Parameter(Mandatory = $False)] [ValidateRange(0, 99)] [int32] $MaxLogFiles = 3,
[Parameter(Mandatory = $False)] [int64] $MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB [Parameter(Mandatory = $False)] [int64] $MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB
) )

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) {
@ -308,7 +306,7 @@ if (Test-Network) {
Start-ScheduledTask $UserScheduledTask.TaskName -ErrorAction SilentlyContinue Start-ScheduledTask $UserScheduledTask.TaskName -ErrorAction SilentlyContinue
Exit 0 Exit 0
} }
elseif (!$UserScheduledTask){ elseif (!$UserScheduledTask) {
Write-Log "User context execution not installed..." Write-Log "User context execution not installed..."
} }
} }

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,6 +1,6 @@
#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) {
$AZCopyLink = (Invoke-WebRequest -Uri https://aka.ms/downloadazcopy-v10-windows -UseBasicParsing -MaximumRedirection 0 -ErrorAction SilentlyContinue).headers.location $AZCopyLink = (Invoke-WebRequest -Uri https://aka.ms/downloadazcopy-v10-windows -UseBasicParsing -MaximumRedirection 0 -ErrorAction SilentlyContinue).headers.location
$AZCopyVersionRegex = [regex]::new("(\d+\.\d+\.\d+)") $AZCopyVersionRegex = [regex]::new("(\d+\.\d+\.\d+)")

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
@ -95,14 +95,14 @@ Function Get-Policies {
$folder = $service.GetFolder('\') $folder = $service.GetFolder('\')
$task = $folder.GetTask("Winget-AutoUpdate") $task = $folder.GetTask("Winget-AutoUpdate")
$definition = $task.Definition $definition = $task.Definition
for($triggerId=1; $triggerId -le $definition.Triggers.Count; $triggerId++){ for ($triggerId = 1; $triggerId -le $definition.Triggers.Count; $triggerId++) {
if(($definition.Triggers.Item($triggerId).Type -eq "2") -or ($definition.Triggers.Item($triggerId).Type -eq "3")){ if (($definition.Triggers.Item($triggerId).Type -eq "2") -or ($definition.Triggers.Item($triggerId).Type -eq "3")) {
$PreStartBoundary = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(0,11) $PreStartBoundary = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(0, 11)
$PostStartBoundary = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(19,6) $PostStartBoundary = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(19, 6)
$Boundary = $PreStartBoundary + $($WAUPolicies.WAU_UpdatesAtTime) + $PostStartBoundary $Boundary = $PreStartBoundary + $($WAUPolicies.WAU_UpdatesAtTime) + $PostStartBoundary
$definition.Triggers.Item($triggerId).StartBoundary = $Boundary $definition.Triggers.Item($triggerId).StartBoundary = $Boundary
break break
$triggerId-=1 $triggerId -= 1
} }
} }
$folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null
@ -116,14 +116,14 @@ Function Get-Policies {
$folder = $service.GetFolder('\') $folder = $service.GetFolder('\')
$task = $folder.GetTask("Winget-AutoUpdate") $task = $folder.GetTask("Winget-AutoUpdate")
$definition = $task.Definition $definition = $task.Definition
for($triggerId=1; $triggerId -le $definition.Triggers.Count; $triggerId++){ for ($triggerId = 1; $triggerId -le $definition.Triggers.Count; $triggerId++) {
if(($definition.Triggers.Item($triggerId).Type -eq "2") -or ($definition.Triggers.Item($triggerId).Type -eq "3")){ if (($definition.Triggers.Item($triggerId).Type -eq "2") -or ($definition.Triggers.Item($triggerId).Type -eq "3")) {
$PreStartBoundary = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(0,11) $PreStartBoundary = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(0, 11)
$PostStartBoundary = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(19,6) $PostStartBoundary = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(19, 6)
$Boundary = $PreStartBoundary + "06:00:00" + $PostStartBoundary $Boundary = $PreStartBoundary + "06:00:00" + $PostStartBoundary
$definition.Triggers.Item($triggerId).StartBoundary = $Boundary $definition.Triggers.Item($triggerId).StartBoundary = $Boundary
break break
$triggerId-=1 $triggerId -= 1
} }
} }
$folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null
@ -137,11 +137,11 @@ Function Get-Policies {
$folder = $service.GetFolder('\') $folder = $service.GetFolder('\')
$task = $folder.GetTask("Winget-AutoUpdate") $task = $folder.GetTask("Winget-AutoUpdate")
$definition = $task.Definition $definition = $task.Definition
for($triggerId=1; $triggerId -le $definition.Triggers.Count; $triggerId++){ for ($triggerId = 1; $triggerId -le $definition.Triggers.Count; $triggerId++) {
if(($definition.Triggers.Item($triggerId).Type -eq "2") -or ($definition.Triggers.Item($triggerId).Type -eq "3")){ if (($definition.Triggers.Item($triggerId).Type -eq "2") -or ($definition.Triggers.Item($triggerId).Type -eq "3")) {
$UpdatesAtTime = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(11,8) $UpdatesAtTime = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(11, 8)
$definition.Triggers.Remove($triggerId) $definition.Triggers.Remove($triggerId)
$triggerId-=1 $triggerId -= 1
} }
} }
$folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null
@ -160,11 +160,11 @@ Function Get-Policies {
$definition = $task.Definition $definition = $task.Definition
$definition.Triggers.Count | Out-Null $definition.Triggers.Count | Out-Null
switch ($($WAUPolicies.WAU_UpdatesInterval)) { switch ($($WAUPolicies.WAU_UpdatesInterval)) {
"Daily" {$tasktrigger = New-ScheduledTaskTrigger -Daily -At $($WAUConfig.WAU_UpdatesAtTime); break} "Daily" { $tasktrigger = New-ScheduledTaskTrigger -Daily -At $($WAUConfig.WAU_UpdatesAtTime); break }
"BiDaily" {$tasktrigger = New-ScheduledTaskTrigger -Daily -At $($WAUConfig.WAU_UpdatesAtTime) -DaysInterval 2; break} "BiDaily" { $tasktrigger = New-ScheduledTaskTrigger -Daily -At $($WAUConfig.WAU_UpdatesAtTime) -DaysInterval 2; break }
"Weekly" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At $($WAUConfig.WAU_UpdatesAtTime) -DaysOfWeek 2; break} "Weekly" { $tasktrigger = New-ScheduledTaskTrigger -Weekly -At $($WAUConfig.WAU_UpdatesAtTime) -DaysOfWeek 2; break }
"BiWeekly" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At $($WAUConfig.WAU_UpdatesAtTime) -DaysOfWeek 2 -WeeksInterval 2; break} "BiWeekly" { $tasktrigger = New-ScheduledTaskTrigger -Weekly -At $($WAUConfig.WAU_UpdatesAtTime) -DaysOfWeek 2 -WeeksInterval 2; break }
"Monthly" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At $($WAUConfig.WAU_UpdatesAtTime) -DaysOfWeek 2 -WeeksInterval 4; break} "Monthly" { $tasktrigger = New-ScheduledTaskTrigger -Weekly -At $($WAUConfig.WAU_UpdatesAtTime) -DaysOfWeek 2 -WeeksInterval 4; break }
} }
if ($definition.Triggers.Count -gt 0) { if ($definition.Triggers.Count -gt 0) {
$triggers = @() $triggers = @()
@ -185,11 +185,11 @@ Function Get-Policies {
$folder = $service.GetFolder('\') $folder = $service.GetFolder('\')
$task = $folder.GetTask("Winget-AutoUpdate") $task = $folder.GetTask("Winget-AutoUpdate")
$definition = $task.Definition $definition = $task.Definition
for($triggerId=1; $triggerId -le $definition.Triggers.Count; $triggerId++){ for ($triggerId = 1; $triggerId -le $definition.Triggers.Count; $triggerId++) {
if(($definition.Triggers.Item($triggerId).Type -eq "2") -or ($definition.Triggers.Item($triggerId).Type -eq "3")){ if (($definition.Triggers.Item($triggerId).Type -eq "2") -or ($definition.Triggers.Item($triggerId).Type -eq "3")) {
$UpdatesAtTime = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(11,8) $UpdatesAtTime = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(11, 8)
$definition.Triggers.Remove($triggerId) $definition.Triggers.Remove($triggerId)
$triggerId-=1 $triggerId -= 1
} }
} }
$folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null
@ -251,10 +251,10 @@ Function Get-Policies {
$task = $folder.GetTask("Winget-AutoUpdate") $task = $folder.GetTask("Winget-AutoUpdate")
$definition = $task.Definition $definition = $task.Definition
$definition.Triggers.Count | Out-Null $definition.Triggers.Count | Out-Null
for($triggerId=1; $triggerId -le $definition.Triggers.Count; $triggerId++){ for ($triggerId = 1; $triggerId -le $definition.Triggers.Count; $triggerId++) {
if($definition.Triggers.Item($triggerId).Type -eq "9"){ if ($definition.Triggers.Item($triggerId).Type -eq "9") {
$definition.Triggers.Remove($triggerId) $definition.Triggers.Remove($triggerId)
$triggerId-=1 $triggerId -= 1
} }
} }
$folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null
@ -268,10 +268,10 @@ Function Get-Policies {
$folder = $service.GetFolder('\') $folder = $service.GetFolder('\')
$task = $folder.GetTask("Winget-AutoUpdate") $task = $folder.GetTask("Winget-AutoUpdate")
$definition = $task.Definition $definition = $task.Definition
for($triggerId=1; $triggerId -le $definition.Triggers.Count; $triggerId++){ for ($triggerId = 1; $triggerId -le $definition.Triggers.Count; $triggerId++) {
if($definition.Triggers.Item($triggerId).Type -eq "9"){ if ($definition.Triggers.Item($triggerId).Type -eq "9") {
$definition.Triggers.Remove($triggerId) $definition.Triggers.Remove($triggerId)
$triggerId-=1 $triggerId -= 1
} }
} }
$folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null

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):
@ -29,7 +29,7 @@ function Invoke-ModsProtect ($ModsPath) {
$acl.Access | ForEach-Object { $acl.RemoveAccessRule($_) } $acl.Access | ForEach-Object { $acl.RemoveAccessRule($_) }
#SYSTEM Full - S-1-5-18 #SYSTEM Full - S-1-5-18
$userSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-18") $userSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-18")
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($userSID,"FullControl","ContainerInherit,ObjectInherit","None","Allow") $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($userSID, "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
$acl.SetAccessRule($rule) $acl.SetAccessRule($rule)
# Save the updated ACL # Save the updated ACL
Set-Acl -Path $directory.FullName -AclObject $acl Set-Acl -Path $directory.FullName -AclObject $acl
@ -37,21 +37,21 @@ function Invoke-ModsProtect ($ModsPath) {
#Administrators Full - S-1-5-32-544 #Administrators Full - S-1-5-32-544
$acl = Get-Acl -Path $directory.FullName $acl = Get-Acl -Path $directory.FullName
$userSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544") $userSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544")
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($userSID,"FullControl","ContainerInherit,ObjectInherit","None","Allow") $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($userSID, "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
$acl.SetAccessRule($rule) $acl.SetAccessRule($rule)
Set-Acl -Path $directory.FullName -AclObject $acl Set-Acl -Path $directory.FullName -AclObject $acl
#Local Users ReadAndExecute - S-1-5-32-545 S-1-5-11 #Local Users ReadAndExecute - S-1-5-32-545 S-1-5-11
$acl = Get-Acl -Path $directory.FullName $acl = Get-Acl -Path $directory.FullName
$userSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-545") $userSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-545")
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($userSID, "ReadAndExecute","ContainerInherit,ObjectInherit","None","Allow") $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($userSID, "ReadAndExecute", "ContainerInherit,ObjectInherit", "None", "Allow")
$acl.SetAccessRule($rule) $acl.SetAccessRule($rule)
Set-Acl -Path $directory.FullName -AclObject $acl Set-Acl -Path $directory.FullName -AclObject $acl
#Authenticated Users ReadAndExecute - S-1-5-11 #Authenticated Users ReadAndExecute - S-1-5-11
$acl = Get-Acl -Path $directory.FullName $acl = Get-Acl -Path $directory.FullName
$userSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-11") $userSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-11")
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($userSID, "ReadAndExecute","ContainerInherit,ObjectInherit","None","Allow") $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($userSID, "ReadAndExecute", "ContainerInherit,ObjectInherit", "None", "Allow")
$acl.SetAccessRule($rule) $acl.SetAccessRule($rule)
Set-Acl -Path $directory.FullName -AclObject $acl Set-Acl -Path $directory.FullName -AclObject $acl

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 @@
#Initialisation # Initialisation
function Start-Init { function Start-Init {

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 {
@ -31,7 +31,7 @@ function Start-NotifTask {
$XMLbinding.Attributes.Append($XMLbindingAtt1) | Out-Null $XMLbinding.Attributes.Append($XMLbindingAtt1) | Out-Null
$XMLimagepath = "$WorkingDir\icons\$MessageType.png" $XMLimagepath = "$WorkingDir\icons\$MessageType.png"
if (Test-Path $XMLimagepath){ if (Test-Path $XMLimagepath) {
# Creation of a image node # Creation of a image node
$XMLimage = $ToastTemplate.CreateElement("image") $XMLimage = $ToastTemplate.CreateElement("image")
$XMLbinding.AppendChild($XMLimage) | Out-Null $XMLbinding.AppendChild($XMLimage) | Out-Null
@ -43,7 +43,7 @@ function Start-NotifTask {
$XMLimage.Attributes.Append($XMLimageAtt2) | Out-Null $XMLimage.Attributes.Append($XMLimageAtt2) | Out-Null
} }
if ($Title){ if ($Title) {
# Creation of a text node # Creation of a text node
$XMLtitle = $ToastTemplate.CreateElement("text") $XMLtitle = $ToastTemplate.CreateElement("text")
$XMLtitleText = $ToastTemplate.CreateTextNode($Title) $XMLtitleText = $ToastTemplate.CreateTextNode($Title)
@ -51,7 +51,7 @@ function Start-NotifTask {
$XMLbinding.AppendChild($XMLtitle) | Out-Null $XMLbinding.AppendChild($XMLtitle) | Out-Null
} }
if ($Message){ if ($Message) {
# Creation of a text node # Creation of a text node
$XMLtext = $ToastTemplate.CreateElement("text") $XMLtext = $ToastTemplate.CreateElement("text")
$XMLtextText = $ToastTemplate.CreateTextNode($Message) $XMLtextText = $ToastTemplate.CreateTextNode($Message)
@ -59,7 +59,7 @@ function Start-NotifTask {
$XMLbinding.AppendChild($XMLtext) | Out-Null $XMLbinding.AppendChild($XMLtext) | Out-Null
} }
if ($Body){ if ($Body) {
# Creation of a group node # Creation of a group node
$XMLgroup = $ToastTemplate.CreateElement("group") $XMLgroup = $ToastTemplate.CreateElement("group")
$XMLbinding.AppendChild($XMLgroup) | Out-Null $XMLbinding.AppendChild($XMLgroup) | Out-Null
@ -91,7 +91,7 @@ function Start-NotifTask {
$XMLactionAtt1 = $ToastTemplate.CreateAttribute("content") $XMLactionAtt1 = $ToastTemplate.CreateAttribute("content")
$XMLactionAtt1.Value = $Button1Text $XMLactionAtt1.Value = $Button1Text
$XMLaction.Attributes.Append($XMLactionAtt1) | Out-Null $XMLaction.Attributes.Append($XMLactionAtt1) | Out-Null
if ($Button1Action){ if ($Button1Action) {
$XMLactionAtt2 = $ToastTemplate.CreateAttribute("arguments") $XMLactionAtt2 = $ToastTemplate.CreateAttribute("arguments")
$XMLactionAtt2.Value = $Button1Action $XMLactionAtt2.Value = $Button1Action
$XMLaction.Attributes.Append($XMLactionAtt2) | Out-Null $XMLaction.Attributes.Append($XMLactionAtt2) | Out-Null
@ -126,7 +126,7 @@ function Start-NotifTask {
$ToastTemplate.LastChild.AppendChild($XMLactions) | Out-Null $ToastTemplate.LastChild.AppendChild($XMLactions) | Out-Null
$ToastTemplate.LastChild.AppendChild($XMLtag) | Out-Null $ToastTemplate.LastChild.AppendChild($XMLtag) | Out-Null
if ($OnClickAction){ if ($OnClickAction) {
$ToastTemplate.toast.SetAttribute("activationType", "Protocol") | Out-Null $ToastTemplate.toast.SetAttribute("activationType", "Protocol") | Out-Null
$ToastTemplate.toast.SetAttribute("launch", $OnClickAction) | Out-Null $ToastTemplate.toast.SetAttribute("launch", $OnClickAction) | Out-Null
} }

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
@ -30,7 +30,7 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath, $AzureBlobSASURL) {
# Collect the external list of href links # Collect the external list of href links
$BinLinks = $BinResponse.Links | Select-Object -ExpandProperty HREF $BinLinks = $BinResponse.Links | Select-Object -ExpandProperty HREF
#If there's a directory path in the HREF:s, delete it (IIS) #If there's a directory path in the HREF:s, delete it (IIS)
$CleanBinLinks = $BinLinks -replace "/.*/","" $CleanBinLinks = $BinLinks -replace "/.*/", ""
#Modify strings to HREF:s #Modify strings to HREF:s
$index = 0 $index = 0
foreach ($Bin in $CleanBinLinks) { foreach ($Bin in $CleanBinLinks) {
@ -41,14 +41,14 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath, $AzureBlobSASURL) {
} }
#Delete Local Bins that don't exist Externally #Delete Local Bins that don't exist Externally
$index = 0 $index = 0
$CleanLinks = $BinLinks -replace "/.*/","" $CleanLinks = $BinLinks -replace "/.*/", ""
foreach ($Bin in $InternalBinsNames) { foreach ($Bin in $InternalBinsNames) {
If ($CleanLinks -notcontains "$Bin") { If ($CleanLinks -notcontains "$Bin") {
Remove-Item $LocalMods\bins\$Bin -Force -ErrorAction SilentlyContinue | Out-Null Remove-Item $LocalMods\bins\$Bin -Force -ErrorAction SilentlyContinue | Out-Null
} }
$index++ $index++
} }
$CleanBinLinks = $BinLinks -replace "/.*/","" $CleanBinLinks = $BinLinks -replace "/.*/", ""
$Bin = "" $Bin = ""
#Loop through all links #Loop through all links
$wc = New-Object System.Net.WebClient $wc = New-Object System.Net.WebClient
@ -56,7 +56,7 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath, $AzureBlobSASURL) {
#Check for .exe in listing/HREF:s in an index page pointing to .exe #Check for .exe in listing/HREF:s in an index page pointing to .exe
if ($_ -like "*.exe") { if ($_ -like "*.exe") {
$dateExternalBin = "" $dateExternalBin = ""
$dateLocalBin ="" $dateLocalBin = ""
$wc.OpenRead("$ExternalBins/$_").Close() | Out-Null $wc.OpenRead("$ExternalBins/$_").Close() | Out-Null
$dateExternalBin = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString("yyyy-MM-dd HH:mm:ss") $dateExternalBin = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString("yyyy-MM-dd HH:mm:ss")
if (Test-Path -Path $LocalMods"\bins\"$_) { if (Test-Path -Path $LocalMods"\bins\"$_) {
@ -64,7 +64,7 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath, $AzureBlobSASURL) {
} }
if ($dateExternalBin -gt $dateLocalBin) { if ($dateExternalBin -gt $dateLocalBin) {
$SaveBin = Join-Path -Path "$LocalMods\bins" -ChildPath $_ $SaveBin = Join-Path -Path "$LocalMods\bins" -ChildPath $_
Invoke-WebRequest -Uri "$ExternalBins/$_" -OutFile $SaveBin.Replace("%20"," ") -UseBasicParsing Invoke-WebRequest -Uri "$ExternalBins/$_" -OutFile $SaveBin.Replace("%20", " ") -UseBasicParsing
} }
} }
} }
@ -74,7 +74,7 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath, $AzureBlobSASURL) {
$ModLinks = $WebResponse.Links | Select-Object -ExpandProperty HREF $ModLinks = $WebResponse.Links | Select-Object -ExpandProperty HREF
#If there's a directory path in the HREF:s, delete it (IIS) #If there's a directory path in the HREF:s, delete it (IIS)
$CleanLinks = $ModLinks -replace "/.*/","" $CleanLinks = $ModLinks -replace "/.*/", ""
#Modify strings to HREF:s #Modify strings to HREF:s
$index = 0 $index = 0
@ -88,7 +88,7 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath, $AzureBlobSASURL) {
#Delete Local Mods that don't exist Externally #Delete Local Mods that don't exist Externally
$DeletedMods = 0 $DeletedMods = 0
$index = 0 $index = 0
$CleanLinks = $ModLinks -replace "/.*/","" $CleanLinks = $ModLinks -replace "/.*/", ""
foreach ($Mod in $InternalModsNames) { foreach ($Mod in $InternalModsNames) {
If ($CleanLinks -notcontains "$Mod") { If ($CleanLinks -notcontains "$Mod") {
Remove-Item $LocalMods\$Mod -Force -ErrorAction SilentlyContinue | Out-Null Remove-Item $LocalMods\$Mod -Force -ErrorAction SilentlyContinue | Out-Null
@ -97,7 +97,7 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath, $AzureBlobSASURL) {
$index++ $index++
} }
$CleanLinks = $ModLinks -replace "/.*/","" $CleanLinks = $ModLinks -replace "/.*/", ""
#Loop through all links #Loop through all links
$wc = New-Object System.Net.WebClient $wc = New-Object System.Net.WebClient
@ -106,7 +106,7 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath, $AzureBlobSASURL) {
if (($_ -like "*.ps1") -or ($_ -like "*.txt")) { if (($_ -like "*.ps1") -or ($_ -like "*.txt")) {
try { try {
$dateExternalMod = "" $dateExternalMod = ""
$dateLocalMod ="" $dateLocalMod = ""
$wc.OpenRead("$ExternalMods/$_").Close() | Out-Null $wc.OpenRead("$ExternalMods/$_").Close() | Out-Null
$dateExternalMod = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString("yyyy-MM-dd HH:mm:ss") $dateExternalMod = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString("yyyy-MM-dd HH:mm:ss")
if (Test-Path -Path $LocalMods"\"$_) { if (Test-Path -Path $LocalMods"\"$_) {
@ -146,7 +146,7 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath, $AzureBlobSASURL) {
$AZCopySyncOutput = & $WingetUpdatePath\azcopy.exe sync "$AzureBlobSASURL" "$LocalMods" --from-to BlobLocal --delete-destination=true $AZCopySyncOutput = & $WingetUpdatePath\azcopy.exe sync "$AzureBlobSASURL" "$LocalMods" --from-to BlobLocal --delete-destination=true
$AZCopyOutputLines = $AZCopySyncOutput.Split([Environment]::NewLine) $AZCopyOutputLines = $AZCopySyncOutput.Split([Environment]::NewLine)
foreach( $_ in $AZCopyOutputLines){ foreach ( $_ in $AZCopyOutputLines) {
$AZCopySyncAdditionsRegex = [regex]::new("(?<=Number of Copy Transfers Completed:\s+)\d+") $AZCopySyncAdditionsRegex = [regex]::new("(?<=Number of Copy Transfers Completed:\s+)\d+")
$AZCopySyncDeletionsRegex = [regex]::new("(?<=Number of Deletions at Destination:\s+)\d+") $AZCopySyncDeletionsRegex = [regex]::new("(?<=Number of Deletions at Destination:\s+)\d+")
$AZCopySyncErrorRegex = [regex]::new("^Cannot perform sync due to error:") $AZCopySyncErrorRegex = [regex]::new("^Cannot perform sync due to error:")
@ -154,15 +154,15 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath, $AzureBlobSASURL) {
$AZCopyAdditions = [int] $AZCopySyncAdditionsRegex.Match($_).Value $AZCopyAdditions = [int] $AZCopySyncAdditionsRegex.Match($_).Value
$AZCopyDeletions = [int] $AZCopySyncDeletionsRegex.Match($_).Value $AZCopyDeletions = [int] $AZCopySyncDeletionsRegex.Match($_).Value
if ($AZCopyAdditions -ne 0){ if ($AZCopyAdditions -ne 0) {
$ModsUpdated = $AZCopyAdditions $ModsUpdated = $AZCopyAdditions
} }
if ($AZCopyDeletions -ne 0){ if ($AZCopyDeletions -ne 0) {
$DeletedMods = $AZCopyDeletions $DeletedMods = $AZCopyDeletions
} }
if ($AZCopySyncErrorRegex.Match($_).Value){ if ($AZCopySyncErrorRegex.Match($_).Value) {
Write-Log "AZCopy Sync Error! $_" Write-Log "AZCopy Sync Error! $_"
} }
} }
@ -179,15 +179,15 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath, $AzureBlobSASURL) {
if (Test-Path -Path $ExternalBins"\*.exe") { if (Test-Path -Path $ExternalBins"\*.exe") {
$ExternalBinsNames = Get-ChildItem -Path $ExternalBins -Name -Recurse -Include *.exe $ExternalBinsNames = Get-ChildItem -Path $ExternalBins -Name -Recurse -Include *.exe
#Delete Local Bins that don't exist Externally #Delete Local Bins that don't exist Externally
foreach ($Bin in $InternalBinsNames){ foreach ($Bin in $InternalBinsNames) {
If ($Bin -notin $ExternalBinsNames ){ If ($Bin -notin $ExternalBinsNames ) {
Remove-Item $LocalMods\bins\$Bin -Force -ErrorAction SilentlyContinue | Out-Null Remove-Item $LocalMods\bins\$Bin -Force -ErrorAction SilentlyContinue | Out-Null
} }
} }
#Copy newer external bins #Copy newer external bins
foreach ($Bin in $ExternalBinsNames){ foreach ($Bin in $ExternalBinsNames) {
$dateExternalBin = "" $dateExternalBin = ""
$dateLocalBin ="" $dateLocalBin = ""
if (Test-Path -Path $LocalMods"\bins\"$Bin) { if (Test-Path -Path $LocalMods"\bins\"$Bin) {
$dateLocalBin = (Get-Item "$LocalMods\bins\$Bin").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") $dateLocalBin = (Get-Item "$LocalMods\bins\$Bin").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
} }
@ -204,17 +204,17 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath, $AzureBlobSASURL) {
#Delete Local Mods that don't exist Externally #Delete Local Mods that don't exist Externally
$DeletedMods = 0 $DeletedMods = 0
foreach ($Mod in $InternalModsNames){ foreach ($Mod in $InternalModsNames) {
If ($Mod -notin $ExternalModsNames ){ If ($Mod -notin $ExternalModsNames ) {
Remove-Item $LocalMods\$Mod -Force -ErrorAction SilentlyContinue | Out-Null Remove-Item $LocalMods\$Mod -Force -ErrorAction SilentlyContinue | Out-Null
$DeletedMods++ $DeletedMods++
} }
} }
#Copy newer external mods #Copy newer external mods
foreach ($Mod in $ExternalModsNames){ foreach ($Mod in $ExternalModsNames) {
$dateExternalMod = "" $dateExternalMod = ""
$dateLocalMod ="" $dateLocalMod = ""
if (Test-Path -Path $LocalMods"\"$Mod) { if (Test-Path -Path $LocalMods"\"$Mod) {
$dateLocalMod = (Get-Item "$LocalMods\$Mod").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") $dateLocalMod = (Get-Item "$LocalMods\$Mod").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
} }

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,10 +1,10 @@
#Function to Update an App #Function to update an App
Function Update-App ($app) { Function Update-App ($app) {
#Get App Info #Get App Info
$ReleaseNoteURL = Get-AppInfo $app.Id $ReleaseNoteURL = Get-AppInfo $app.Id
if ($ReleaseNoteURL){ if ($ReleaseNoteURL) {
$Button1Text = $NotifLocale.local.outputs.output[10].message $Button1Text = $NotifLocale.local.outputs.output[10].message
} }

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,8 +1,8 @@
#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") {
if (!$RunSwitch) {$RunSwitch = " "} if (!$RunSwitch) { $RunSwitch = " " }
if (!$User) { if (!$User) {
if (!$RunWait) { if (!$RunWait) {
Start-Process $Run -ArgumentList $RunSwitch Start-Process $Run -ArgumentList $RunSwitch
@ -20,42 +20,37 @@ 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) {
$UninstallString = $obj.GetValue('UninstallString') $UninstallString = $obj.GetValue('UninstallString')
$CleanedUninstallString = $UninstallString.Trim([char]0x0022) $CleanedUninstallString = $UninstallString.Trim([char]0x0022)
@ -111,7 +106,7 @@ function Uninstall-ModsApp ($AppUninst) {
} }
if (!$x64) { if (!$x64) {
$InstalledSoftware = Get-ChildItem "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" $InstalledSoftware = Get-ChildItem "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
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)
@ -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
@ -178,7 +172,7 @@ function Remove-ModsLnk ($Lnk) {
function Add-ModsReg ($AddKey, $AddValue, $AddTypeData, $AddType) { function Add-ModsReg ($AddKey, $AddValue, $AddTypeData, $AddType) {
if ($AddKey -like "HKEY_LOCAL_MACHINE*") { if ($AddKey -like "HKEY_LOCAL_MACHINE*") {
$AddKey = $AddKey.replace("HKEY_LOCAL_MACHINE","HKLM:") $AddKey = $AddKey.replace("HKEY_LOCAL_MACHINE", "HKLM:")
} }
if (!(Test-Path "$AddKey")) { if (!(Test-Path "$AddKey")) {
New-Item $AddKey -Force -ErrorAction SilentlyContinue | Out-Null New-Item $AddKey -Force -ErrorAction SilentlyContinue | Out-Null
@ -189,7 +183,7 @@ function Add-ModsReg ($AddKey, $AddValue, $AddTypeData, $AddType) {
function Remove-ModsReg ($DelKey, $DelValue) { function Remove-ModsReg ($DelKey, $DelValue) {
if ($DelKey -like "HKEY_LOCAL_MACHINE*") { if ($DelKey -like "HKEY_LOCAL_MACHINE*") {
$DelKey = $DelKey.replace("HKEY_LOCAL_MACHINE","HKLM:") $DelKey = $DelKey.replace("HKEY_LOCAL_MACHINE", "HKLM:")
} }
if (Test-Path "$DelKey") { if (Test-Path "$DelKey") {
if (!$DelValue) { if (!$DelValue) {
@ -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
} }
@ -228,14 +221,13 @@ function Copy-ModsFile ($CopyFile, $CopyTo) {
function Edit-ModsFile ($File, $FindText, $ReplaceText) { function Edit-ModsFile ($File, $FindText, $ReplaceText) {
if (Test-Path "$File") { if (Test-Path "$File") {
((Get-Content -path $File -Raw) -replace "$FindText","$ReplaceText") | Set-Content -Path $File -Force -ErrorAction SilentlyContinue | Out-Null ((Get-Content -path $File -Raw) -replace "$FindText", "$ReplaceText") | Set-Content -Path $File -Force -ErrorAction SilentlyContinue | Out-Null
} }
Return Return
} }
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