Added confirmation for updates in deploy script

This commit is contained in:
Bram Prieshof
2022-03-18 15:15:39 +00:00
parent 71ab0008fb
commit 04b3601101

View File

@@ -1,59 +1,65 @@
############################################################### ###############################################################
# @description: # # @description: #
# Used when image get cloned to new system # # Used when image get cloned to new system #
# For Checking activation status, Setting SystemName, # # For Checking activation status, Setting SystemName, #
# running updates for Chocolatry apps and Windows Updates # # running updates for Chocolatry apps and Windows Updates #
# # # #
# @project: IMGSystTools # # @project: IMGSystTools #
# @author: Bram Prieshof # # @author: Bram Prieshof #
############################################################### ###############################################################
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) { if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) { if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments $CommandLine = $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList " Set-ExecutionPolicy -Scope Process Unrestricted -Force; $CommandLine" Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList " Set-ExecutionPolicy -Scope Process Unrestricted -Force; $CommandLine"
Exit Exit
} }
} }
#Disable Windows updates service #Disable Windows updates service
Set-Service -Name "wuauserv" -Status Stopped -StartupType Disabled Set-Service -Name "wuauserv" -Status Stopped -StartupType Disabled
Write-Output "Checking activation status..." Write-Output "Checking activation status..."
$ta = Get-CimInstance -ClassName SoftwareLicensingProduct -Filter "PartialProductKey IS NOT NULL" | Where-Object -Property Name -Like "Windows*" $ta = Get-CimInstance -ClassName SoftwareLicensingProduct -Filter "PartialProductKey IS NOT NULL" | Where-Object -Property Name -Like "Windows*"
if ($ta.LicenseStatus -eq 1) {Write-Output "Activation [OK]"} else {Write-Output "Activation [Error, Opening settings]";Start-Process "ms-settings:activation"; pause } if ($ta.LicenseStatus -eq 1) {Write-Output "Activation [OK]"} else {Write-Output "Activation [Error, Opening settings]";Start-Process "ms-settings:activation"; pause }
Write-Output "Getting System name" Write-Output "Getting System name"
$sysid = Read-Host -Prompt 'Please enter system ID (example: DT001)' $sysid = Read-Host -Prompt 'Please enter system ID (example: DT001)'
Rename-Computer -NewName $sysid Rename-Computer -NewName $sysid
Write-Output "System name [OK]" Write-Output "System name [OK]"
#Chocolaty software updates
Write-Output "Checking Chocolatey package updates" $confirmSupdates = Read-Host "Run Software updates? (y/n)"
choco upgrade -y all if ( $confirmSupdates -eq 'y'){
Write-Output " Chocolatey updates [OK]" Write-Output "Checking Chocolatey package updates"
choco upgrade -y all
#Enable Windows updates service Write-Output " Chocolatey updates [OK]"
Set-Service -Name "wuauserv" -Status Stopped -StartupType Manual }
Write-Output "Checking Windows updates" $confirmWupdates = Read-Host "Run Windows updates? (y/n)"
Import-Module PSWindowsUpdate if ( $confirmWupdates -eq 'y'){
Get-WUInstall -MicrosoftUpdate -AcceptAll -IgnoreReboot -IgnoreRebootRequired -Install #Enable Windows updates service
Write-Output " Windows updates [OK]" Set-Service -Name "wuauserv" -Status Stopped -StartupType Manual
#Removing Created Shortcuts Write-Output "Checking Windows updates"
Remove-Item C:\Users\Public\Desktop\*.lnk Import-Module PSWindowsUpdate
Get-WUInstall -MicrosoftUpdate -AcceptAll -IgnoreReboot -IgnoreRebootRequired -Install
#Remove "Run on login script" if exists Write-Output " Windows updates [OK]"
if (Test-Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\FirstBoot.lnk" -PathType leaf) }
{Remove-Item "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\FirstBoot.lnk"}
#Removing Created Shortcuts
#Finalizing and reboot Remove-Item C:\Users\Public\Desktop\*.lnk
Write-Output ""
Write-Output "" #Remove "Run on login script" if exists
Write-Output "The System deployed successfully, but it needs to be rebooted" if (Test-Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\FirstBoot.lnk" -PathType leaf)
{Remove-Item "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\FirstBoot.lnk"}
$confirmation = Read-Host "Do you want to do that now? y/N:"
if ($confirmation -eq 'y') { #Finalizing and reboot
Restart-Computer -Force Write-Output ""
} Write-Output ""
Write-Output "The System deployed successfully, but it needs to be rebooted"
$confirmation = Read-Host "Do you want to do that now? y/N:"
if ($confirmation -eq 'y') {
Restart-Computer -Force
}