Created
March 13, 2022 01:27
-
-
Save tknhs/7f84db179ed93cffe106304d134f1782 to your computer and use it in GitHub Desktop.
Windows Updateの有効/無効化を実施して更新する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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." | |
} |
Author
tknhs
commented
Mar 30, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment