This repository has been archived on 2023-05-21. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
SysTools/DeployTools/Deploy-FirstBoot.ps1
Bram Prieshof a3da939025 Added auto Prepend for systemname and removed enableing/disableing WU
Now prepending 'PC' to the given input (assetID), since windows refuses system name only consisting of numbers.
Removed setting status of Windows updates services since this did not work,
this feature was meant to pause WU until the system was activated, to prevent the network form being overloaded
2022-06-10 14:12:15 +02:00

60 lines
2.7 KiB
PowerShell

###############################################################
# @description: #
# Used when image get cloned to new system #
# For Checking activation status, Setting SystemName, #
# running updates for Chocolatry apps and Windows Updates #
# #
# @project: IMGSystTools #
# @author: Bram Prieshof #
###############################################################
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) {
$CommandLine = $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList " Set-ExecutionPolicy -Scope Process Unrestricted -Force; $CommandLine"
Exit
}
}
Write-Output "Checking activation status..."
$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 }
Write-Output "Getting System name"
$sysid = Read-Host -Prompt 'Please enter asset ID:'
Rename-Computer -NewName "PC$sysid"
Write-Output "System name [OK]"
#Chocolaty software updates
$confirmSupdates = Read-Host "Run Software updates? (y/n)"
if ( $confirmSupdates -eq 'y'){
Write-Output "Checking Chocolatey package updates"
choco upgrade -y all
Write-Output " Chocolatey updates [OK]"
}
$confirmWupdates = Read-Host "Run Windows updates? (y/n)"
if ( $confirmWupdates -eq 'y'){
Write-Output "Checking Windows updates"
Import-Module PSWindowsUpdate
Get-WUInstall -MicrosoftUpdate -AcceptAll -IgnoreReboot -IgnoreRebootRequired -Install
Write-Output " Windows updates [OK]"
}
#Removing Created Shortcuts
Remove-Item C:\Users\Public\Desktop\*.lnk
#Remove "Run on login script" if exists
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"}
#Finalizing and reboot
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
}