デバイス(ドメイン)にログインする際、個別のIDではなく、共通のIDでログインしている。個人の特定までできなくていいが、どのPCからのアクセスかを特定したい
そのPCをメンバーとして、ジョーシス上に登録してください。その際、「姓」、「メールアドレス」(ダミーでかまいません)、「紐づけID(ITデバイスID)」を登録してください。紐づけID(ITデバイスID)には、PC名(COMPUTERNAME)を登録してください。
スクリプトの概要
システム権限で実行します。HKLMのChromeとEdge用のレジストリに、ジョーシスの組織IDとデバイス名(COMPUTERNAME)を書き込みます。
エラーがあった場合のみ、$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 でのソフトウェア配布の方法 をご参照の上設定を続けてください。
※PCをメンバーとして、ジョーシス上に登録してください。その際、「姓」、「メールアドレス」(ダミーでかまいません)、「紐づけID(ITデバイスID)」を登録してください。紐づけID(ITデバイスID)には、PC名(COMPUTERNAME)を登録してください。
<#
.SYNOPSIS
Writes specified policy values (OrganizationKey and DeviceIdentity) 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.
- Sets OrganizationKey
- Sets DeviceIdentity to the local Computer Name
#>
# --- 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
$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."
# Get Computer Name
$computerName = $env:COMPUTERNAME
Add-Log "Target Computer Name: $computerName"
# 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
if (-not (Test-Path -Path $chromePath)) {
Add-Log "Chrome registry key does not exist. Creating..."
New-Item -Path $chromePath -Force -ErrorAction Stop | Out-Null
}
# 1. Set OrganizationKey
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" }
# 2. Set DeviceIdentity (Computer Name)
New-ItemProperty -Path $chromePath -Name "DeviceIdentity" -Value $computerName -PropertyType String -Force -ErrorAction SilentlyContinue
if ($?) { Add-Log "Successfully set Chrome 'DeviceIdentity' to '$computerName'." }
else { Add-Log "Failed to set Chrome 'DeviceIdentity'. 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
if (-not (Test-Path -Path $edgePath)) {
Add-Log "Edge registry key does not exist. Creating..."
New-Item -Path $edgePath -Force -ErrorAction Stop | Out-Null
}
# 1. Set OrganizationKey
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" }
# 2. Set DeviceIdentity (Computer Name)
New-ItemProperty -Path $edgePath -Name "DeviceIdentity" -Value $computerName -PropertyType String -Force -ErrorAction SilentlyContinue
if ($?) { Add-Log "Successfully set Edge 'DeviceIdentity' to '$computerName'." }
else { Add-Log "Failed to set Edge 'DeviceIdentity'. 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 {
# Fallback if logging fails
}
}