You want to identify and detect individual users when they log into a device (domain) using a shared ID instead of an individual ID
(Users must log into their browser using the same email address registered in Josys, such as an organizational Google or Microsoft account. Otherwise, detection is not possible.)
Script Overview
Runs with system privileges. Writes the Josys Organization ID to the HKLM registry for Chrome and Edge.
Logs are output to the location specified by the $logFilePath variable (in the sample, C:\Windows\Temp\Set-BrowserExtensionPolicy_Error.log) only if an error occurs.
Required Changes Before Use
Change YOUR_ORGANIZATION_KEY_HERE in $organizationKey = "YOUR_ORGANIZATION_KEY_HERE" to your actual Organization ID.
$logFilePath = "C:\Windows\Temp\Set-BrowserExtensionPolicy_Error.log" Change the folder path where logs are output as needed.
How to Use
Copy the script below, paste it into Notepad or a similar text editor, and select "Save As". Set the file extension to .ps1 and select UTF-8 with BOM as the character encoding.
Afterward, please refer to the software distribution method in SKYSEA Client View to continue the setup.
<#
.SYNOPSIS
Writes specified policy values to the HKLM registry hive for both Chrome and Edge extensions.
This applies to all users on the device.
ERROR LOGGING ENABLED: Writes a log file only if an error occurs.
.DESCRIPTION
Modified version: Targets HKLM instead of HKU, and removed DeviceIdentity logic.
#>
# --- Configuration Settings ---
# Set the OrganizationKey value here (Mandatory)
$organizationKey = "YOUR_ORGANIZATION_KEY_HERE" # Replace with your actual key
# HKLM Registry key paths for the specific extensions
# Note: Changed from relative paths to full HKLM paths
$chromePath = "Registry::HKEY_LOCAL_MACHINE\Software\Policies\Google\Chrome\3rdparty\extensions\moaklgcgokbgplldonjkoochhlefkbjf\policy"
$edgePath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Edge\3rdparty\extensions\hjifncajikcdkhlofdjjlhcjoennmdfc\policy"
# Log settings
$logFilePath = "C:\Windows\Temp\Set-BrowserExtensionPolicy_Error.log" # Path to the log file output in case of an error
# --- End of Configuration Settings ---
# --- Logging Setup ---
# List to accumulate messages in memory
$logBuffer = New-Object System.Collections.Generic.List[string]
# Flag to determine if an error occurred
$errorOccurred = $false
# Logging function (records to buffer instead of screen output)
function Add-Log {
param (
[string]$Message,
[string]$Type = "INFO"
)
$timestamp = Get-Date -Format "yyyy/MM/dd HH:mm:ss"
$logEntry = "[$timestamp] [$Type] $Message"
$script:logBuffer.Add($logEntry)
# Set flag if it is an error type
if ($Type -eq "ERROR") {
$script:errorOccurred = $true
}
}
# --- Script Body ---
Add-Log "Script started. Processing HKLM policies for Chrome and Edge extensions."
# Basic check if OrganizationKey is set
if ([string]::IsNullOrWhiteSpace($organizationKey) -or $organizationKey -eq "YOUR_ORGANIZATION_KEY_HERE") {
Add-Log "Please set a valid value for the `$organizationKey variable at the top of the script." -Type "ERROR"
# Output log and exit since an error occurred
$logBuffer | Out-File -FilePath $logFilePath -Encoding UTF8
exit 1
}
# --- Process Chrome Path (HKLM) ---
Add-Log "--- Processing Chrome Path (HKLM) ---"
try {
# Ensure the Chrome registry key exists, create if not
if (-not (Test-Path -Path $chromePath)) {
Add-Log "Chrome registry key does not exist. Creating..."
New-Item -Path $chromePath -Force -ErrorAction Stop | Out-Null
}
# Set OrganizationKey for Chrome
New-ItemProperty -Path $chromePath -Name "OrganizationKey" -Value $organizationKey -PropertyType String -Force -ErrorAction SilentlyContinue
if ($?) { Add-Log "Successfully set Chrome 'OrganizationKey'." }
else { Add-Log "Failed to set Chrome 'OrganizationKey'. Last Error: $($error[0].Exception.Message)" -Type "ERROR" }
} catch {
Add-Log "An error occurred while processing Chrome registry: $($_.Exception.Message)" -Type "ERROR"
}
# --- Process Edge Path (HKLM) ---
Add-Log "--- Processing Edge Path (HKLM) ---"
try {
# Ensure the Edge registry key exists, create if not
if (-not (Test-Path -Path $edgePath)) {
Add-Log "Edge registry key does not exist. Creating..."
New-Item -Path $edgePath -Force -ErrorAction Stop | Out-Null
}
# Set OrganizationKey for Edge
New-ItemProperty -Path $edgePath -Name "OrganizationKey" -Value $organizationKey -PropertyType String -Force -ErrorAction SilentlyContinue
if ($?) { Add-Log "Successfully set Edge 'OrganizationKey'." }
else { Add-Log "Failed to set Edge 'OrganizationKey'. Last Error: $($error[0].Exception.Message)" -Type "ERROR" }
} catch {
Add-Log "An error occurred while processing Edge registry: $($_.Exception.Message)" -Type "ERROR"
}
Add-Log "------------------------------------------------------------"
Add-Log "Script execution finished."
# --- Final Check: Save Log if Error Occurred ---
if ($errorOccurred) {
try {
$logBuffer | Out-File -FilePath $logFilePath -Encoding UTF8 -Force
} catch {
# Last resort if writing the log file itself fails (usually no log)
}
}