KI GeneriertPowerShell Skript zum setzen von Browser Startseite für Firefox, Chrome und Edge
Veröffentlicht:Wenn es um das Surfen geht, bevorzugen viele von uns bestimmte Websites als Startseite in unseren Browsern. Die Startseiten Einstellung zählt bei den Browsern als Benutzereinstellung. Im Unternehmenskontext für jeden Benutzer die Startseite manuell zu setzen wäre ein extrem aufwendiges Unterfangen. Mittels Powershell und einem Startskript nach dem Login oder mittels PowerShell Remoting lässt sich das Problem beheben. In diesem Blogbeitrag zeigen ich Ihnen eine Sammlung von PowerShell Funktionen die ich geschrieben habe, mit denen sich einfach die Startseiten setzen lassen.
Das PowerShell Skript
function Set-EdgeDefaultPage {
Param(
[string]$Url = "https://www.marcogriep.de"
)
# Einstellen das URLs geöffnet werden sollen und nicht die NewTabPage
$path = 'HKCU:\Software\Policies\Microsoft\Edge\'
$name = 'RestoreOnStartup'
$value = 4
Set-Itemproperty -Path $path -Name $name -Value $value
# Die Url zum öffnen
New-Item -Path 'HKCU:\Software\Policies\Microsoft\Edge' -Name RestoreOnStartupURLs -Force
$path = 'HKCU:\Software\Policies\Microsoft\Edge\RestoreOnStartupURLs'
$name = '1'
$value = $Url
Set-Itemproperty -Path $path -Name $name -Value $value
}
function Set-ChromeDefaultPage {
Param(
[string]$Url = "https://www.marcogriep.de"
)
if (test-path "$($env:LOCALAPPDATA)\Google\Chrome\User Data\Default\Preferences") {
$ChromePrefFile = "$($env:LOCALAPPDATA)\Google\Chrome\User Data\Default\Preferences"
}
elseif (test-path "$($env:LOCALAPPDATA)\Google\Chrome\User Data\Profile 1\Preferences") {
$ChromePrefFile = "$($env:LOCALAPPDATA)\Google\Chrome\User Data\Profile 1\Preferences"
}
$Settings = Get-Content $ChromePrefFile -Encoding UTF8 | ConvertFrom-Json
$newhp = $Url
if (! $Settings.session.startup_urls) {
$sBlock = '
{
"restore_on_startup": 4,
"startup_urls": [ "$Url" ]
}'
$Settings | Add-Member -name "session" -Value (convertfrom-json $sBlock) -MemberType NoteProperty -Force
}
if(! $Settings.homepage_is_newtabpage) {
$Settings | Add-Member -name "homepage_is_newtabpage" -value "" -MemberType NoteProperty -force
}
if(! $settings.browser.show_home_button) {
$Settings.browser | Add-Member -name "show_home_button" -value "" -MemberType NoteProperty -force
}
if(! $settings.homepage) {
$Settings | Add-Member -name "homepage" -value "" -MemberType NoteProperty -force
}
$Settings.session.startup_urls = @($newhp)
$settings.session.restore_on_startup = 4
$Settings.homepage = $newhp
$Settings.homepage_is_newtabpage = $false
$settings.browser.show_home_button = $true
$Settings | ConvertTo-Json -compress -Depth 99 | Out-File $ChromePrefFile -Encoding UTF8
}
function Get-FirefoxProfilePath {
$TopDir = "$env:APPDATA\Mozilla\Firefox\Profiles"
$FileName = 'prefs.js'
$DefaultProfileDir = (Get-ChildItem -LiteralPath $TopDir -Directory).
Where({
$_.FullName -match '\.default'
}).FullName
$activeProfileDir = ""
foreach($profile in $DefaultProfileDir) {
if (Test-Path -Path "$profile\$FileName") {
$activeProfileDir = $profile
}
}
if ($activeProfileDir -eq "") {
return
}
$FullFileName = Join-Path -Path $activeProfileDir -ChildPath $FileName
return $FullFileName
}
function Get-FirefoxUserSettingsPath {
$profilePath = Get-FirefoxProfilePath
$FileName = 'user.js'
$activeProfileDir = Split-Path -Path $profilePath -Parent
$FullFileName = Join-Path -Path $activeProfileDir -ChildPath $FileName
return $FullFileName
}
function Get-FirefoxDefaultPage {
$profilePath = Get-FirefoxUserSettingsPath
if (-Not (Test-Path $profilePath)) {
return
}
$startUpPage = (Get-Content -LiteralPath $profilePath -Encoding UTF8).
Where({
$_ -match 'user_pref\("browser.startup.homepage"'
}) -replace '.*= ' -replace ';.*'
return $startUpPage
}
function Set-FirefoxDefaultPage {
Param(
[string]$Url = "https://www.marcogriep.de"
)
$profilePath = Get-FirefoxUserSettingsPath
if (-Not (Test-Path $profilePath)) {
$startUpPage = ""
}
else {
$startUpPage = (Get-Content -LiteralPath $profilePath -Encoding UTF8).
Where({
$_ -match 'user_pref\("browser.startup.homepage"'
}) -replace '.*= ' -replace ';.*'
}
if ([String]::IsNullOrEmpty($startUpPage)) {
$startUpPage = "user_pref(`"`"browser.startup.homepage`"`", `"`"$Url`"`");"
Add-Content -LiteralPath $profilePath -Value $startUpPage
return
}
(Get-Content -LiteralPath $profilePath -Encoding UTF8) |
Foreach-Object {
$_ -replace $startUpPage, $Url
} | Set-Content -LiteralPath $profilePath -Encoding UTF8
}
Sie haben Fragen, benötigen Unterstützung oder haben ein Problem, das Sie nicht alleine lösen können? Zögern Sie nicht, mich zu kontaktieren! Als erfahrener Experte stehe ich Ihnen gerne zur Seite und helfe Ihnen bei Ihren Anliegen.
Artikel drucken