Skip to content

Instantly share code, notes, and snippets.

@danmaq
Last active November 19, 2017 22:30
Show Gist options
  • Save danmaq/53603d0860bd821e8f9e57b4d9dfbf43 to your computer and use it in GitHub Desktop.
Save danmaq/53603d0860bd821e8f9e57b4d9dfbf43 to your computer and use it in GitHub Desktop.
Script of apply Windows Update automatically. (includes: http://www.vwnet.jp/Windows/PowerShell/FullAutoWU.htm )
@echo off
whoami /groups | Find "High Mandatory Level" > NUL
if not errorlevel 1 goto RUN
powershell -Command Start-Process -Verb runas "%0"
exit /b %errorlevel%
:RUN
powershell -NoProfile -ExecutionPolicy Unrestricted "$s=[scriptblock]::create((gc \"%~f0\"|?{$_.readcount -gt 9})-join\"`n\");&$s" %*
exit /b 0
Set-StrictMode -Version 2.0
function MyWget($src, $dst)
{
set SRCPATH "http://www.vwnet.jp/Windows/PowerShell/ps1/" -option constant
set DSTPATH "C:\WindowsUpdate\" -option constant
mkdir -Force $DSTPATH > $null
$dstfpath = $DSTPATH + $dst
(new-object System.Net.WebClient).Downloadfile($SRCPATH + $src, $dstfpath)
$dstfpath
}
MyWget "autowindowsupdate.txt" "AutoWindowsUpdate.ps1" > $null
. (MyWget "SubmitWU.txt" "SubmitWU.ps1") Full
@echo off
rem USAGE: wait_windows_update [command: run if completed] [args for command]
powershell -NoProfile -ExecutionPolicy Unrestricted "$s=[scriptblock]::create((gc \"%~f0\"|?{$_.readcount -gt 8})-join\"`n\");&$s"
%*
exit /b 0
Set-StrictMode -Version 2.0
echo ">>> Awaiting completion of Windows Update... <<<"
$lastLine = ""
do
{
sleep 10
$newestFile = dir C:\WU_Log\*.log | sort LastWriteTime -Descending | Select -First 1
$lastLine = Get-Content $newestFile.FullName | Select-Object -last 1
echo $lastLine
}
while (-not $lastLine.Contains("Windows Update finished"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment