Last active
August 31, 2022 07:18
-
-
Save hansgafriedzal/172def2c727145cb8c07a599b776127b to your computer and use it in GitHub Desktop.
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
function Get-BrowserProfile { | |
param | |
( | |
[Parameter(Position=0)] | |
[ValidateSet('chrome','msedge','All')] | |
$Browser = 'All', | |
) | |
$browsers = @{} | |
$browsers['chrome'] = 'google\chrome' | |
$browsers['msedge'] = 'microsoft\edge' | |
if ($Browser -ne 'All') | |
{ | |
$toRemove = $browsers.GetEnumerator() | where Key -ne $Browser | |
$toRemove | %{ | |
$browsers.Remove($_.Name) | |
} | |
} | |
$profiles = @() | |
$browsers.Keys | %{ | |
$key = $_ | |
$pathUserData = "$env:localappdata\$($browsers[$key])\user data\" | |
$profileFolders = dir $pathUserData | ?{ | |
$_.Name -like 'default' -or $_.Name -like 'profile*' | |
} | |
$profiles += $profileFolders | %{ | |
$pref = cat "$($_.FullName)\preferences" | ConvertFrom-Json -AsHashtable | |
[pscustomobject] @{ | |
Browser = $key | |
Profile = $_.Name | |
Email = $pref.account_info.email | |
} | |
} | |
} | |
if ($Email) | |
{ | |
$profiles = $profiles | where Email -Contains $email | |
} | |
return $profiles | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment