324 lines
8.2 KiB
PowerShell
324 lines
8.2 KiB
PowerShell
# Let script run without admin saying yes, and run the script as admin
|
|
# Turns off error responses or turn on or what
|
|
# Here is where to turn all errors on and off
|
|
# Remove comment for Write-Output to create a log file somewhere on the local computer, or where you like
|
|
# $Postup is variable for the path to the logfile
|
|
# Enter your KMS server name
|
|
# Replace YOUR.KMS.SERVER.NAME with your KMS server name
|
|
|
|
|
|
|
|
$ErrorActionPreference = "SilentlyContinue"
|
|
#$ErrorActionPreference = "Inquire"
|
|
#$ErrorActionPreference = "Stop"
|
|
#$ErrorActionPreference = "Continue"
|
|
|
|
|
|
cls
|
|
|
|
# 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"
|
|
|
|
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 = "Black"
|
|
|
|
clear-host
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# We are not running "as Administrator" - so relaunch as administrator
|
|
|
|
|
|
|
|
# Create a new process object that starts PowerShell
|
|
|
|
$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
|
|
|
|
|
|
|
|
# Specify the current script path and name as a parameter
|
|
|
|
$newProcess.Arguments = $myInvocation.MyCommand.Definition;
|
|
|
|
|
|
|
|
# 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Run your code that needs to be elevated below
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Function Activate10
|
|
{
|
|
# Activate Windows 10 - Install KMS Key (Public Key @ Microsoft)
|
|
# slmgr.vbs /ipk NPPR9-FWDCX-D2C8J-H872K-2YT43
|
|
#Write-Output "Windows 10 Activation Commands" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
#Write-Output "slmgr.vbs /ipk NPPR9-FWDCX-D2C8J-H872K-2YT43" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
|
|
# Activate Windows - Point to KMS Server (Public Key @ Microsoft)
|
|
#slmgr.vbs /skms snkms.unistra.fr
|
|
#Write-Output "slmgr.vbs /skms YOUR.KMS.SERVER.NAME" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
|
|
# Activate Windows - Activate Windows
|
|
#slmgr.vbs /ato
|
|
#Write-Output "slmgr.vbs /ato" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
#Write-Output "End of Windows 10 Activation commands" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
#Write-Output `n | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
}
|
|
|
|
|
|
|
|
Function Activate7
|
|
{
|
|
# Activate Windows - Install KMS Key Windows 7 (Public Key @ Microsoft)
|
|
#slmgr.vbs /ipk 33PXH-7Y6KF-2VJC9-XBBR8-HVTHH
|
|
|
|
#Write-Output "Windows 7 Activation Commands" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
#Write-Output "slmgr.vbs /ipk 33PXH-7Y6KF-2VJC9-XBBR8-HVTHH" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
|
|
|
|
# Activate Windows - Point to KMS Server
|
|
#slmgr.vbs /skms snkms.unistra.fr
|
|
|
|
#Write-Output "slmgr.vbs /skms YOUR.KMS.SERVER.NAME" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
|
|
|
|
# Activate Windows - Activate Windows 7
|
|
#slmgr.vbs /ato
|
|
|
|
#Write-Output "slmgr.vbs /ato" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
#Write-Output "End of Windows 7 Activation commands" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
#Write-Output `n | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Function 2013
|
|
{
|
|
# Change to Office 2013 - 32/64bit directory
|
|
CD "c:\Program Files\Microsoft Office\Office15"
|
|
|
|
#Write-Output "Activate Office commands" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
#Write-Output 'CD "c:\Program Files\Microsoft Office\Office15"' | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
|
|
#Activate Office Function
|
|
WonderTwinsPowerActivate
|
|
}
|
|
|
|
|
|
Function 20133264
|
|
{
|
|
# Change to Office 2013 32bit - 64bit OS directory
|
|
CD "c:\Program Files (x86)\Microsoft Office\Office15"
|
|
|
|
#Send Commands to log file
|
|
#Write-Output "Activate Office commands" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
#Write-Output 'CD "c:\Program Files\Microsoft Office\Office15"' | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
|
|
#Activate Office Function
|
|
WonderTwinsPowerActivate
|
|
}
|
|
|
|
Function 2016
|
|
{
|
|
# Change to Office 2016 - 32/64bit directory
|
|
CD "c:\Program Files\Microsoft Office\Office16"
|
|
|
|
#Send Commands to log file
|
|
#Write-Output "Activate Office commands" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
#Write-Output 'CD "c:\Program Files\Microsoft Office\Office16"' | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
|
|
#Activate Office Function
|
|
WonderTwinsPowerActivate
|
|
}
|
|
|
|
Function 20163264
|
|
{
|
|
# Change to Office 2016 32bit - 64bit OS directory
|
|
CD "c:\Program Files (x86)\Microsoft Office\Office16"
|
|
|
|
#Send Commands to log file
|
|
#Write-Output "Activate Office commands" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
#Write-Output 'CD "c:\Program Files (x86)\Microsoft Office\Office16"' | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
|
|
#Activate Office Function
|
|
WonderTwinsPowerActivate
|
|
}
|
|
|
|
|
|
|
|
|
|
Function WonderTwinsPowerActivate
|
|
{
|
|
# Activate Office All Versions - Point to KMS Server
|
|
cscript ospp.vbs /sethst:snkms.unistra.fr
|
|
|
|
#Send Commands to log file
|
|
#Write-Output 'cscript ospp.vbs /sethst:YOUR.KMS.SERVER.NAME' | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
|
|
|
|
# Activate Office 2013 - Activate Office 2013
|
|
cscript ospp.vbs /act
|
|
|
|
#Send Commands to log file
|
|
#Write-Output 'cscript ospp.vbs /act' | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
#Write-Output 'End of Office Activation' | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
#Write-Output `n | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Variables - CHANGE THIS!
|
|
|
|
|
|
|
|
#Remove Comment for PostUp and enter your path for where you want the log file to be
|
|
|
|
#$PostUp = "C:\Path\On\Local\Computer\To\Log\All\Commands.txt"
|
|
|
|
#Office Version Variables (Default Install locations)
|
|
$2013 = "c:\Program Files\Microsoft Office\Office15"
|
|
$20133264 = "c:\Program Files (x86)\Microsoft Office\Office15"
|
|
$2016 = "c:\Program Files\Microsoft Office\Office16"
|
|
$20163264 = "c:\Program Files (x86)\Microsoft Office\Office16"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Script
|
|
|
|
|
|
|
|
#Create Log File - Remove Comment to use log file
|
|
|
|
#Remember to make changes for path and postup variable
|
|
|
|
<#
|
|
|
|
New-Item C:\Path\On\Local\Computer\To\Log\All\Commands.txt -type file -force
|
|
Get-date | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
#Check for Windows 7 or Windows 10
|
|
|
|
If (!((Get-WmiObject -class Win32_OperatingSystem -Property * | Select-Object -ExpandProperty Caption) -eq "Microsoft Windows 10 Enterprise"))
|
|
|
|
{
|
|
#Write-Output "Operating System:" "(Get-WmiObject -class Win32_OperatingSystem -Property * | Select-Object -ExpandProperty Caption)" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
#Write-Output `n | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
#Activate7
|
|
}
|
|
|
|
Else
|
|
{
|
|
#write-Host "Windows 10 - Hip Hop Hooray! Hooooo Haaaaay Hoooooo"
|
|
#Write-Output "Operating System:" "(Get-WmiObject -class Win32_OperatingSystem -Property * | Select-Object -ExpandProperty Caption)" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
#Write-Output `n | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
#Activate10
|
|
}
|
|
|
|
|
|
|
|
|
|
#Check Office Versions
|
|
|
|
#Check for office 2013 32bit
|
|
If (Test-Path $2013)
|
|
{
|
|
#Write-Output "Office: 2013-32bit" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
2013
|
|
}
|
|
|
|
#check for office 2013 64bit
|
|
ElseIf (Test-Path $20133264)
|
|
{
|
|
#Write-Output "Office: 2013-64bit" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
20133264
|
|
}
|
|
|
|
#check for office 2016 32bit
|
|
ElseIf (Test-Path $2016)
|
|
{
|
|
#Write-Output "Office: 2016-32bit" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
2016
|
|
}
|
|
|
|
#check for office 2016 64bit
|
|
ElseIf (Test-Path $20163264)
|
|
{
|
|
#Write-Output "Office: 2016-64bit" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
20163264
|
|
}
|
|
|
|
Else
|
|
{
|
|
#Write-Output "No Office Installed" | out-file $PostUp -encoding ascii -Append -Noclobber
|
|
$null
|
|
}
|
|
|
|
ExitError: Resource has been moved or is unavailable. Please contact the forum admin. |