mirror of
https://github.com/zebrajr/sysadmin.git
synced 2025-12-06 00:20:23 +01:00
add initial windows activator script (#2)
This commit is contained in:
parent
bbc7a5a811
commit
680c3af9a8
24
Windows/Windows Activator/README.md
Normal file
24
Windows/Windows Activator/README.md
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# Windows Activation Script
|
||||
|
||||
Read lists of targets and an activation key from json files, then for each target change the key and re-enable Windows activation.
|
||||
|
||||
## Note
|
||||
|
||||
Check the json files before running the script. Make sure you have a valid key for the targets you want to apply the script to.
|
||||
|
||||
### Error handling
|
||||
|
||||
At the beginning, the script requests the credentials to be used. If an error occurs (command invalid, not enough permissions, WinRM not enabled on the target computer, etc.), the script aborts to avoid locking out a user due to too many failed attempts.
|
||||
|
||||
### json file example
|
||||
|
||||
```
|
||||
{
|
||||
|
||||
"windows_key" : [ 12345-12345-12345-12345 ],
|
||||
"targets" : [
|
||||
"pc1.domain.tld",
|
||||
"pc2.domain.tld",
|
||||
]
|
||||
}
|
||||
```
|
||||
6
Windows/Windows Activator/jobs/datacenter-01.json
Normal file
6
Windows/Windows Activator/jobs/datacenter-01.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"windows_key": "12345-12345-12345-12345-12345",
|
||||
"targets": [
|
||||
"pc01.domain.tld"
|
||||
]
|
||||
}
|
||||
8
Windows/Windows Activator/jobs/standard-01.json
Normal file
8
Windows/Windows Activator/jobs/standard-01.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"windows_key": "12345-12345-12345-12345-12345",
|
||||
"targets": [
|
||||
"pc01.domain.tld",
|
||||
"pc02.domain.tld",
|
||||
"pc03.domain.tld"
|
||||
]
|
||||
}
|
||||
36
Windows/Windows Activator/windows_activator.ps1
Normal file
36
Windows/Windows Activator/windows_activator.ps1
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
cls
|
||||
# Load JSON Configuration
|
||||
$jsonConfig = Get-Content -Path .\jobs\*.json -Raw | ConvertFrom-Json
|
||||
|
||||
$credential = Get-Credential
|
||||
|
||||
foreach ($input_file in $jsonConfig){
|
||||
foreach ($target in $input_file.targets) {
|
||||
Write-Output "Connecting to $target..."
|
||||
|
||||
# Initialize PowerShell Session
|
||||
try {
|
||||
$session = New-PSSession -ComputerName $target -Credential $credential
|
||||
} catch {
|
||||
Write-Output "Failed to establish a connection to $target. Check if the server is running and accessible. Error: $_"
|
||||
exit
|
||||
}
|
||||
|
||||
# Execute command and capture the output
|
||||
try {
|
||||
$output = Invoke-Command -Session $session -ScriptBlock {
|
||||
param($new_key)
|
||||
slmgr -ipk $new_key
|
||||
sleep 5
|
||||
slmgr -ato
|
||||
sleep 5
|
||||
} -ArgumentList $input_file.windows_key
|
||||
} catch {
|
||||
Write-Output "Failed to execute the command on $target. Error: $_"
|
||||
exit
|
||||
} finally {
|
||||
# Close the session
|
||||
Remove-PSSession -Session $session
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user