Skip to content

Commit 82defb9

Browse files
Add Jamf Trust Scripts for silent activation for inc-337 (#25)
This script creates an init.json file in the JamfTrust Global folder and restarts the JamfTrust service for silent activation. It must be run with administrator rights and contains hardcoded activation parameters.
1 parent 9ab92bb commit 82defb9

1 file changed

Lines changed: 101 additions & 0 deletions

File tree

support/Jamf Trust Scripts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<#
2+
.SYNOPSIS
3+
Creates an init.json file in the JamfTrust Global folder and restarts the service to trigger silent activation.
4+
5+
.DESCRIPTION
6+
Writes an init.json file into C:\ProgramData\JamfTrust\Global (the location the
7+
service reads via IConfigurationProvider.GetJamfTrustGlobalDirectory()). On startup
8+
the ActivationActor pops these registration parameters and performs silent activation,
9+
then deletes the file. Once the file is created, the JamfTrust service is restarted.
10+
11+
Must be executed with administrator rights since the JamfTrust folder is protected.
12+
13+
This variant takes no parameters; the activation values are hardcoded below so the
14+
script can be deployed as-is (e.g. an Intune platform script or a Win32 PowerShell
15+
script installer type, neither of which accepts command-line arguments).
16+
17+
.NOTES
18+
Error codes are based on
19+
https://learn.microsoft.com/en-gb/windows/win32/debug/system-error-codes--0-499-
20+
Error code 0 - ERROR_SUCCESS
21+
Error code 352 - ERROR_FAIL_RESTART
22+
#>
23+
24+
<# Hardcoded activation parameters #>
25+
$SecretKey = "" #Taken from secure cloud (radar) deployment screen under specific activation link
26+
$ApiKey = "" #Taken from secure cloud (radar) deployment screen under specific activation link
27+
$ActivationProfileLink = "" #Taken from secure cloud (radar) example https://e.wandera.com/test
28+
$NoPii = $false #leave as is
29+
30+
$global_folder = "C:\ProgramData\JamfTrust\Global"
31+
$service_name = "JamfTrust"
32+
33+
<# init.json content #>
34+
function New-InitJson {
35+
param(
36+
[string]$GlobalFolder,
37+
[string]$SecretKey,
38+
[string]$ApiKey,
39+
[string]$ActivationProfileLink,
40+
[bool]$NoPii
41+
)
42+
43+
# Fields and casing mirror the installer's RegistrationParameters DTO
44+
# (JamfTrust.Client.Windows.Installer/Models/RegistrationParameter.cs),
45+
# which is serialized with default Newtonsoft (PascalCase) into init.json.
46+
$init_json = [ordered]@{
47+
SecretKey = $SecretKey
48+
ApiKey = $ApiKey
49+
ActivationProfileLink = $ActivationProfileLink
50+
NoPii = $NoPii
51+
}
52+
53+
$init_json_file = [pscustomobject]$init_json
54+
55+
if (-not (Test-Path $GlobalFolder)) {
56+
New-Item -ItemType Directory -Path $GlobalFolder | Out-Null
57+
}
58+
59+
$init_json_path = Join-Path $GlobalFolder "init.json"
60+
61+
Write-Host "Creating init.json at $init_json_path"
62+
$init_json_file | ConvertTo-Json -Depth 100 | Out-File -FilePath $init_json_path -Encoding utf8
63+
}
64+
65+
<# Restart the JamfTrust service #>
66+
function Restart-JamfTrust {
67+
Write-Host "Restarting JamfTrust UI and Service"
68+
69+
net stop JamfTrust
70+
taskkill /F /IM JamfTrust.Client.Windows.UI.exe
71+
72+
net start JamfTrust
73+
74+
$limit = (Get-Date).AddMinutes(1)
75+
76+
while ((Get-Date) -le $limit) {
77+
$service_status = Get-Service -Name $service_name
78+
if ($service_status.Status -eq 'Running') {
79+
Write-Host "Service is running"
80+
return
81+
}
82+
83+
Start-Sleep -Seconds 1
84+
}
85+
86+
Write-Error -Message "Script failed to restart the service" -Category InvalidOperation -ErrorId 352
87+
exit(352)
88+
}
89+
90+
<#----------------------------------------#>
91+
92+
New-InitJson -GlobalFolder $global_folder `
93+
-SecretKey $SecretKey `
94+
-ApiKey $ApiKey `
95+
-ActivationProfileLink $ActivationProfileLink `
96+
-NoPii $NoPii
97+
98+
Restart-JamfTrust
99+
100+
Write-Host "Done. init.json created in Global folder and service restarted."
101+
exit(0)

0 commit comments

Comments
 (0)