Overview
This page provides a sample script required to silently install and activate the Josys browser extension on Windows devices using Microsoft Intune.
This guide is intended for those who fall under Case E (users do not have administrator privileges on their devices, and their UPN differs from their email address in Josys) in How to Silently Install and Activate Extensions on Windows Devices Using Intune (2/2).
Target Audience
Personnel responsible for planning and implementing the bulk deployment of the Josys browser extension.
About Browser Extensions
Please read the following pages first for information regarding browser extensions.
1. About Browser Extensions
2. How to Use Browser Extensions
Script
Save the script below to run it in the system 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 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 Extensions on Windows Devices Using Intune (2/2) - 2. Apply the script to target devices to proceed with the setup.
# --- Configuration Settings ---
# Set the OrganizationKey value here (Mandatory)
$organizationKey = "YOUR_ORGANIZATION_KEY" # Replace with your actual key
# Relative registry key paths under HKCU for the specific extensions
$chromeRelativePath = "Software\Policies\Google\Chrome\3rdparty\extensions\moaklgcgokbgplldonjkoochhlefkbjf\policy"
$edgeRelativePath = "SOFTWARE\Policies\Microsoft\Edge\3rdparty\extensions\hjifncajikcdkhlofdjjlhcjoennmdfc\policy"
# --- End of Configuration Settings ---
# --- Script Body ---
Write-Host "Script started for Chrome and Edge extension policies. OrganizationKey: '${organizationKey}'"
# Basic check if OrganizationKey is set
if ([string]::IsNullOrWhiteSpace($organizationKey) -or $organizationKey -eq "YOUR_ORGANIZATION_KEY_HERE") {
Write-Error "Please set a valid value for the `${organizationKey}` variable at the top of the script."
exit 1
}
# Function to get the active user session username
function Get-ActiveUserSessionInfo {
try {
$queryOutput = query user
$activeSessionLine = $queryOutput | Select-String -Pattern '^\s*>' | Select-Object -First 1
if ($activeSessionLine) {
$sessionInfo = $activeSessionLine.Line -split '\s+' | Where-Object {$_}
if ($sessionInfo.Count -ge 2) {
$userName = $sessionInfo[1]
Write-Host "Detected active user '${userName}' using query user."
return $userName
} else {
Write-Warning "Unexpected output format from query user. Line: $($activeSessionLine.Line)"
}
} else {
Write-Warning "Could not find an active session using query user."
}
} catch {
Write-Warning "Failed to execute query user command: $($_.Exception.Message)"
}
try {
Write-Host "Fallback: Attempting to get username from Win32_ComputerSystem..."
$computerSystem = Get-CimInstance -ClassName Win32_ComputerSystem
if ($computerSystem.UserName) {
Write-Host "Retrieved username '$($computerSystem.UserName)' from Win32_ComputerSystem."
if ($computerSystem.UserName -like "*\*" -or $computerSystem.UserName -like "*@*") {
return $computerSystem.UserName
} else {
Write-Warning "Username from Win32_ComputerSystem ('$($computerSystem.UserName)') is not in the expected format (Domain\User or user@domain)."
}
} else {
Write-Warning "Could not retrieve username from Win32_ComputerSystem."
}
} catch {
Write-Error "Error retrieving username from Win32_ComputerSystem: $($_.Exception.Message)"
}
Write-Error "Could not determine the active user session username."
return $null
}
# Get the active username
$activeUserName = Get-ActiveUserSessionInfo
if (-not $activeUserName) {
Write-Error "No target user found. Exiting script."
exit 1
}
# Get SID and the username part for the DeviceIdentity value
$deviceIdentityValue = $null
$userSid = $null
try {
$ntAccount = New-Object System.Security.Principal.NTAccount($activeUserName)
$userSid = $ntAccount.Translate([System.Security.Principal.SecurityIdentifier]).Value
Write-Host "Retrieved SID for user '${activeUserName}': ${userSid}"
$localUsernamePart = $null
if ($activeUserName -like '*@*') {
$potentialLocalPart = $activeUserName.Split('@')[0]
if ($potentialLocalPart -like '*\*') {
$localUsernamePart = $potentialLocalPart.Split('\')[1]
} else {
$localUsernamePart = $potentialLocalPart
}
} elseif ($activeUserName -like '*\*') {
$localUsernamePart = $activeUserName.Split('\')[1]
} else {
Write-Warning "Username '${activeUserName}' does not contain '@' or '\'. Using the full username."
$localUsernamePart = $activeUserName
}
if ($localUsernamePart) {
$deviceIdentityValue = $localUsernamePart
Write-Host "Determined value for DeviceIdentity: ${deviceIdentityValue}"
} else {
Write-Error "Failed to determine local username part for user '${activeUserName}'."
exit 1
}
} catch {
Write-Error "Failed to retrieve SID or determine username part for user '${activeUserName}': $($_.Exception.Message)"
exit 1
}
# Proceed with registry operations only if SID and deviceIdentityValue were obtained
if ($userSid -and $deviceIdentityValue) {
# --- Process Chrome Path ---
$chromeRegistryPath = "Registry::HKEY_USERS\${userSid}\${chromeRelativePath}"
Write-Host "--- Processing Chrome Path: ${chromeRegistryPath} ---"
try {
if (-not (Test-Path -Path $chromeRegistryPath)) {
Write-Host "Chrome registry key does not exist. Creating..."
New-Item -Path $chromeRegistryPath -Force -ErrorAction Stop | Out-Null
Write-Host "Successfully created Chrome registry key '${chromeRegistryPath}'."
} else {
Write-Host "Chrome registry key already exists."
}
$CurrentErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = "SilentlyContinue"
New-ItemProperty -Path $chromeRegistryPath -Name "DeviceIdentity" -Value $deviceIdentityValue -PropertyType String -Force
if ($?) { Write-Host "Successfully set Chrome 'DeviceIdentity' to '${deviceIdentityValue}'." }
else { Write-Error "Failed to set Chrome 'DeviceIdentity'. Last Error: $($error[0].Exception.Message)" }
New-ItemProperty -Path $chromeRegistryPath -Name "OrganizationKey" -Value $organizationKey -PropertyType String -Force
if ($?) { Write-Host "Successfully set Chrome 'OrganizationKey' to '${organizationKey}'." }
else { Write-Error "Failed to set Chrome 'OrganizationKey'. Last Error: $($error[0].Exception.Message)" }
$ErrorActionPreference = $CurrentErrorActionPreference
} catch {
Write-Error "Failed processing Chrome registry path '${chromeRegistryPath}': $($_.Exception.Message)"
}
Write-Host "--- Finished Processing Chrome Path ---"
# --- Process Edge Path ---
$edgeRegistryPath = "Registry::HKEY_USERS\${userSid}\${edgeRelativePath}"
Write-Host "--- Processing Edge Path: ${edgeRegistryPath} ---"
try {
if (-not (Test-Path -Path $edgeRegistryPath)) {
Write-Host "Edge registry key does not exist. Creating..."
New-Item -Path $edgeRegistryPath -Force -ErrorAction Stop | Out-Null
Write-Host "Successfully created Edge registry key '${edgeRegistryPath}'."
} else {
Write-Host "Edge registry key already exists."
}
$CurrentErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = "SilentlyContinue"
New-ItemProperty -Path $edgeRegistryPath -Name "DeviceIdentity" -Value $deviceIdentityValue -PropertyType String -Force
if ($?) { Write-Host "Successfully set Edge 'DeviceIdentity' to '${deviceIdentityValue}'." }
else { Write-Error "Failed to set Edge 'DeviceIdentity'. Last Error: $($error[0].Exception.Message)" }
New-ItemProperty -Path $edgeRegistryPath -Name "OrganizationKey" -Value $organizationKey -PropertyType String -Force
if ($?) { Write-Host "Successfully set Edge 'OrganizationKey' to '${organizationKey}'." }
else { Write-Error "Failed to set Edge 'OrganizationKey'. Last Error: $($error[0].Exception.Message)" }
$ErrorActionPreference = $CurrentErrorActionPreference
} catch {
Write-Error "Failed processing Edge registry path '${edgeRegistryPath}': $($_.Exception.Message)"
}
Write-Host "--- Finished Processing Edge Path ---"
} else {
Write-Error "Cannot perform registry operations because SID or DeviceIdentity value could not be obtained."
exit 1
}
Write-Host "Script execution finished."