Skip to content

Instantly share code, notes, and snippets.

@tknhs
Created March 13, 2022 01:27
Show Gist options
  • Save tknhs/7f84db179ed93cffe106304d134f1782 to your computer and use it in GitHub Desktop.
Save tknhs/7f84db179ed93cffe106304d134f1782 to your computer and use it in GitHub Desktop.
Windows Updateの有効/無効化を実施して更新する
$windows_module_installer = "TrustedInstaller"
$windows_update = "wuauserv"
Get-Service -Name $windows_module_installer
Get-Service -Name $windows_update
$answer = (Read-Host "Windows Update 有効化/無効化 (e/d)")
if($answer -eq "e"){
Set-Service -Name $windows_module_installer -StartupType "Manual"
Set-Service -Name $windows_update -StartupType "Manual"
Start-Service -Name $windows_module_installer
Start-Service -Name $windows_update
Get-WUInstall -AcceptAll -AutoReboot -Install
} elseif($answer -eq "d") {
for($i=0; $i -lt 5; $i++) {
$status_wmi = (Get-Service -Name $windows_module_installer).Status
$status_wu = (Get-Service -Name $windows_update).Status
if (($status_wmi -eq "Stopped") -And ($status_wu -eq "Stopped")) {
break
} else {
Stop-Service -Name $windows_module_installer
Stop-Service -Name $windows_update
Set-Service -Name $windows_module_installer -StartupType "Disabled"
Set-Service -Name $windows_update -StartupType "Disabled"
}
Start-Sleep -s 5
}
} else {
Write-Host "please input: e or d."
}
@tknhs
Copy link
Author

tknhs commented Mar 30, 2022

Install-Module -Name PSWindowsUpdate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment