- 先にアクティベーションの設定を実施してください。
- 以下のスクリプトに名前を付けて、ps1 ファイルとして保存してください。
(メモ帳などで保存する場合は、UTF-8(BOM付き)推奨)- このスクリプトはChrome、Edge 両方のブラウザに対して設定を行います。
- このスクリプトはエラーだった場合のみ、スクリプト内のパスにログファイルを残します。
パスは必要に応じて編集してください。
<# .SYNOPSIS ブラウザ拡張機能強制インストール設定スクリプト .DESCRIPTION Google ChromeおよびMicrosoft Edgeの ExtensionInstallForcelist にエントリを追加します。 SKYSEA、ADスタートアップスクリプト等、SYSTEM権限での実行に対応しています。 .NOTES 設定エリアの $ExtensionList に登録したい拡張機能情報を記述してください。 #> #Requires -Version 5.1 #Requires -RunAsAdministrator # ----------------------------------------------------------- # [設定エリア] 導入したい拡張機能とログ設定 # ----------------------------------------------------------- # ログファイルのパス $LogFilePath = "C:\Windows\Temp\BrowserExtensionInstall.log" # 対象のブラウザと拡張機能設定のリスト # 記述形式: "拡張機能ID;更新URL" $TargetExtensions = @( @{ Name = "Google Chrome" RegPath = "HKLM:\SOFTWARE\Policies\Google\Chrome\ExtensionInstallForcelist" # 以下は例: JosysのID Value = "moaklgcgokbgplldonjkoochhlefkbjf;https://clients2.google.com/service/update2/crx" }, @{ Name = "Microsoft Edge" RegPath = "HKLM:\SOFTWARE\Policies\Microsoft\Edge\ExtensionInstallForcelist" # 以下は例: JosysのID Value = "hjifncajikcdkhlofdjjlhcjoennmdfc;https://edge.microsoft.com/extensionwebstorebase/v1/crx" } ) # ----------------------------------------------------------- # 初期処理 # ----------------------------------------------------------- $script:HasError = $false try { Start-Transcript -Path $LogFilePath -Append -ErrorAction SilentlyContinue } catch { # ログ開始失敗時も動作は継続させる } Write-Host "--- 処理開始: $(Get-Date) ---" Write-Host "実行ユーザー: $env:USERNAME" # ----------------------------------------------------------- # 関数定義 # ----------------------------------------------------------- function Set-BrowserExtension { param ( [string]$BrowserName, [string]$RegistryPath, [string]$ExtensionData ) Write-Host "`n[$BrowserName] の設定を確認中..." try { # 1. パスの確認と作成 if (-not (Test-Path $RegistryPath)) { Write-Host " [INFO] レジストリキーが存在しないため作成します: $RegistryPath" New-Item -Path $RegistryPath -Force -ErrorAction Stop | Out-Null } # 2. 既存値の取得 $existingProps = Get-ItemProperty -Path $RegistryPath -ErrorAction SilentlyContinue $numericNames = @() $isDuplicate = $false if ($existingProps) { # 重複チェック (値の内容で比較) foreach ($prop in $existingProps.PSObject.Properties) { if ($prop.Value -eq $ExtensionData) { $isDuplicate = $true Write-Host " [SKIP] 既に登録済みです (Entry: $($prop.Name))" break } } # 既存の連番を取得 (数値の名前のみ抽出) $numericNames = $existingProps.PSObject.Properties.Name | Where-Object { $_ -match "^\d+$" } | ForEach-Object { [int]$_ } | Sort-Object } # 3. 新規登録 if (-not $isDuplicate) { # 最大値 + 1 を計算 $nextNum = 1 if ($numericNames.Count -gt 0) { $nextNum = $numericNames[-1] + 1 } $newValueName = $nextNum.ToString() Write-Host " [ADD] 新規登録を実行します: 名前='$newValueName'" New-ItemProperty -Path $RegistryPath -Name $newValueName -Value $ExtensionData -PropertyType String -Force -ErrorAction Stop | Out-Null Write-Host " [SUCCESS] 登録完了" } } catch { Write-Error " [ERROR] $BrowserName の処理中にエラーが発生しました: $($_.Exception.Message)" $script:HasError = $true } } # ----------------------------------------------------------- # メイン処理 # ----------------------------------------------------------- foreach ($target in $TargetExtensions) { Set-BrowserExtension -BrowserName $target.Name -RegistryPath $target.RegPath -ExtensionData $target.Value } Write-Host "`n--- 処理終了: $(Get-Date) ---" Stop-Transcript # ----------------------------------------------------------- # 終了処理 (ログ削除判定 と ExitCode) # ----------------------------------------------------------- if ($script:HasError) { # エラーがあった場合: ログを残し、終了コード 1 (失敗) を返す Write-Warning "処理中にエラーが発生しました。ログを確認してください: $LogFilePath" exit 1 } else { # エラーがなかった場合: ログを削除し、終了コード 0 (成功) を返す Remove-Item -Path $LogFilePath -Force -ErrorAction SilentlyContinue exit 0 } - ps1ファイルとして保存したら、「SKYSEA Client View(クラウド版) でのソフトウェア配布の方法」
をご参照の上設定を行ってください。
✕