Created
June 28, 2017 18:04
-
-
Save jmelosegui/dac6a8696ced5cedc8dff36438075cf7 to your computer and use it in GitHub Desktop.
Add extension to Chrome
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
param() | |
Function Get-RegistryKeyPropertiesAndValues | |
{ | |
Param( | |
[Parameter(Mandatory=$true)] | |
[string]$path | |
) | |
Push-Location | |
Set-Location -Path $path | |
Get-Item . | | |
Select-Object -ExpandProperty property | | |
ForEach-Object { | |
New-Object psobject -Property @{"name"=$_; "Value" = (Get-ItemProperty -Path . -Name $_).$_} | |
} | |
Pop-Location | |
} | |
$registryKey = "HKLM:\SOFTWARE\Policies\Google\Chrome\ExtensionInstallWhitelist" | |
$forceChromeExtensinkey = "HKLM:\SOFTWARE\Policies\Google\Chrome\ExtensionInstallForcelist" | |
$currentAllowedExtensions = Get-RegistryKeyPropertiesAndValues $registryKey | |
$currentAllowedValues = $currentAllowedExtensions | Select-Object -ExpandProperty "Value" | |
$lastExtensionNumber = $currentAllowedExtensions | Select-Object -ExpandProperty "name" | Measure-Object -Maximum | Select-Object -ExpandProperty Maximum | |
$forceExtensionTemplate = "{0};http://clients2.google.com/service/update2/crx?response=updatecheck&x=id%3D{0}" | |
$lastForcedExtensionNumber = Get-RegistryKeyPropertiesAndValues $forceChromeExtensinkey | Select-Object -ExpandProperty "name" | Measure-Object -Maximum | Select-Object -ExpandProperty Maximum | |
$myExtensions = Get-Content "ChromeExtensions.json" -Raw | ConvertFrom-Json | ForEach-Object { | |
$_ | Select-Object -ExpandProperty Id | |
} | |
Compare-Object $myExtensions $currentAllowedValues | | |
Where-Object {$_.sideindicator -eq "<="} | | |
ForEach-Object { | |
$lastExtensionNumber = $lastExtensionNumber + 1 | |
New-ItemProperty -Path $registryKey -Name $lastExtensionNumber -Value $_.inputobject -PropertyType String -Force | |
$lastForcedExtensionNumber = $lastForcedExtensionNumber + 1 | |
$forceExtensionValue = $forceExtensionTemplate -f $_.inputobject | |
New-ItemProperty -Path $forceChromeExtensinkey -Name $lastForcedExtensionNumber -Value $forceExtensionValue -PropertyType String -Force | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ "Name": "Postman", "Id" : "fhbjgbiflinjbdggehcddcbncdddomop" }, | |
{ "Name": "Grammarly", "Id" : "kbfnbcaeplbcioakkpcpgfkobkghlhen" } | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment