Configure Microsoft Edge with powershell - Windows 11 - windows

My goal is to configure Microsoft Edge with Powershell only.
So for example, the first window does not appear when you open it for the first time, to adjust the overlay etc. .
Set the home page, show the home button at the top, set favorites, etc.
What is the best way to do this with Powershell?

The logic to configuring MS Edge with PowerShell is you need to access and modify the relevant registry keys using PowerShell.
For configuring different Edge browser features, you need to configure the corresponding registries. so you would need to know which registry key is used for which feature.
Below is an example to set the Homepage for the Edge browser using Powershell.
# Ensure Edge key exists
$EdgeHome = 'HKCU:\Software\Policies\Microsoft\Edge'
If ( -Not (Test-Path $EdgeHome)) {
New-Item -Path $EdgeHome | Out-Null
}
# Set RestoreOnStartup value entry
$IPHT = #{
Path = $EdgeHome
Name = 'RestoreOnStartup'
Value = 4
Type = 'DWORD'
}
Set-ItemProperty #IPHT -verbose
# Create Startup URL's registry key
$EdgeSUURL = "$EdgeHome\RestoreOnStartupURLs"
If ( -Not (Test-Path $EdgeSUURL)) {
New-Item -Path $EdgeSUURL | Out-Null
}
# Create a single URL startup page
$HOMEURL = 'https://duckduckgo.com'
Set-ItemProperty -Path $EdgeSUURL -Name '1' -Value $HomeURL
Helpful References:
How to Change the Start Page for the Edge Browser
How can I set the home page in Edge Chromium with Powershell?
The above example will give you an idea about how to access and modify the registry using PowerShell to configure the Edge features.
Further, you could make tests on your side to configure other options for the Edge browser.
Note: Some Edge options/ features are only available to configure if the machine is AD joined. If you try to configure and the machine is not AD joined then it will be ignored.

Related

Can I make a PowerShell to dynamically add a Trusted Site on the user's computer?

I want to add my internal network folders to the trusted sites dynamically because Excel is blocking the macros inside them (when opening the Excel document via network folder).
I want my users to be able to read and update the document as their wish, meaning that I don't want to make local copies of the file onto the user's computers every time they want to use, edit or add a macro.
Is there a way to replicate the "Internet Options -> Security -> Trusted sites -> Sites -> Add site" process using a PowerShell (or a bash) script?
If you want to add the domain name to the trusted site list in the IE browser then you could refer to the Powershell script example below.
Set-Location "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains"
New-Item test.com
Set-Location test.com
New-ItemProperty . -Name http -Value 2 -Type DWORD
If you want to add the IP address to the trusted site list in the Ie browser then you could refer to the Powershell script example below.
Set-Location "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges"
New-Item Range1 # Modify it if it is exists#
Set-Location "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range1" #Modify the path, if you modify the Range key in line above#
New-ItemProperty . -Name ":Range" -Value "129.0.0.1"
New-ItemProperty . -Name "file" -Value 2
Note:
If you receive an error that A key in this path already exists then you need to modify the key name (e.g. Range2, Range3, etc.)
After you modify the Key name(in 2nd line), you need to modify the path(in 3rd line) according to the new key name.
Further, you could modify the above example as per your requirements.

Powershell: How can i get the primary screen resolution of a logged in user?

Our current scenario is this:
We have more than 80 tablet computers (running Windows 10) in our network that run under the same user (DefaultUser). In order to verify that the display settings are correctly set, we would like to use a powershell script to automatically check the used resolution remotely with a support user account.
So far, we know how to get the primary screen resolution for the user under which the script gets executed (which is rather easy):
// get primary screen width
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Width // height accordingly
In case we execute this script on one of the tablets using the support account, we get the primary screen resolution for the support account user - but not for the desired user DefaultUser.
How can we get the resolution for the DefaultUser?
The only solution that easily comes to my mind is a rather ugly thing:
Using the windows task scheduler i could create a task that executes the script (under the defaultUser) to get the screen resolution and write the result(s) into a file that can be accessed by the support user account. But i am looking for something more elegant.
It sounds like you're looking for the screen scaling values, based on your code checking the PrimaryScreen values:
# My monitor resolution is 3000x2000
Add-Type -AssemblyName System.Windows.Forms
# [Screen] returns screen size AFTER scaling (200% here)
[System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Height
1000
# [SystemInformation] returns the hardware screen resolution (applies to all users)
[System.Windows.Forms.SystemInformation]::VirtualScreen.Height
2000
Scaling can be set on a per-user basis, though there is a machine-wide "Default" setting. Screen scaling is weird, and gets done differently depending on what version of windows you have. Here's how it works in Windows 10 at least.
You can check the current values like so:
# AllUsers setting, which shows as (default)
Get-ItemProperty -path "HKCU:\Control Panel\Desktop\WindowMetrics" | fl AppliedDPI
# User's current scaling setting (I use a * instead of the per-monitor ID)
Get-ItemProperty -path "HKCU:\Control Panel\Desktop\PerMonitorSettings\*" | fl DpiValue
# AppliedDPI shows the "Default" scaling setting on a system level like:
96 : 100%
120 : 125%
144 : 150%
192 : 200% (my default)
# DpiValue shows how many steps up or down the current user's scaling setting is. For example on my machine:
#250%
DpiValue : 2 # +2
#200% (default)
DpiValue : 0
#150%
DpiValue : 4294967294 # -1
#100%
DpiValue : 4294967292 # -3
Finding and overriding scaling for other user profiles is pretty involved, but has been done by other people. I found this script and usage details by user romaliceishimwe2. I have not tested, but it does show how to look at and change other users' profiles:
#First we configure the default, later we will configure any existing users.
#Load the ntuser.dat of the default user
REG LOAD HKU\Default_User C:\users\default\ntuser.dat
#Assign new registry keys
New-ItemProperty -path registry::"HKU\Default_User\Control Panel\Desktop" -Name LogPixels -Value 120 -Type DWord
New-ItemProperty -path registry::"HKU\Default_User\Control Panel\Desktop" -Name Win8DpiScaling -Value 1 -Type DWord
#unload default user ntuser.dat
REG UNLOAD HKU\Default_User
#Here we configure any eixting users
# Regex pattern for SIDs
$PatternSID = 'S-1-5-21-\d+-\d+\-\d+\-\d+$'
# Get Username, SID, and location of ntuser.dat for all users
$ProfileList = gp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\*' | Where-Object {$_.PSChildName -match $PatternSID} |
Select #{name="SID";expression={$_.PSChildName}},
#{name="UserHive";expression={"$($_.ProfileImagePath)\ntuser.dat"}},
#{name="Username";expression={$_.ProfileImagePath -replace '^(.*[\\\/])', ''}}
# Get all user SIDs found in HKEY_USERS (ntuder.dat files that are loaded)
$LoadedHives = gci Registry::HKEY_USERS | ? {$_.PSChildname -match $PatternSID} | Select #{name="SID";expression={$_.PSChildName}}
# Get all users that are not currently logged
$UnloadedHives = Compare-Object $ProfileList.SID $LoadedHives.SID | Select #{name="SID";expression={$_.InputObject}}, UserHive, Username
# Loop through each profile on the machine
Foreach ($item in $ProfileList) {
# Load User ntuser.dat if it's not already loaded
IF ($item.SID -in $UnloadedHives.SID) {
reg load HKU\$($Item.SID) $($Item.UserHive) | Out-Null
}
#####################################################################
# This is where you can read/modify a users portion of the registry
"{0}" -f $($item.Username) | Write-Output
New-ItemProperty -path registry::"HKU\$($Item.SID)\Control Panel\Desktop" -Name LogPixels -Value 120 -Type DWord -force
New-ItemProperty -path registry::"HKU\$($Item.SID)\Control Panel\Desktop" -Name Win8DpiScaling -Value 1 -Type DWord -force
#####################################################################
# Unload ntuser.dat
IF ($item.SID -in $UnloadedHives.SID) {
### Garbage collection and closing of ntuser.dat ###
[gc]::Collect()
reg unload HKU\$($Item.SID) | Out-Null
}
}
You may be able to use CIM or WMI to get from point a to b.
CIM_VideoController is the class that would contain the resolution.
Using PowerShell Core:
Get-CimInstance CIM_VideoController | Select SystemName, CurrentHorizontalResolution, CurrentVerticalResolution
Using Windows PowerShell:
Get-WmiObject Win32_VideoController | Select SystemName, CurrentHorizontalResolution, CurrentVerticalResolution
You should be able to open the proper ports to use either of these options remotely (though you could also probably get away with using Invoke-Command to run them, as long as you use CredSSP or Kerberos Delegation to take the 2nd hop problem into account).

Change Language and Regional settings on Windows

I never tried doing this, but I think it is possible. I need a executable file,
or a script, that can automatically change Default Windows Format and Digital symbol.
I need it so that I can one click change the default Region on many PCs.
I made a shortcut for opening intl.cpl:
C:\Windows\System32\rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,0
But I want it all to be automatic:
Change format to:
Serbian (Latin, Serbia)
Change Decimal and grouping Symbol to:"." and "," respectively
And Change RegionSetings to:Serbian (Latin, Serbia)
I found this PowerShell Script but I don't know how to make all changes that I want.
These are the three commands I use for changing Windows 10 to UK English (en-GB / 242), I had a look for the Serbian values and found these from a bit of google-fu:
sr-Latn-RS language (from Windows table of Language IDs)
271 for GeoId (from table-of-geographical-locations)
Hopefully those are the correct values for your language/location.
I can't test these commands as I don't have a VM to hand and don't want to change the language on my own system.
Set-WinSystemLocale -SystemLocale sr-Latn-RS
Set-WinHomeLocation -GeoId 271
Set-WinUserLanguageList -LanguageList (New-WinUserLanguageList -Language sr-Latn-RS) -Force
EDIT:
OP found the settings for the other configuration changes:
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sDecimal -Value "."
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sThousand -Value ","

Powershell script: List files with specific change date (Amount if possible)

For license porpuses I try to automate the counting process instead of having to login into every single server, go into directory, search a file name and count the results based on the change date.
Want I'm aiming for:
Running a powershell script every month that checks the directory "C:\Users" for the file "Outlook.pst" recursively. And then filters the result by change date (one month or newer). Then packing this into an email to send to my inbox.
I'm not sure if that's possible, cause I am fairly new to powershell. Would appreciate your help!
It is possible.
I dont know how to start a ps session on a remote computer, but I think the cmdlet Enter-PSSession will do the trick. Or at least it was the first result while searching for "open remote powershell session". If that does not work use the Invoke-Command as suggested by lit to get $outlookFiles as suggested below.
For the rest use this.
$outlookFiles = Get-ChildItem -Path "C:\Users" -Recurse | Where-Object { $_.Name -eq "Outlook.pst" }
Now you have all files that have this name. If you are not familiar with the pipe in powershell it redirects all objects it found with the Get-ChildItem to the next pipe section and here the Where-Object will filter the received objects. If the current object ($_) will pass the condition it is returned by the whole command.
Now you can filter these objects again to only include the latest ones with.
$latestDate = (Get-Date).AddMonths(-1)
$newFiles = $outlookFiles | Where-Object { $_.LastAccessTime -gt $latestDate }
Now you have all the data you want in one object. Now you only have to format this how you like it e.g. you could use $mailBody = $newFiles | Out-String and then use Send-MailMessage -To x#y.z -From r#g.b -Body $mailBodyto send the mail.

How to get the Dropbox folder in Powershell in Windows

Same question exists for Python here: How can I get the Dropbox folder location programmatically in Python?, or here for OSX: How to get the location of currently logined Dropbox folder
Same thing in Powershell. I need the path of DropBox to copy files to it (building a software and then copying it to dropbox to share with team).
This Dropbox help page tells us where this info is stored, ie, in a json file in the AppData of the user: https://www.dropbox.com/help/4584
function GetDropBoxPathFromInfoJson
{
$DropboxPath = Get-Content "$ENV:LOCALAPPDATA\Dropbox\info.json" -ErrorAction Stop | ConvertFrom-Json | % 'personal' | % 'path'
return $DropboxPath
}
The line above is taken from: https://www.powershellgallery.com/packages/Spizzi.Profile/1.0.0/Content/Functions%5CProfile%5CInstall-ProfileEnvironment.ps1
Note that it doesn't check if you've got a Dropbox business account, or if you have both. It just uses the personal one.
You can then use this base Dropbox folder to build your final path, for example:
$targetPath = Join-Path -Path (GetDropBoxPathFromInfoJson) -ChildPath 'RootDropboxFolder\Subfolder1\Subfolder2'
if (-not (Test-Path -Path $targetPath)) { throw "Path '$targetPath' not found!" }
--
Alternative way is using the host.db file, as shown on this page:
http://bradinscoe.tumblr.com/post/75819881755/get-dropbox-path-in-powershell
$base64path = gc $env:appdata\Dropbox\host.db | select -index 1 # -index 1 is the 2nd line in the file
$dropboxPath = [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($base64path)) # convert from base64 to ascii

Resources