Based on Fiddles code this version addresses a couple of issues I found in testing. Must be run as the logged in user. See the notes at the end.
The "Local State" json file holds the per-user setting for the 'enable-site-per-process' configuration item that enables this experimental setting
Using the Local system environmental variable to get the users C:\Users\UserID\Appdata\Local folder
$USRPROF = Get-Childitem env:LOCALAPPDATA
Under that folder is the '\Google\Chrome\User Data'
folder which contains the 'Local State'
file we need to modify
$ChromeLocalState = -Join($USRPROF.Value.ToString(),'\','Google\Chrome\User Data\Local State')
Stop Chrome
Stop-Process -Name chrome -Force -ErrorAction SilentlyContinue
add site-per-process setting. Ok if it doubles the same nested statement. Chrome will parse it out.
(Get-Content $ChromeLocalState) | Foreach-Object {$_ -replace 'last_redirect_origin', 'enabled_labs_experiments":["enable-site-per-process"],"last_redirect_origin'} | Set-Content $ChromeLocalState
Find which version of Chrome is installed and launch it
Switch($TRUE) {
{Test-Path 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'} {Start-Processs -FilePath 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' }
{Test-Path 'C:\Program Files\Google\Chrome\Application\chrome.exe'} {Start-Processs -FilePath 'C:\Program Files\Google\Chrome\Application\chrome.exe' }
}
Observations during testing
If chrome is running when this script has launched the value in the 'Local State' File is made but does not take effect.
If Chrome is then closed, the 'Local State' File is overwritten with information in memory and the setting is Removed!!
So to have the best chance of this working the script has been modified to
1. Stop Chrome
2. Change the setting
3. Relaunch Chrome
Relaunching chrome is optional, the user will be asked to restore open tabs because of the non-standard termination of Chrome.
Further observation is that the local state file is constantly being modified even while chrome is in the background
This is another reason to stop chrome first.