Page Overview
This page provides a sample script required to silently install and activate the Josys browser extension on Windows devices using Microsoft Intune.
This script is intended for those who fall under Case A (each user has administrator privileges on their device, and their UPN is the same as their email address in Josys) in How to Silently Install and Activate the Extension on Windows Devices Using Intune (2/2).
Target Audience
Those responsible for planning or executing the bulk deployment of the Josys browser extension.
About the Browser Extension
Please refer to the following pages first for information regarding the browser extension.
1. About the Browser Extension
2. How to Use the Browser Extension
Script
Save the following script to run it in the user context.
- Copy the script below and paste it into a text editor such as Notepad.
- Replace YOUR_ORGANIZATION_KEY on line 3 with your company's Organization Key, which can be found in Josys.
- Save the file with the name "josys-extension-config.ps1".
- Verify that the file type is "Windows PowerShell script".
- Return to How to Silently Install and Activate the Extension on Windows Devices Using Intune (2/2) - 2. Apply the script to target devices to proceed with the setup.
# --- Configuration Section ---
# Please replace with your company's Organization Key
$organizationKey = "YOUR_ORGANIZATION_KEY" # Replace with your actual Organization Key
# --- Script Body ---
# Definition of registry paths (Array)
$registryPaths = @(
# Google Chrome
"HKCU:\Software\Policies\Google\Chrome\3rdparty\extensions\moaklgcgokbgplldonjkoochhlefkbjf\policy",
# Microsoft Edge
"HKCU:\Software\Policies\Microsoft\Edge\3rdparty\extensions\hjifncajikcdkhlofdjjlhcjoennmdfc\policy"
)
# Get UserPrincipalName (Run only once)
$userPrincipalName = $null
try {
# Execute 'whoami /upn' command to get UserPrincipalName and trim whitespace
$userPrincipalName = (whoami /upn).Trim()
if ([string]::IsNullOrWhiteSpace($userPrincipalName)) {
Write-Warning "Could not retrieve UserPrincipalName. 'UserEmail' will not be set."
# Consider exiting with code 1 here if UPN is mandatory.
} else {
Write-Host "Retrieved UserPrincipalName: $userPrincipalName"
}
} catch {
# E.g., if the 'whoami /upn' command itself fails
Write-Warning "Failed to retrieve UserPrincipalName. 'UserEmail' will not be set. Error: $($_.Exception.Message)"
# Similarly, consider exiting with code 1 here.
}
# Function to create registry keys and write values
function Set-ExtensionPolicyRegistry {
param(
[Parameter(Mandatory=$true)]
[string]$Path,
[Parameter(Mandatory=$true)]
[string]$OrgKey,
[Parameter(Mandatory=$false)] # Optional, considering UPN might not be available
[string]$Email
)
Write-Host "Processing registry path: $Path"
$operationSuccess = $true # Success flag for processing this specific path
# Check and create parent path
$parentPath = Split-Path -Path $Path -Parent
if (!(Test-Path $parentPath)) {
try {
New-Item -Path $parentPath -Force -ItemType Directory -ErrorAction Stop | Out-Null
Write-Host " Created parent registry key structure: $parentPath"
} catch {
Write-Error " Failed to create parent registry key: $parentPath. Error: $($_.Exception.Message)"
$operationSuccess = $false
}
}
# Check and create the policy key (Attempt only if parent key creation was successful)
if ($operationSuccess -and !(Test-Path $Path)) {
try {
New-Item -Path $Path -Force -ItemType Directory -ErrorAction Stop | Out-Null
Write-Host " Created registry key: $Path"
} catch {
Write-Error " Failed to create registry key: $Path. Error: $($_.Exception.Message)"
$operationSuccess = $false
}
}
# 1. Write OrganizationKey (Attempt only if key creation was successful)
if ($operationSuccess) {
try {
Set-ItemProperty -Path $Path -Name "OrganizationKey" -Value $OrgKey -Type String -Force -ErrorAction Stop
Write-Host " Successfully set 'OrganizationKey' to '$OrgKey'"
} catch {
Write-Error " Failed to set 'OrganizationKey'. Error: $($_.Exception.Message)"
$operationSuccess = $false
}
}
# 2. Write UserEmail (Attempt only if UPN was retrieved and key creation was successful)
if ($operationSuccess -and (-not [string]::IsNullOrWhiteSpace($Email))) {
try {
Set-ItemProperty -Path $Path -Name "UserEmail" -Value $Email -Type String -Force -ErrorAction Stop
Write-Host " Successfully set 'UserEmail' to '$Email'"
} catch {
Write-Error " Failed to set 'UserEmail'. Error: $($_.Exception.Message)"
$operationSuccess = $false
}
} elseif ($operationSuccess -and [string]::IsNullOrWhiteSpace($Email)) {
Write-Host " Skipping 'UserEmail' setting because UserPrincipalName was not available."
}
# Return the result of processing for this path
return $operationSuccess
}
# --- Main Processing ---
$overallSuccess = $true # Overall success flag
Write-Host "Starting registry setting process..."
# Execute the function for each registry path
foreach ($regPath in $registryPaths) {
# Execute the function and set the overall flag to false if the result is false
if (-not (Set-ExtensionPolicyRegistry -Path $regPath -OrgKey $organizationKey -Email $userPrincipalName)) {
$overallSuccess = $false
Write-Warning "An error occurred while processing path '$regPath'."
# Processing continues to the next path even if an error occurs
} else {
Write-Host "Processing for path '$regPath' completed successfully."
}
Write-Host "---" # Separator for each path
}
# Set the exit code based on the final result
if ($overallSuccess) {
Write-Host "Processing completed successfully for all specified registry paths."
exit 0
} else {
Write-Error "Script completed with one or more errors. Please check the logs above."
exit 1
}