Just putting this out there for easy copy / pasta
# https://github.com/richie65x
# https://hilite.me/ # (Powershell - 'Fruity') [Highlight!]
#~~~~~~~~~~~~~~~~~~~~~~~~~~~
########################### # start ms-cxh:localonly # oobe\bypassnro # Start "https://github.com/massgravel/Microsoft-Activation-Scripts" #~~~~~~# # c:\windows\system32\sysprep\sysprep.exe /oobe /generalize # https://www.catalog.update.microsoft.com/Search.aspx?q=KB5032190 # NumLock for ALL users / Default profile (logon screen & future users) reg add "HKU\.DEFAULT\Control Panel\Keyboard" /v InitialKeyboardIndicators /t REG_SZ /d 2 /f # NumLock for Current user reg add "HKCU\Control Panel\Keyboard" /v InitialKeyboardIndicators /t REG_SZ /d 2 /f # Windows 10/11 may ignore this due to Fast Startup. powercfg /h off # disable Fast Startup # --- Set DateTime and TimeZone --- $TimeServer = "pool.ntp.org" # You can change to pool.ntp.org, time.nist.gov, etc. $TimeZone = "Eastern Standard Time" # Change as needed Write-Output "Setting time zone to $TimeZone..." tzutil /s "$TimeZone" Write-Output "Configuring time service..." # Ensure time service is enabled Set-Service -Name w32time -StartupType Automatic Start-Service w32time -ErrorAction SilentlyContinue # Point to external NTP source (manual sync mode) w32tm /config /manualpeerlist:$TimeServer /syncfromflags:manual /reliable:NO /update | Out-Null # Restart service to apply changes Restart-Service w32time # Force resync Write-Output "Syncing time with $TimeServer..." w32tm /resync /force # Show result Start-Sleep 3 w32tm /query /status Get-Date # Evaluate Windows activation status: Write-Host (cscript c:\windows\system32\slmgr.vbs /xpr | ? { $_ -Notmatch "Script|reserved" } | Out-String).Trim() -F 10 -B 0 Write-Host "If not activated: Go here: Start 'https://github.com/massgravel/Microsoft-Activation-Scripts' Go to: Method 2 - Traditional (Windows Vista and later) Download and run the script: MAS_AIO.cmd " -F 14 Sleep 10 # END - Evaluate activation status: # Set time-zone automatically Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\tzautoupdate -Name start -Value "3" Set-TimeZone "Eastern Standard Time" Start-Service W32Time w32tm /resync /rediscover # PoSh ~As admin~ shortcut, and S.T.S.T. set up page, on Desktop $PathToDesktop = "C:\Users\$env:Username\Desktop" $TargetFile = "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell_ise.exe" $ShortcutFile = "$PathToDesktop\PoSh-Admin.lnk" $WScriptShell = New-Object -ComObject WScript.Shell $Shortcut = $WScriptShell.CreateShortcut($ShortcutFile) $Shortcut.TargetPath = $TargetFile $Shortcut.Save() $bytes = [System.IO.File]::ReadAllBytes($ShortcutFile) $bytes[0x15] = $bytes[0x15] -bor 0x20 #set byte 21 (0x15) bit 6 (0x20) ON [System.IO.File]::WriteAllBytes($ShortcutFile, $bytes) $TargetFile = "http://www.somethingtoscrollthrough.com/2022/05/firewall.html" $ShortcutFile = "$PathToDesktop\STST ~ PC Set-Up.lnk" $WScriptShell = New-Object -ComObject WScript.Shell $Shortcut = $WScriptShell.CreateShortcut($ShortcutFile) $Shortcut.TargetPath = $TargetFile $ShortCut.IconLocation = "%SystemRoot%\System32\SHELL32.dll,48" $Shortcut.Save() # turn off sleep while plugged in (on AC power) powercfg /change standby-timeout-ac 0 # Toggle 'Set timezone automatically' to 'On' Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\tzautoupdate' -name 'Start' -value 3 # Prevent Edge 'First Run' page # edge://settings/resetProfileSettings # (hit 'reset' - Use this to reset edge if you want to see the First Run) New-Item -Path "Registry::HKLM\SOFTWARE\Policies\Microsoft\MicrosoftEdge" New-Item -Path "Registry::HKLM\SOFTWARE\Policies\Microsoft\MicrosoftEdge\Main" New-ItemProperty -Path "Registry::HKLM\SOFTWARE\Policies\Microsoft\MicrosoftEdge\Main" -Name "PreventFirstRunPage" -Value 1 -PropertyType "DWord" -Force ########################################## # Locate the Dell Command-Update download page and open it: $Mfgr = (Get-CimInstance -ClassName Win32_ComputerSystem).Manufacturer If ($Mfgr -and $Mfgr -match "Dell") { $ErrorActionPreference = "SilentlyContinue" $url = "https://www.dell.com/support/kbdoc/en-us/000177325/dell-command-update" $url = "https://www.dell.com/support/kbdoc/en-us/000177325/dell-command-update" $Page = Invoke-WebRequest $url -UseBasicParsing $Link = ($Page.Links | ? { $_.href -match "driversdetails\?driverid=" } | Select -First 1).href $ErrorActionPreference = "Continue" Write-Host "$url" -F 10 Write-Host " $Link" -F 14 # Can't 'iwr' parse this link - Returns a permissions error. start -FilePath "msedge.exe" -ArgumentList $Link Function Wait {Start-Sleep -Milliseconds 300} Wait; Wait; Wait; Wait Do { $edge = Get-Process msedge | ? { $_.MainWindowTitle -match "Dell Command" } | Select -First 1 } Until ( $edge ); Write-Host "Tab Found..." Add-Type -AssemblyName System.Windows.Forms [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $wshell = New-Object -ComObject wscript.shell $wshell.AppActivate($edge.Id) | Out-Null; Wait # Focus Edge, 'Out-Null' because this prints 'True' on the console [System.Windows.Forms.SendKeys]::SendWait("^+a"); Wait # open search box [System.Windows.Forms.SendKeys]::SendWait("Dell Command"); Wait [System.Windows.Forms.SendKeys]::SendWait("{Tab}{Tab}{Tab}"); Wait [System.Windows.Forms.SendKeys]::SendWait("{ENTER}"); Wait; Wait # search for tab [System.Windows.Forms.SendKeys]::SendWait("{PGDN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}") Do { Sleep 5; } Until ( gci "C:\Users\$env:USERNAME\Downloads" | ? { $_.Name -match "Dell-Command" } ) } # END 'If ($Mfgr -and $Mfgr -match "Dell") {' ############### END DCU finder ##################### # Download and run Windows PC Health, and Update Assistant: # $Ver = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').DisplayVersion Sleep 20 $Foldr = "C:\Users\$env:USERNAME\Downloads" $Apps = "WindowsPCHealthCheckSetup|Windows11InstallationAssistant" # gci $Foldr | ? { $_.Name -match $Apps } | ri -Force # Download PC Health Check App and Installation Assistant - Page: https://www.microsoft.com/en-us/software-download/windows11 @("https://aka.ms/GetPCHealthCheckApp","https://go.microsoft.com/fwlink/?linkid=2171764") | % { start -FilePath "msedge.exe" -ArgumentList $_ } Get-Process | ? {$_.ProcessName -Match 'OneDrive'} | Stop-Process -Force Do { $PC_HC = (gci "$Foldr" | ? { $_.Name -match "WindowsPCHealthCheckSetup.msi" }).FullName } Until ( $PC_HC ) msiexec.exe /i $PC_HC /qn # Install and run it. Do {Sleep 1} Until ( Test-Path "C:\Users\$env:USERNAME\AppData\Local\PCHealthCheck\PCHealthCheck.exe" ) If (!(gps | ? { $_.Name -match "PCHealthCheck" })) { start "C:\Users\$env:USERNAME\AppData\Local\PCHealthCheck\PCHealthCheck.exe" } Do { $Asst = (gci "$Foldr" | ? { $_.Name -match "Windows11InstallationAssistant.exe" }).FullName } Until ( $Asst ) Write-Host " Click the 'Check Now' [BUTTON] in the 'PC Health Check' window... Then close 'PC Health Check'..." -F 11 $exe = "C:\Users\$env:USERNAME\AppData\Local\PCHealthCheck\PCHealthCheck.exe" Add-Type @" using System; using System.Runtime.InteropServices; public class Win32 { [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd); } "@ $p = Start-Process $exe -PassThru Start-Sleep -Seconds 2 $p.Refresh() [Win32]::SetForegroundWindow($p.MainWindowHandle) | Out-Null Do {$Running = $null; $Running = gps | ? { $_.Name -match "PCHealthCheck" } } Until (!$Running) $wsh = New-Object -ComObject Wscript.Shell 1..50 | % { $wsh.SendKeys([char]175) } [System.Media.SystemSounds]::Asterisk.Play() Write-Host "Starting the 'Installation Assistant'..." -F 14 start "C:\Users\$env:USERNAME\Downloads\Windows11InstallationAssistant.exe" ############### Windows PC Health, and Update Assistant ##################### Return; Break ##~~~~~~~~~ Grab the Office installer ~~~~~~~~~~~~~~ # Start 'https://www.microsoft.com/en-us/download/details.aspx?id=49117' $dir = "$env:USERPROFILE\Downloads" New-Item -ItemType Directory -Path "$dir\Office" -Force $url = "https://github.com/richie65x/MS_OfcDeplyTool/releases/download/v1.0/officedeploymenttool.exe" curl.exe -k -L $url -o "$dir\officedeploymenttool.exe" Do { Sleep 5; $ODT = ( gci $dir | ? { $_.Name -match "officedeployment" } ).FullName } Until ( $ODT ) Sleep 3 # Minimize the browser after download completes. # Use this if using the 'Start 'https://www.microsoft.com...' <# gps msedge -ErrorAction SilentlyContinue | Where-Object MainWindowHandle | % { $sig = '[DllImport("user32.dll")]public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);' $type = Add-Type -MemberDefinition $sig -Name NativeMethods -Namespace Win32 -PassThru $type::ShowWindowAsync($_.MainWindowHandle, 2) | Out-Null } #> $xmlPath = "$dir\Office\configuration.xml" $setupExe = "$dir\Office\setup.exe" # $ODT = (gci $dir | ? { $_.Name -match "officedeployment" }).FullName $extractArgs = @("/extract:$dir\Office", "/quiet") $extractProc = Start-Process -FilePath $ODT -ArgumentList $extractArgs -Wait -NoNewWindow -PassThru $xmlContent = @" <Configuration> <Add OfficeClientEdition="64" Channel="Current"> <Product ID="O365ProPlusRetail"> <Language ID="en-us" /> </Product> </Add> <Display Level="None" AcceptEULA="TRUE" /> </Configuration> "@ Set-Content -Path $xmlPath -Value $xmlContent -Encoding Utf8 Write-Host "Downloading and installing Office (Silently - This may take several minutes)..." -F 14 $installArgs = @("/configure", $xmlPath) $installProc = Start-Process -FilePath $setupExe -ArgumentList $installArgs -Wait -NoNewWindow -PassThru $Props = @( 'HKLM:\Software\Microsoft\Office\ClickToRun\Configuration', 'SilentlyContinue', 'ProductReleaseIds', 'InstallationPath', 'AudienceData', 'VersionToReport' ) gp $Props[0] -ea $Props[1] | fl $Props[2..5] $wsh = New-Object -ComObject Wscript.Shell 1..50 | % { $wsh.SendKeys([char]175) } [System.Media.SystemSounds]::Asterisk.Play() Return; Break ##################################### Start-Service wuauserv [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Install-PackageProvider -Name NuGet -Force Install-Module -Name PSWindowsUpdate -Force Get-Package -Name PSWindowsUpdate -Force Set-ExecutionPolicy -ExecutionPolicy Bypass -Force Import-Module PSWindowsUpdate # $ErrorActionPreference = "SilentlyContinue" Get-WUList Sleep 5 Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -AutoReboot $ErrorActionPreference = "Continue" Return $wsh = New-Object -ComObject Wscript.Shell 1..50 | % { $wsh.SendKeys([char]175) } [System.Media.SystemSounds]::Asterisk.Play() ########################### Break # Enable RDP - and show the active IP address Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -name "fDenyTSConnections" -value 0 Enable-NetFirewallRule -DisplayGroup "Remote Desktop" (Get-NetIPConfiguration | ? {$_.IPv4DefaultGateway -ne $null -and $_.NetAdapter.status -ne "Disconnected"}).IPv4Address.IPAddress # Disable the firewall netsh advfirewall set allprofiles state off # Set the current connection to 'Private' - By default it is 'Public' so WinRM will not enable. Set-NetConnectionProfile -InterfaceIndex $((Get-NetConnectionProfile).InterfaceIndex) -NetworkCategory Private # Enable WinRM c:\windows\system32\winrm.cmd quickconfig -quiet # Add DOT.NET 2.0--3.5 # Add-WindowsCapability -Online -Name NetFx3~~~~ ########################### # Get Serial number from BIOS $SerialNumber = (Get-WmiObject -class win32_bios).SerialNumber # Dell computers have a shorter Serial number, but others (ie. BeeLink mini's) are too long - This shortens it (to 7 characters) if the SN is longer than 9 characters. # MPC = Mini PC If ($SerialNumber.Length -gt 9) { $SerialNumber = "MPC$($SerialNumber.Remove(0, ($SerialNumber.Length - 7)))" } $SerialNumber #Read-Host # Rename the computer to its SN Rename-Computer -NewName $SerialNumber -Force Sleep 5 # Gotta reboot shutdown -r -t 0 ########################### # Make sure you have successfully, and correctly set the computers hostname hostname # Enable NumLock Add-Type -AssemblyName System.Windows.Forms If ( ! [System.Windows.Forms.Control]:: IsKeyLocked('NumLock') ) { (New-Object -ComObject WScript.Shell). SendKeys('{NUMLOCK}') } [Int]$ChassisType_Q = (Get-CimInstance -ClassName Win32_SystemEnclosure).ChassisTypes | Out-String $Chassis_All = "Form;ChasVal`nDesktop;3`nLaptop;9`nLaptop;10`nTablet;30`nDesktop;35" | ConvertFrom-Csv -Delimiter ';' $Chassis_All | % { $_.ChasVal = [Int]$_.ChasVal } $Chassis = ( $Chassis_All | ? { $_.ChasVal -eq $ChassisType_Q } ).Form $OUList = "Loc;OU SVP - Desktop - Prod ;OU=SVPDskProduction,OU=SVPOU SVP - Laptop - Office;OU=SVPLpt10,OU=SVPOU SVP - Desktop - Office;OU=SVPDskOffice,OU=SVPOU WCP - Laptop - Office;OU=WCPLpt10,OU=WCPOU WCP - Desktop - Prod ;OU=WCPDskProduction,OU=WCPOU WCP - Desktop - Office;OU=WCPDskOffice,OU=WCPOU" | ConvertFrom-Csv -Delimiter ';' If ($Chassis) { $OUList = $OUList | ? { $_.Loc -match $Chassis } } Do { ''; $Counter = 1 $OUList | % { If ($_.Loc -match "SVP") { $Bc = 11}; If ($_.Loc -match "WC") { $Bc = 10} Write-Host "$Counter`:" -F 14 -N; Write-Host " $($_.Loc)" -F $Bc $Counter++ } '' Write-Host "Select Location - Enter selection #:" -fore 10 -back 8 -no Write-Host " [1-$($OUList.Count)]: " -Fore 14 -No $ErrorActionPreference = "SilentlyContinue" $ans = $null; [int]$ans = Read-Host } Until ($ans -is [int] -and 1..($OUList.Count) -ccontains $ans) If (1..$($OUList.Count) -contains $ans) { $Domain_Name = (Get-DnsClient -InterfaceIndex $((Get-NetConnectionProfile).InterfaceIndex)).ConnectionSpecificSuffix $OUSffx = ",OU=UsuiOU,OU=UICOU,"; $Domain_Name.Split('.') | % { $OUSffx += "DC=$($_)," } $OUSffx = $OUSffx.TrimEnd(',') $OUPath = "$($OUList[$ans-1].OU)$OUSffx" ''; Write-Host "$($OUList[$ans-1].Loc)" -F 14; Write-Host "$OUPath" -F 11; Add-Computer -domainname $Domain_Name -OUPath $OUPath -ErrorVariable JoinFail } $ErrorActionPreference = "Continue" If ($JoinFail -ge 1) { Write-Host "Well, that didn't work..." -F 14 Write-Host "'$Domain_Name' is in the clipboard..." -F 0 -B 14 $Domain_Name | Set-Clipboard cmd.exe /c sysdp.cpl } Write-Host "$(hostname)" -F 11 Write-Host "$(hostname)" -F 13 Write-Host "$(hostname)" -F 14 $wsh = New-Object -ComObject Wscript.Shell 1..50 | % { $wsh.SendKeys([char]175) } [System.Media.SystemSounds]::Asterisk.Play() Break # Gotta reboot shutdown -r -t 0 #---------#
# Make sure you have successfully, and correctly set the computers hostname
hostname
# This grabs the full name of the domain
$Domain_Name = (Get-DnsClient -InterfaceIndex $((Get-NetConnectionProfile).InterfaceIndex)).ConnectionSpecificSuffix
# it is possible to add creds to this command - but just enter username, and password at the credential prompt (no need to add 'domain\')
Add-Computer -domainname $Domain_Name
Break
# Gotta reboot
shutdown -r -t 0
###########################
Others...
netsh advfirewall set currentprofile state off
netsh advfirewall set domainprofile state off
netsh advfirewall set privateprofile state off
netsh advfirewall set publicprofile state off