- Please configure the activation settings first.
- Name the following script and save it as a ps1 file.
(If saving with Notepad or similar, UTF-8 with BOM is recommended.)- This script configures settings for both Chrome and Edge browsers.
- This script leaves a log file at the path specified within the script only if an error occurs.
You can edit the path as needed.
<# .SYNOPSIS Browser Extension Force-Install Configuration Script .DESCRIPTION Adds entries to the ExtensionInstallForcelist for Google Chrome and Microsoft Edge. Supports execution with SYSTEM privileges, such as via SKYSEA or AD startup scripts. .NOTES Describe the extension information you want to register in $ExtensionList in the configuration area. #> #Requires -Version 5.1 #Requires -RunAsAdministrator # ----------------------------------------------------------- # [Configuration Area] Extensions to install and log settings # ----------------------------------------------------------- # Path to the log file $LogFilePath = "C:\Windows\Temp\BrowserExtensionInstall.log" # List of target browsers and extension settings # Format: "ExtensionID;UpdateURL" $TargetExtensions = @( @{ Name = "Google Chrome" RegPath = "HKLM:\SOFTWARE\Policies\Google\Chrome\ExtensionInstallForcelist" # Example below: Josys ID Value = "moaklgcgokbgplldonjkoochhlefkbjf;https://clients2.google.com/service/update2/crx" }, @{ Name = "Microsoft Edge" RegPath = "HKLM:\SOFTWARE\Policies\Microsoft\Edge\ExtensionInstallForcelist" # Example below: Josys ID Value = "hjifncajikcdkhlofdjjlhcjoennmdfc;https://edge.microsoft.com/extensionwebstorebase/v1/crx" } ) # ----------------------------------------------------------- # Initialization # ----------------------------------------------------------- $script:HasError = $false try { Start-Transcript -Path $LogFilePath -Append -ErrorAction SilentlyContinue } catch { # Continue execution even if starting the log fails } Write-Host "--- Process Started: $(Get-Date) ---" Write-Host "Execution User: $env:USERNAME" # ----------------------------------------------------------- # Function Definition # ----------------------------------------------------------- function Set-BrowserExtension { param ( [string]$BrowserName, [string]$RegistryPath, [string]$ExtensionData ) Write-Host "`nChecking settings for [$BrowserName]..." try { # 1. Check and create path if (-not (Test-Path $RegistryPath)) { Write-Host " [INFO] Registry key does not exist. Creating: $RegistryPath" New-Item -Path $RegistryPath -Force -ErrorAction Stop | Out-Null } # 2. Get existing values $existingProps = Get-ItemProperty -Path $RegistryPath -ErrorAction SilentlyContinue $numericNames = @() $isDuplicate = $false if ($existingProps) { # Duplicate check (compare by value content) foreach ($prop in $existingProps.PSObject.Properties) { if ($prop.Value -eq $ExtensionData) { $isDuplicate = $true Write-Host " [SKIP] Already registered (Entry: $($prop.Name))" break } } # Get existing sequential numbers (extract numeric names only) $numericNames = $existingProps.PSObject.Properties.Name | Where-Object { $_ -match "^\d+$" } | ForEach-Object { [int]$_ } | Sort-Object } # 3. New registration if (-not $isDuplicate) { # Calculate Max Value + 1 $nextNum = 1 if ($numericNames.Count -gt 0) { $nextNum = $numericNames[-1] + 1 } $newValueName = $nextNum.ToString() Write-Host " [ADD] Executing new registration: Name='$newValueName'" New-ItemProperty -Path $RegistryPath -Name $newValueName -Value $ExtensionData -PropertyType String -Force -ErrorAction Stop | Out-Null Write-Host " [SUCCESS] Registration completed" } } catch { Write-Error " [ERROR] An error occurred while processing $BrowserName: $($_.Exception.Message)" $script:HasError = $true } } # ----------------------------------------------------------- # Main Process # ----------------------------------------------------------- foreach ($target in $TargetExtensions) { Set-BrowserExtension -BrowserName $target.Name -RegistryPath $target.RegPath -ExtensionData $target.Value } Write-Host "`n--- Process Ended: $(Get-Date) ---" Stop-Transcript # ----------------------------------------------------------- # Post-processing (Log deletion check and ExitCode) # ----------------------------------------------------------- if ($script:HasError) { # If an error occurred: Keep the log and return exit code 1 (Failure) Write-Warning "An error occurred during processing. Please check the log: $LogFilePath" exit 1 } else { # If no error occurred: Delete the log and return exit code 0 (Success) Remove-Item -Path $LogFilePath -Force -ErrorAction SilentlyContinue exit 0 } - After saving it as a ps1 file, please configure the settings by referring to "How to Distribute Software Using SKYSEA Client View (Cloud Edition)."
✕