PowerShell/update_and_clean.ps1

31 lines
960 B
PowerShell
Raw Normal View History

2023-06-18 00:28:56 +00:00
param([switch]$elevated)
# If not in an Administrator environment
If (!(New-Object Security.Principal.WindowsPrincipal $(
[Security.Principal.WindowsIdentity]::GetCurrent()
2023-06-18 00:37:01 +00:00
)).IsInRole(
[Security.Principal.WindowsBuiltinRole]::Administrator
)
) {
2023-06-18 00:28:56 +00:00
# and elevating hasn't already been tried
if (!$elevated) {
2023-06-18 17:24:35 +00:00
# attempt to become Administrator by re-invoking this script
2023-06-18 00:28:56 +00:00
Start-Process PowerShell -Verb RunAs -ArgumentList (
'-noprofile -noexit -file "{0}" -elevated' -f ($MyInvocation.MyCommand.Definition)
)
}
# otherwise just exit.
2023-06-18 17:36:28 +00:00
Exit-PSHostProcess
2023-06-18 00:28:56 +00:00
}
Get-WindowsUpdate -AcceptAll -Install
if (Get-Command "scoop.exe" -ErrorAction SilentlyContinue) {
scoop update
scoop update --all
scoop cache rm *
}
if (Get-Command "bleachbit.exe" -ErrorAction SilentlyContinue) {
# Clean everything selected in the UI last time it was run.
# So... run The UI to set things up initially.
bleachbit --preset --clean
}