Bulk-add list of URLS to Chrome whitelist/blacklist
Bulk-add list of URLS to Chrome whitelist/blacklist. #MC-KB26
To whitelist URLS:
Script Events:
- Import data from CSV
- Load data into array
- Convert json profile
- Replace the existing url list
- Convert back to json
- Save json file under a different name
Mandatory fields in CSV
Script example:
Script:
$oldjson = "C:\Temp\test_profile.json" #Specify location of the profile you're editing
$newjson = "C:\Temp\new_profile.json" #Specify the location where the new profile will be saved
$newRuleList = Import-Csv -Delimiter "," -Path "C:\Temp\urls.csv" #Specify the location of the csv file containing urls
#do not edit below this line
#########################################
$ruleList = @()
foreach ($l in $newRuleList) {
$ruleFormat = [PSCustomObject]@{
Hive = 0
Key = "Software\Policies\Google\Chrome\URLAllowlist"
ValueName = $l.ValueName
ValueType = 0
ValueData = $l.ValueData
Enabled = $true
}
$ruleList += $ruleFormat
}
$currentProfile = Get-Content $oldjson
$profileOuter = $currentProfile |ConvertFrom-Json
$profileData = $profileOuter.profileData | ConvertFrom-Json
$profileData.ComputerSettings.RegistrySettings = $ruleList
$profileOuter.profileData = $profileData | ConvertTo-Json -Depth 99
$updatedProfile = $profileOuter | ConvertTo-Json -Depth 99
$updatedProfile | Set-Content $newjson
To blacklist URLS
Mandatory fields in CSV
Script example:
Script:
$oldjson = "C:\Temp\test_profile.json" #Specify location of the profile you're editing
$newjson = "C:\Temp\newprofile.json" #Specify the location where the new profile will be saved
$newRuleList = Import-Csv -Delimiter "," -Path "C:\Temp\urls.csv" #Specify the location of the csv file containing urls
#do not edit below this line
#########################################
$ruleList = @()
foreach ($l in $newRuleList) {
$ruleFormat = [PSCustomObject]@{
Hive = 0
Key = "Software\Policies\Google\Chrome\URLBlocklist"
ValueName = $l.ValueName
ValueType = 0
ValueData = $l.ValueData
Enabled = $true
}
$ruleList += $ruleFormat
}
$currentProfile = Get-Content $oldjson
$profileOuter = $currentProfile |ConvertFrom-Json
$profileData = $profileOuter.profileData | ConvertFrom-Json
$profileData.ComputerSettings.RegistrySettings = $ruleList
$profileOuter.profileData = $profileData | ConvertTo-Json -Depth 99
$updatedProfile = $profileOuter | ConvertTo-Json -Depth 99
$updatedProfile | Set-Content $newjson