add noninteractive mode

This commit is contained in:
zoicware
2025-08-01 19:32:56 -04:00
committed by GitHub
parent a20d3b92d1
commit d87359a27d

View File

@@ -1,5 +1,58 @@
param(
[switch]$EnableLogging,
[switch]$nonInteractive,
[ValidateSet('DisableRegKeys',
'RemoveNudgesKeys',
'DisableCopilotPolicies',
'RemoveAppxPackages',
'RemoveRecallFeature',
'RemoveCBSPackages',
'RemoveAIFiles',
'HideAIComponents',
'DisableRewrite',
'RemoveRecallTasks')]
[array]$Options,
[switch]$AllOptions
)
if ($nonInteractive) {
if (!($AllOptions) -and (!$Options -or $Options.Count -eq 0)) {
throw 'Non-Interactive mode was supplied without any options... Please use -Options or -AllOptions when using Non-Interactive Mode'
exit
}
}
If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')) { If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')) {
Start-Process PowerShell.exe -ArgumentList ("-NoProfile -ExecutionPolicy Bypass -File `"{0}`"" -f $PSCommandPath) -Verb RunAs $arglist = "-NoProfile -ExecutionPolicy Bypass -File `"{0}`"" -f $PSCommandPath
#pass the correct params if supplied
if ($nonInteractive) {
$arglist = $arglist + ' -nonInteractive'
if ($AllOptions) {
$arglist = $arglist + ' -AllOptions'
}
if ($Options -and $Options.count -ne 0) {
#if options and alloptions is supplied just do all options
if ($AllOptions) {
#double check arglist has all options (should already have it)
if (!($arglist -like '*-AllOptions*')) {
$arglist = $arglist + ' -AllOptions'
}
}
else {
$arglist = $arglist + " -Options $Options"
}
}
}
if ($EnableLogging) {
$arglist = $arglist + ' -EnableLogging'
}
Start-Process PowerShell.exe -ArgumentList $arglist -Verb RunAs
Exit Exit
} }
@@ -656,7 +709,36 @@ Remove-Item "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCac
} }
if ($nonInteractive) {
if ($AllOptions) {
Disable-Registry-Keys
Remove-Copilot-Nudges-Keys
Disable-Copilot-Policies
Remove-AI-Appx-Packages
Remove-Recall-Optional-Feature
Remove-AI-CBS-Packages
Remove-AI-Files
Hide-AI-Components
Disable-Notepad-Rewrite
Remove-Recall-Tasks
}
else {
#loop through options array and run desired tweaks
switch ($Options) {
'DisableRegKeys' { Disable-Registry-Keys }
'RemoveNudgesKeys' { Remove-Copilot-Nudges-Keys }
'DisableCopilotPolicies' { Disable-Copilot-Policies }
'RemoveAppxPackages' { Remove-AI-Appx-Packages }
'RemoveRecallFeature' { Remove-Recall-Optional-Feature }
'RemoveCBSPackages' { Remove-AI-CBS-Packages }
'RemoveAIFiles' { Remove-AI-Files }
'HideAIComponents' { Hide-AI-Components }
'DisableRewrite' { Disable-Notepad-Rewrite }
'RemoveRecallTasks' { Remove-Recall-Tasks }
}
}
}
else {
#=============================================================================== #===============================================================================
#BEGIN UI #BEGIN UI
@@ -796,7 +878,7 @@ foreach ($func in $functions) {
$description = $functionDescriptions[$funcName] $description = $functionDescriptions[$funcName]
[System.Windows.MessageBox]::Show($description, $funcName, [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information) [System.Windows.MessageBox]::Show($description, $funcName, [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
}.GetNewClosure()) })
$optionContainer.Children.Add($checkbox) | Out-Null $optionContainer.Children.Add($checkbox) | Out-Null
$optionContainer.Children.Add($infoButton) | Out-Null $optionContainer.Children.Add($infoButton) | Out-Null
@@ -1091,6 +1173,7 @@ $bottomGrid.Children.Add($actionPanel) | Out-Null
$mainGrid.Children.Add($bottomGrid) | Out-Null $mainGrid.Children.Add($bottomGrid) | Out-Null
$window.ShowDialog() | Out-Null $window.ShowDialog() | Out-Null
}
#cleanup code #cleanup code
try { try {
@@ -1108,5 +1191,6 @@ if ($ogExecutionPolicy) {
} }
$input = Read-Host 'Done! Press Any Key to Exit' Write-Host 'Done! Press Any Key to Exit...' -ForegroundColor Green
if ($input) { exit } $Host.UI.RawUI.ReadKey() *>$null
exit