デバイス(ドメイン)にログインする際、個別のIDではなく、共通のIDでログインしているが、個人を特定して検知したい
(組織用GoogleアカウントやMicrosoftアカウントなどジョーシス上に登録されているのと同じメールアドレスでブラウザにログインしている必要があります。それ以外の場合検知できません)
スクリプトの概要
システム権限で実行します。HKLMのChromeとEdge用のレジストリに、ジョーシスの組織IDを書き込みます。
エラーがあった場合のみ、$logFilePath 変数で指定している場所(サンプル内では、 C:\Windows\Temp\Set-BrowserExtensionPolicy_Error.log)にログが出力されます。
利用にあたって変更が必要な箇所
$organizationKey = "YOUR_ORGANIZATION_KEY_HERE" の YOUR_ORGANIZATION_KEY_HERE をお客様の組織IDに変更してください。
$logFilePath = "C:\Windows\Temp\Set-BrowserExtensionPolicy_Error.log" ログが出力されるフォルダパスを必要に応じて変更して下さい。
利用方法
以下のスクリプトをコピーし、メモ帳などに貼り付け「名前を付けて保存」してください。ファイルの拡張子は、.ps1 とし、文字コードはUTF-8(BOM付)を選択してください。
その後 SKYSEA Client View でのソフトウェア配布の方法 をご参照の上設定を続けてください。
<#
.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" # エラー時に出力されるログのパス
# --- End of Configuration Settings ---
# --- Logging Setup ---
# メッセージをメモリに蓄積するためのリスト
$logBuffer = New-Object System.Collections.Generic.List[string]
# エラーが発生したかどうかを判定するフラグ
$errorOccurred = $false
# ログ記録用関数(画面出力の代わりにバッファに記録)
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)
# エラータイプの場合はフラグを立てる
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"
# エラーが発生したのでログを出力して終了
$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 {
# 万が一ログファイルの書き込み自体に失敗した場合の最終手段(通常はログなし)
}
}