Improved PowerShell to create Edge Profiles
Are you tired of manually configuring your Microsoft Edge profiles? In my previous blog post Create and configure your Edge profiles with PowerShell, I showed you how to create a new profile for Edge using PowerShell, which can save you time and effort. However, there was one thing that bothered me (and other people): there was a new side bar and start page that showed up with news with one of the last updates. I wanted to automate this process as well, and thanks to some fantastic feedback I received at the previous blog I was able to improve with a new version. Thanks Patrik for the feedback!
New configuration
To build the improved PowerShell script, I followed a familiar approach that I used in my previous blog post. I started by investigating the Edge browser the local state and preference files to determine the properties that needed to be updated. Fiddling around with the settings and comparing the files, I was able to determine the following settings in the preference file:
browser.show_hub_apps_tower_pinned
Part of the side barbrowser.show_toolbar_learning_toolkit_button
Part of the side baredge.performance_detector
The weird performance recommendationsedge.vertical_tabs.feedback_do_not_show
A feedback button in the sidebaredge.vertical_tabs.opened
The sidebar itselfntp
contains all start page settings
These settings can be updated as we did before:
if ($null -eq $preferenceJson.edge) {
Write-Output "Set vertical tabs"
$blockvalue = @"
{
"perf_center":{
"performance_detector":false
},
"vertical_tabs":{
"collapsed":true,
"feedback_do_not_show":true,
"first_opened2":true,
"opened":true
}
}
"@
$preferenceJson | add-member -Name "edge" -value (Convertfrom-Json $blockvalue) -MemberType NoteProperty
}
if ($null -eq $preferenceJson.ntp) {
Write-Output "Disable start page"
$blockvalue = @"
{
"background_image_type":"imageAndVideo",
"hide_default_top_sites":false,
"layout_mode":3,
"news_feed_display":"off",
"num_personal_suggestions":1,
"prerender_contents_height":823,
"prerender_contents_width":1185,
"quick_links_options":0
}
"@
$preferenceJson | add-member -Name "ntp" -value (Convertfrom-Json $blockvalue) -MemberType NoteProperty
}
That would bring the full sample as follows:
Param(
[Parameter(Mandatory = $true)]
[string]
$customerName,
[Parameter(Mandatory = $false)]
[bool]
$createBackup = $true
)
Write-Output "Creating Edge profile for $customerName"
$profilePath = "profile-" + $customerName.replace(' ', '-')
$proc = Start-Process -FilePath "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" -ArgumentList "--profile-directory=$profilePath --no-first-run --no-default-browser-check --flag-switches-begin --flag-switches-end --site-per-process" -PassThru
Write-Output "Profile $customerName created, wait 15 seconds before closing Edge"
Start-Sleep -Seconds 15 #it takes roughly 15 seconds to prepare the profile and write all files to disk.
Stop-Process -Name "msedge"
# Edit profile name
$localStateFile = "$Env:LOCALAPPDATA\Microsoft\Edge\User Data\Local State"
if ($createBackup) {
$localStateBackUp = "$Env:LOCALAPPDATA\Microsoft\Edge\User Data\Local State Backup"
Copy-Item $localStateFile -Destination $localStateBackUp
}
$state = Get-Content -Raw $localStateFile
$json = $state | ConvertFrom-Json
$edgeProfile = $json.profile.info_cache.$profilePath
Write-Output "Found profile $profilePath"
Write-Output "Old profile name: $($edgeProfile.name)"
$edgeProfile.name = $customerName
Write-Output "Write profile name to local state: $($edgeProfile.name)"
# Only uncomment the next line if you know what you're doing!!
$json | ConvertTo-Json -Compress -Depth 100 | Out-File $localStateFile
Write-Output "Write profile name to registry: $($edgeProfile.name)"
Push-Location
Set-Location HKCU:\Software\Microsoft\Edge\Profiles\$profilePath
Set-ItemProperty . ShortcutName "$customerName"
Pop-Location
$preferenceSettings = "$Env:LOCALAPPDATA\Microsoft\Edge\User Data\$profilePath\Preferences"
if ($createBackup) {
$preferenceSettingsBackup = "$Env:LOCALAPPDATA\Microsoft\Edge\User Data\$profilePath\Preferences Backup"
Copy-Item $preferenceSettings -Destination $preferenceSettingsBackup
}
$preferences = Get-Content -Raw $preferenceSettings
$preferenceJson = $preferences | ConvertFrom-Json
if ($null -eq $preferenceJson.browser.show_hub_apps_tower) {
Write-Output "show_hub_apps_tower is not set and turned on by default, lets disable it"
$preferenceJson.browser | add-member -Name "show_hub_apps_tower" -value $false -MemberType NoteProperty
}
else {
$sideBarToggle = $preferenceJson.browser.show_hub_apps_tower
Write-Output "show_hub_apps_tower is set to: $sideBarToggle lets make it false"
$preferenceJson.browser.show_hub_apps_tower = $false #disable side bar
}
if ($null -eq $preferenceJson.browser.show_hub_apps_tower_pinned) {
Write-Output "show_hub_apps_tower_pinned is not set and turned on by default, lets disable it"
$preferenceJson.browser | add-member -Name "show_hub_apps_tower_pinned" -value $false -MemberType NoteProperty
}
else {
$sideBarToggle = $preferenceJson.browser.show_hub_apps_tower_pinned
Write-Output "show_hub_apps_tower_pinned is set to: $sideBarToggle lets make it false"
$preferenceJson.browser.show_hub_apps_tower_pinned = $false #disable side bar
}
if ($null -eq $preferenceJson.browser.show_toolbar_learning_toolkit_button) {
Write-Output "show_toolbar_learning_toolkit_button is not set and turned on by default, lets disable it"
$preferenceJson.browser | add-member -Name "show_toolbar_learning_toolkit_button" -value $false -MemberType NoteProperty
}
else {
$sideBarToggle = $preferenceJson.browser.show_toolbar_learning_toolkit_button
Write-Output "show_toolbar_learning_toolkit_button is set to: $sideBarToggle lets make it false"
$preferenceJson.browser.show_toolbar_learning_toolkit_button = $false #disable side bar
}
if ($null -eq $preferenceJson.edge) {
Write-Output "Set vertical tabs"
$blockvalue = @"
{
"perf_center":{
"performance_detector":false
},
"vertical_tabs":{
"collapsed":true,
"feedback_do_not_show":true,
"first_opened2":true,
"opened":true
}
}
"@
$preferenceJson | add-member -Name "edge" -value (Convertfrom-Json $blockvalue) -MemberType NoteProperty
}
else {
Write-Output "Set vertical tabs (force overwrite)"
$blockvalue = @"
{
"perf_center":{
"performance_detector":false
},
"vertical_tabs":{
"collapsed":true,
"feedback_do_not_show":true,
"first_opened2":true,
"opened":true
}
}
"@
$preferenceJson | add-member -Name "edge" -value (Convertfrom-Json $blockvalue) -MemberType NoteProperty -Force
}
if ($null -eq $preferenceJson.local_browser_data_share.enabled) {
Write-Output "Disable data share between profiles"
$blockvalue = @"
{
"enabled": false,
"index_last_cleaned_time": "0"
}
"@
$preferenceJson | add-member -Name "local_browser_data_share" -value (Convertfrom-Json $blockvalue) -MemberType NoteProperty
}
else {
Write-Output "Disable data share between profiles"
$preferenceJson.local_browser_data_share.enabled = $false; #disable sharing data between profiles
}
if ($null -eq $preferenceJson.edge_share) {
Write-Output "Disable enhanced copy paste"
$blockvalue = @"
{
"enhanced_copy_paste": {
"default_url_format": 1,
"enable_secondary_ecp": true
}
}
"@
$preferenceJson | add-member -Name "edge_share" -value (Convertfrom-Json $blockvalue) -MemberType NoteProperty
}
else {
Write-Output "Disable enhanced copy paste"
$preferenceJson.edge_share.enhanced_copy_paste.default_url_format = 1; #disable enhanced copy paste
}
if ($null -eq $preferenceJson.ntp) {
Write-Output "Disable start page"
$blockvalue = @"
{
"background_image_type":"imageAndVideo",
"hide_default_top_sites":false,
"layout_mode":3,
"news_feed_display":"off",
"num_personal_suggestions":1,
"prerender_contents_height":823,
"prerender_contents_width":1185,
"quick_links_options":0
}
"@
$preferenceJson | add-member -Name "ntp" -value (Convertfrom-Json $blockvalue) -MemberType NoteProperty
}
else {
Write-Output "Disable start page (force overwrite)"
$blockvalue = @"
{
"background_image_type":"imageAndVideo",
"hide_default_top_sites":false,
"layout_mode":3,
"news_feed_display":"off",
"num_personal_suggestions":1,
"prerender_contents_height":823,
"prerender_contents_width":1185,
"quick_links_options":0
}
"@
$preferenceJson | add-member -Name "ntp" -value (Convertfrom-Json $blockvalue) -MemberType NoteProperty -Force
}
Write-Output "Write new settings to $($profilePath)"
# Only uncomment the next line if you know what you're doing!!
$preferenceJson | ConvertTo-Json -Compress -Depth 100 | Out-File $preferenceSettings
Write-Output "Done, you can start browsing with your new profile"
I am sure I can figure out more settings if needed but with these settings I am able to create a new profile and configure it to my needs. I hope this helps you as well! It would return you with a new profile, proper naming and my favorite settings. It will work with most versions of Edge I would assume (I tested it with both the current beta and stable releases. The latest beta it has been tested with is 115.0.1901.7 (Official build) beta (64-bit)
).
Are you excited about the potential of the enhanced PowerShell script for creating and configuring your Microsoft Edge profiles? If you have any suggestions or ideas to further improve its functionality, I would love to hear from you! 🔥