Skip to content

Instantly share code, notes, and snippets.

@HauptJ
Last active February 21, 2020 08:38
Show Gist options
  • Save HauptJ/4dd5e28a0ff108d3784a70578c770b3a to your computer and use it in GitHub Desktop.
Save HauptJ/4dd5e28a0ff108d3784a70578c770b3a to your computer and use it in GitHub Desktop.
Powershell script to set date and time settings and update Windows
############################################################
# Powershell script to set date and time settings and update Windows
# Author: Joshua Haupt josh@hauptj.com Date: 22.12.2017
############################################################
##### Set Time Settings #####
Write-Host "Setting Date and Time Settings"
# Source: https://www.ucunleashed.com/1753
# Set Time Zone to Central Standard Time
Write-Host "Setting Time Zone"
Set-TimeZone "Central Standard Time"
# Source: https://stackoverflow.com/questions/28749439/changing-windows-time-and-date-format
# Source: https://superuser.com/questions/1204142/removing-12-hour-time-from-windows-10-login-screen-at-startup-24-hour-already-s
# Set Short date format
Write-Host "Setting Short date format"
Set-ItemProperty -Path "HKCU:\Control Panel\International" -name sShortDate -value "dd-MMM-yy"
# Set Long date format
Write-Host "Setting Long date format"
Set-ItemProperty -Path "HKCU:\Control Panel\International" -name sLongDate -value "dddd-MMMM-yyyy"
# Set Short time format
Write-Host "Setting Short time format"
Set-ItemProperty -Path "HKCU:\Control Panel\International" -name sShortTime -value "HH:mm"
# Set Long time format
Write-Host "Setting Long time format"
Set-ItemProperty -Path "HKCU:\Control Panel\International" -name sTimeFormat -value "HH:mm:ss"
##### Run Windows Updates #####
# Source: https://www.urtech.ca/2017/07/solved-simple-powershell-script-download-install-windows-updates-reboot-necessary/
Write-Host "Updating Windows"
# Requires PowerShell 5.0 or newer
# Apparently NUGET is required for the PSWINDOWSUPDATE module
Install-PackageProvider NuGet -Force
Import-PackageProvider NuGet -Force
# Apparently PSWindowsUpdate module comes from the PSGallery and needs to be trusted
# See https://msdn.microsoft.com/en-us/powershell/gallery/psgallery/psgallery_gettingstarted
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
# Now actually do the update and reboot if necessary
Install-Module PSWindowsUpdate
Get-Command –module PSWindowsUpdate
Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d -Confirm:$false
Get-WUInstall –MicrosoftUpdate –AcceptAll –AutoReboot
##### Set Computer Name #####
Write-Host "Naming Computer"
Rename-computer -NewName "Dragon-Aurora" -Restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment