##################### # Get Admin Rights ## #################### # Get the ID and security principal of the current user account $myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent() $myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID) # Get the security principal for the Administrator role $adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator # Check to see if we are currently running "as Administrator" and not 64 bit if ($myWindowsPrincipal.IsInRole($adminRole)) { # We are running "as Administrator" - so change the title and background color to indicate this $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)" #$Host.UI.RawUI.BackgroundColor = "DarkBlue" clear-host } else { # We are not running "as Administrator" - so relaunch as administrator # Create a new process object that starts PowerShell x86 # Check to see if we are currently running x86 arch # the LHO script can only run with 32 bit powershell if (([environment]::Is64BitProcess)) { # run the 32 bit powershell exe when on a 64 bit computer $newProcess = new-object System.Diagnostics.ProcessStartInfo "C:\Windows\SysWoW64\WindowsPowerShell\v1.0\powershell.exe"; } else { # run the normal 32 bit powershell exe when on 32 bit computer $newProcess = new-object System.Diagnostics.ProcessStartInfo "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe"; } # Specify the current script path and name as a parameter with added scope and support for scripts with spaces in it's path $newProcess.Arguments = "& '" + $script:MyInvocation.MyCommand.Path + "'" # Indicate that the process should be elevated $newProcess.Verb = "runas"; # Start the new process [System.Diagnostics.Process]::Start($newProcess); # Exit from the current, unelevated, process exit } # Windows OS # Set KMS Host c:\Windows\System32\cscript.exe /nologo c:\Windows\System32\slmgr.vbs /skms gauntkms.home.johnhgaunt.com # https://stackoverflow.com/questions/48592120/how-do-i-find-out-from-powershell-if-i-am-on-a-server-or-workstation # $osInfo = Get-WmiObject -Class Win32_OperatingSystem # $osInfo.ProductType # ProductType # Data type: uint32 # Access type: Read-only # Additional system information. # Work Station (1) # Domain Controller (2) # Server (3) $osType = Get-WmiObject -Class Win32_OperatingSystem $osInfo = Get-ComputerInfo if ($osType.ProductType -eq 1) { if ($osInfo.WindowsProductName -match "Windows 10 Enterprise LTSC 20(19|21|24)") { # Windows 10/11 2019/2021/2024 LTSC c:\Windows\System32\cscript.exe /nologo c:\Windows\System32\slmgr.vbs /ipk M7XTQ-FN8P6-TTKYV-9D4CC-J462D }elseif ($osInfo.WindowsProductName -match "Windows 10 IoT Enterprise LTSC 20(19|21|24)") { # Windows 10/11 IoT 2019/2021/2024 LTSC c:\Windows\System32\cscript.exe /nologo c:\Windows\System32\slmgr.vbs /ipk KBN8V-HFGQ4-MGXVD-347P6-PDQGT } elseif ($osInfo.WindowsProductName -eq "Windows 10 Enterprise LTSB 2016") { # Windows 10 2016 LTSB c:\Windows\System32\cscript.exe /nologo c:\Windows\System32\slmgr.vbs /ipk DCPHK-NFMTC-H88MJ-PFHPY-QJ4BJ } elseif ($osInfo.WindowsProductName -match "Windows 1[0-1] Enterprise") { # Windows 10/11 Enterprise c:\Windows\System32\cscript.exe /nologo c:\Windows\System32\slmgr.vbs /ipk NPPR9-FWDCX-D2C8J-H872K-2YT43 } else { # Windows 10/11 Pro c:\Windows\System32\cscript.exe /nologo c:\Windows\System32\slmgr.vbs /ipk W269N-WFGWX-YVC9B-4J6C9-T83GX } } else { if ($osInfo.WindowsProductName -eq "Windows Server 2025 DataCenter") { # windows Server 2025 Datacenter c:\Windows\System32\cscript.exe /nologo c:\Windows\System32\slmgr.vbs /ipk D764K-2NDRG-47T6Q-P8T8W-YP6DF } elseif ($osInfo.WindowsProductName -eq "Windows Server 2022 DataCenter") { # windows Server 2022 Datacenter c:\Windows\System32\cscript.exe /nologo c:\Windows\System32\slmgr.vbs /ipk WX4NM-KYWYW-QJJR4-XV3QB-6VM33 } elseif ($osInfo.WindowsProductName -eq "Windows Server 2019 DataCenter") { # windows Server 2019 Datacenter c:\Windows\System32\cscript.exe /nologo c:\Windows\System32\slmgr.vbs /ipk WMDGN-G9PQG-XVVXX-R3X43-63DFG } elseif ($osInfo.WindowsProductName -eq "Windows Server 2016 DataCenter") { # Windows Server 2016 Datacenter c:\Windows\System32\cscript.exe /nologo c:\Windows\System32\slmgr.vbs /ipk CB7KF-BWN84-R7R2Y-793K2-8XDDG } else { $message = "Your server version is not supported or could not be detected corrected. Version: $($osInfo.WindowsProductName)" write-error $message exit } } # Activate it c:\Windows\System32\cscript.exe /nologo c:\Windows\System32\slmgr.vbs /ato # lets check for an office install if (test-path "C:\Program Files\Microsoft Office\Office16\ospp.vbs") { $officePath = "C:\Program Files\Microsoft Office\Office16\ospp.vbs" } elseif (test-path "C:\Program Files (x86)\Microsoft Office\Office16\ospp.vbs") { $officePath = "C:\Program Files (x86)\Microsoft Office\Office16\ospp.vbs" } if ($null -ne $officePath) { # Office 2024 LTSC c:\Windows\System32\cscript.exe /nologo "$officePath" /inpkey:XJ2XN-FW8RK-P4HMP-DKDBV-GCVGB # Project Pro 2024 LTSC c:\Windows\System32\cscript.exe /nologo "$officePath" /inpkey:FQQ23-N4YCY-73HQ3-FM9WC-76HF4 # Visio Pro 2024 LTSC c:\Windows\System32\cscript.exe /nologo "$officePath" /inpkey:B7TN8-FJ8V3-7QYCP-HQPMV-YY89G # Set KMS Host c:\Windows\System32\cscript.exe /nologo "$officePath" /sethst:gauntkms.home.johnhgaunt.com # Activate it c:\Windows\System32\cscript.exe /nologo "$officePath" /act } pause # https://learn.microsoft.com/en-us/office/volume-license-activation/gvlks # Office 2013: YC7DK-G2NP3-2QQC3-J6H88-GVGXT # Office 2016: # Office 2019: NMMKJ-6RK4F-KMJVX-8D9MJ-6MWKP # Office 2021 LTSC: FXYTK-NJJ8C-GB6DW-3DYQT-6F7TH # Project 2021 LTSC: FTNWT-C6WBT-8HMGF-K9PRX-QV9H8 # Visio 2021 LTSC: KNH8D-FGHT4-T8RK3-CTDYJ-K2HT4 # Office 2024 LTSC: XJ2XN-FW8RK-P4HMP-DKDBV-GCVGB # Project 2024 LTSC: FQQ23-N4YCY-73HQ3-FM9WC-76HF4 # Visio 2024 LTSC: B7TN8-FJ8V3-7QYCP-HQPMV-YY89G