Bulk-add list of URLS to Chrome whitelist/blacklist

Bulk-add list of URLS to Chrome whitelist/blacklist. #MC-KB26

Written by Ines

Last published at: February 28th, 2024

To whitelist URLS:

Script Events:

  1. Import data from CSV
  2. Load data into array
  3. Convert json profile
  4. Replace the existing url list
  5. Convert back to json
  6. Save json file under a different name


Delete

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


Delete

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