# Set-PhimaskPolicy.ps1, from phimask.com # Installs PHI Mask in Chrome, with your staff key. # # Run it as an administrator, with the staff key (the Seat 2 key): # powershell -ExecutionPolicy Bypass -File .\Set-PhimaskPolicy.ps1 -LicenseKey PHIM-XXXXXX-XXXXXX-XXXXXX-XXXXXX # # Or put the key in the $LicenseKey line below and run it without -LicenseKey. # Intune: add it as a platform script (logged on credentials: No). # Group Policy: add it as a computer startup script. # To take PHI Mask away again, add -Remove to the run line. # At chrome://policy press Reload policies. #Requires -RunAsAdministrator param( # Not the Seat 1 billing key: it's the clinic manager's. [string]$LicenseKey = 'PUT-STAFF-KEY-HERE', [switch]$Remove = $false # $true takes PHI Mask away again ) $ErrorActionPreference = 'Stop' $Browsers = @( @{ Policy = 'SOFTWARE\Policies\Google\Chrome'; Id = 'kcmpppojpihbagegmplldklbpfagodge' } ) $String = [Microsoft.Win32.RegistryValueKind]::String $Machine = [Microsoft.Win32.RegistryKey]::OpenBaseKey('LocalMachine', 'Registry64') function Get-Names($List) { @($List.GetValueNames() | Where-Object { $_ -match '^[0-9]{1,9}$' } | Sort-Object { [int]$_ }) } function Get-Run($List) { $Run = @() foreach ($Name in (Get-Names $List)) { $Run += [string]$List.GetValue($Name) } , $Run } function Set-Run($List, $Run) { foreach ($Name in (Get-Names $List)) { $List.DeleteValue($Name) } for ($N = 0; $N -lt $Run.Count; $N++) { $List.SetValue([string]($N + 1), $Run[$N], $String) } } $Failed = $false try { if (-not $Remove) { $Compact = $LicenseKey.Trim().ToUpperInvariant() -replace '[\s-]', '' if ($Compact -notmatch '^(?:PHIM|(?!PHIM))[0-9A-TV-Z]{24}$') { throw 'Put the staff key in $LicenseKey, or pass it with -LicenseKey.' } } foreach ($Browser in $Browsers) { $ListPath = $Browser.Policy + '\ExtensionInstallForcelist' $ValuePath = $Browser.Policy + '\3rdparty\extensions\' + $Browser.Id + '\policy' if ($Remove) { $List = $Machine.OpenSubKey($ListPath, $true) if ($List) { $Run = Get-Run $List $Kept = @($Run | Where-Object { $_.Split(';')[0].Trim() -ne $Browser.Id }) if ($Kept.Count -ne $Run.Count) { Set-Run $List $Kept } $Empty = $List.ValueCount -eq 0 -and $List.SubKeyCount -eq 0 $List.Close() if ($Empty) { $Machine.DeleteSubKey($ListPath, $false) } } $Key = $Machine.OpenSubKey($ValuePath, $true) if ($Key) { $Key.DeleteValue('phimask', $false); $Key.Close() } } else { $List = $Machine.CreateSubKey($ListPath) $Run = Get-Run $List if (-not ($Run | Where-Object { $_.Split(';')[0].Trim() -eq $Browser.Id })) { Set-Run $List @($Run + $Browser.Id) } $List.Close() $Json = [ordered]@{ licenseKey = $LicenseKey.Trim() } | ConvertTo-Json -Compress $Key = $Machine.CreateSubKey($ValuePath) $Key.SetValue('phimask', $Json, $String) $Key.Close() } } if ($Remove) { Write-Output 'PHI Mask is taken away from Chrome.' } else { Write-Output 'PHI Mask is set up in Chrome.' Write-Output 'At chrome://policy, press Reload policies.' } } catch { Write-Host "PHI Mask was not set up: $($_.Exception.Message)" $Failed = $true } if ($Failed) { exit 1 }