Description

Windows Update script for Nano Server running currently.

It also reports current build number of Nano Server. (show WindowsBuildLabExvalue)

Usage

PS> Enter-PSSession -ComputerName <nanoserver> -Credential <your cred>

[nanoserver] PS C:\Path to Script> .\winupdatefornano.ps1

Note

This script only works en-us lang environment.

Sometimes WindowsBuildLabEx return wrong build information.

PowerShell
スクリプトの編集|Remove
# Windows Update for Nano Server 
# winupdatefornano.ps1 
 
$typename = "System.Management.Automation.Host.ChoiceDescription" 
$yes = new-object $typename("&Yes","Yes"$no  = new-object $typename("&No","No"$assembly$yes.getType().AssemblyQualifiedName 
$choice = new-object "System.Collections.ObjectModel.Collection``1[[$assembly]]" 
$choice.add($yes$choice.add($no) 
 
$CurrentWindowsBuildLabEx = (Get-ComputerInfo).WindowsBuildLabEx 
$CurrentNtoskrnl = ((Get-ItemProperty C:\Windows\System32\ntoskrnl.exe).VersionInfo).ProductVersion 
$CurrentMajorVer = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").CurrentMajorVersionNumber 
$CurrentMinorVer = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").CurrentMinorVersionNumber 
$CurrentBldNum = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").CurrentBuild 
$CurrentRevNum = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").UBR 
 
Write-Host "-----------------------------------------------------------------------" 
Write-Host "Current Build Information ..." 
Write-Host $CurrentWindowsBuildLabEx "(from WindowsBuildLabEx)" 
Write-Host $CurrentNtoskrnl "(from ntoskrnl.exe Version Resource)" 
Write-Host $CurrentMajorVer"."$CurrentMinorVer"."$CurrentBldNum"."$CurrentRevNum "(from HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion)" 
Write-Host "-----------------------------------------------------------------------" 
Write-Host "Searching for updates..." 
$sess = New-CimInstance -Namespace root/Microsoft/Windows/WindowsUpdate -ClassName MSFT_WUOperationsSession 
$scanResults = Invoke-CimMethod -InputObject $sess -MethodName ScanForUpdates -Arguments @{SearchCriteria="IsInstalled=0";OnlineScan=$true}  
if ($scanResults.Updates.Count -eq 0) { 
  Write-Host "There are no applicable updates." 
} 
else 
{ 
  $scanResults.Updates 
  $answer = $host.ui.PromptForChoice("Confirm","Do you install this update?",$choice,0) 
  if ($answer -eq 0) { 
  Write-Host "Installing updates..." 
  $scanResults = Invoke-CimMethod -InputObject $sess -MethodName ApplyApplicableUpdates 
  Write-Host "Done." 
  Write-Host "It is recommended to reboot. (type Restart-Comptuer)" 
  } 
  else 
  { 
  Write-Host "Canceled." 
  } 
}