-
-
Save cfsamson/4b11a130335a4c16ac5f384409dd1eec to your computer and use it in GitHub Desktop.
Powershell script to set date and time settings and update Windows
This file contains hidden or 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
############################################################ | |
# Powershell script to set date and time settings and update Windows | |
# Author: Joshua Haupt [email protected] 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