Files
winutil/functions/private/Invoke-WinUtilCurrentSystem.ps1
T

145 lines
5.5 KiB
PowerShell
Raw Normal View History

+2
2023-05-09 13:14:27 -05:00
Function Invoke-WinUtilCurrentSystem {
<#
2023-10-19 17:12:55 -05:00
.SYNOPSIS
Checks to see what tweaks have already been applied and what programs are installed, and checks the according boxes
+2
2023-05-09 13:14:27 -05:00
2023-10-19 17:12:55 -05:00
.EXAMPLE
2026-02-17 12:39:44 -06:00
InvokeWinUtilCurrentSystem -Checkbox "winget"
+2
2023-05-09 13:14:27 -05:00
#>
param(
$CheckBox
)
if ($CheckBox -eq "choco") {
$apps = (choco list | Select-String -Pattern "^\S+").Matches.Value
$filter = Get-WinUtilVariables -Type Checkbox | Where-Object {$psitem -like "WPFInstall*"}
$sync.GetEnumerator() | Where-Object {$psitem.Key -in $filter} | ForEach-Object {
$dependencies = @($sync.configs.applications.$($psitem.Key).choco -split ";")
if ($dependencies -in $apps) {
Write-Output $psitem.name
}
}
}
+2
2023-05-09 13:14:27 -05:00
if ($checkbox -eq "winget") {
+2
2023-05-09 13:14:27 -05:00
$originalEncoding = [Console]::OutputEncoding
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()
$Sync.InstalledPrograms = winget list -s winget | Select-Object -skip 3 | ConvertFrom-String -PropertyNames "Name", "Id", "Version", "Available" -Delimiter '\s{2,}'
[Console]::OutputEncoding = $originalEncoding
$filter = Get-WinUtilVariables -Type Checkbox | Where-Object {$psitem -like "WPFInstall*"}
$sync.GetEnumerator() | Where-Object {$psitem.Key -in $filter} | ForEach-Object {
$dependencies = @($sync.configs.applications.$($psitem.Key).winget -split ";")
2023-07-13 15:46:00 -05:00
if ($dependencies[-1] -in $sync.InstalledPrograms.Id) {
Write-Output $psitem.name
+2
2023-05-09 13:14:27 -05:00
}
}
}
2026-02-10 13:37:37 -06:00
if ($CheckBox -eq "tweaks") {
+2
2023-05-09 13:14:27 -05:00
2026-02-10 13:37:37 -06:00
if (!(Test-Path 'HKU:\')) {$null = (New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS)}
+2
2023-05-09 13:14:27 -05:00
$ScheduledTasks = Get-ScheduledTask
$sync.configs.tweaks | Get-Member -MemberType NoteProperty | ForEach-Object {
$Config = $psitem.Name
#WPFEssTweaksTele
2026-02-10 13:37:37 -06:00
$entry = $sync.configs.tweaks.$Config
$registryKeys = $entry.registry
$scheduledtaskKeys = $entry.scheduledtask
$serviceKeys = $entry.service
$appxKeys = $entry.appx
$invokeScript = $entry.InvokeScript
$entryType = $entry.Type
if ($registryKeys -or $scheduledtaskKeys -or $serviceKeys) {
$Values = @()
2023-10-19 17:12:55 -05:00
2026-02-10 13:37:37 -06:00
if ($entryType -eq "Toggle") {
if (-not (Get-WinUtilToggleStatus $Config)) {
$values += $False
}
} else {
$registryMatchCount = 0
$registryTotal = 0
2026-02-10 13:37:37 -06:00
Foreach ($tweaks in $registryKeys) {
Foreach ($tweak in $tweaks) {
$registryTotal++
$regstate = $null
2026-02-10 13:37:37 -06:00
if (Test-Path $tweak.Path) {
$regstate = Get-ItemProperty -Name $tweak.Name -Path $tweak.Path -ErrorAction SilentlyContinue | Select-Object -ExpandProperty $($tweak.Name)
}
if ($null -eq $regstate) {
switch ($tweak.DefaultState) {
"true" {
$regstate = $tweak.Value
}
"false" {
$regstate = $tweak.OriginalValue
}
default {
$regstate = $tweak.OriginalValue
}
}
}
if ($regstate -eq $tweak.Value) {
$registryMatchCount++
+2
2023-05-09 13:14:27 -05:00
}
}
+2
2023-05-09 13:14:27 -05:00
}
2026-02-10 13:37:37 -06:00
if ($registryTotal -gt 0 -and $registryMatchCount -ne $registryTotal) {
$values += $False
}
+2
2023-05-09 13:14:27 -05:00
}
Foreach ($tweaks in $scheduledtaskKeys) {
2026-02-10 13:37:37 -06:00
Foreach ($tweak in $tweaks) {
+2
2023-05-09 13:14:27 -05:00
$task = $ScheduledTasks | Where-Object {$($psitem.TaskPath + $psitem.TaskName) -like "\$($tweak.name)"}
2023-10-19 17:12:55 -05:00
2026-02-10 13:37:37 -06:00
if ($task) {
+2
2023-05-09 13:14:27 -05:00
$actualValue = $task.State
$expectedValue = $tweak.State
if ($expectedValue -ne $actualValue) {
+2
2023-05-09 13:14:27 -05:00
$values += $False
}
}
}
}
Foreach ($tweaks in $serviceKeys) {
2026-02-10 13:37:37 -06:00
Foreach ($tweak in $tweaks) {
+2
2023-05-09 13:14:27 -05:00
$Service = Get-Service -Name $tweak.Name
2023-10-19 17:12:55 -05:00
2026-02-10 13:37:37 -06:00
if ($Service) {
+2
2023-05-09 13:14:27 -05:00
$actualValue = $Service.StartType
$expectedValue = $tweak.StartupType
if ($expectedValue -ne $actualValue) {
+2
2023-05-09 13:14:27 -05:00
$values += $False
}
}
}
}
2026-02-10 13:37:37 -06:00
if ($values -notcontains $false) {
+2
2023-05-09 13:14:27 -05:00
Write-Output $Config
}
2026-02-10 13:37:37 -06:00
} else {
if ($invokeScript -or $appxKeys) {
Write-Debug "Skipping $Config in Get Installed: no detectable registry, scheduled task, or service state."
}
+2
2023-05-09 13:14:27 -05:00
}
}
}
}