PowerShell/Scripts/Update-And-Clean.ps1

47 lines
1.1 KiB
PowerShell
Raw Normal View History

2023-06-24 19:03:29 +00:00
param(
[switch]$elevated,
[switch]$CleanOnly
)
2023-06-28 18:27:21 +00:00
winget upgrade --all
2023-06-24 19:03:29 +00:00
if ((Get-Command "scoop" -ErrorAction SilentlyContinue) -and -not $elevated) {
if (-not $CleanOnly) {
scoop update
scoop update --all
}
scoop cache rm *
}
2023-06-18 00:28:56 +00:00
# If not in an Administrator environment
2023-06-24 19:03:29 +00:00
If (-not (New-Object Security.Principal.WindowsPrincipal $(
2023-06-18 00:28:56 +00:00
[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
2023-06-24 19:03:29 +00:00
if (-not $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 (
2023-06-22 15:37:38 +00:00
'-file "{0}" -elevated' -f ($MyInvocation.MyCommand.Definition)
2023-06-18 00:28:56 +00:00
)
}
# otherwise just exit.
2023-06-19 05:13:05 +00:00
exit
2023-06-18 00:28:56 +00:00
}
2023-06-24 02:50:33 +00:00
2023-06-24 19:03:29 +00:00
if (-not $CleanOnly) {
if (-not (Get-Command "Get-WindowsUpdate")) {
Install-Module PSWindowsUpdate
}
Get-WindowsUpdate -AcceptAll -Install
2023-06-18 00:28:56 +00:00
}
2023-06-24 19:03:29 +00:00
if (Get-Command "bleachbit" -ErrorAction SilentlyContinue) {
2023-06-18 00:28:56 +00:00
# Clean everything selected in the UI last time it was run.
# So... run The UI to set things up initially.
bleachbit --preset --clean
}