Last active
June 19, 2024 21:49
-
-
Save zbalkan/5793f681e8342b89d6de5965b40eef4e to your computer and use it in GitHub Desktop.
Registry.Pol Viewer
This file contains 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
#Requires -Modules GPRegistryPolicyParser | |
#Requires -Version 5 | |
Import-Module -Name GPRegistryPolicyParser -WarningAction Ignore | |
Add-Type -AssemblyName System.Windows.Forms | |
$Script:response = [System.Windows.Forms.MessageBox]::Show("Do you want to open current hives?`n`nClick Yes to display current hives on this computer.`nClick No to pick a `'registry.pol`' file to read.", "Open current hives?", [System.Windows.MessageBoxButton]::YesNoCancel, [System.Windows.MessageBoxImage]::Question) | |
switch ($Script:response) | |
{ | |
'Yes' { $Script:OpenHive = $true } | |
'No' { $Script:OpenHive = $false } | |
Default { return } | |
} | |
if ($Script:OpenHive) | |
{ | |
$Script:AdminSession = ((New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) | |
if ($Script:AdminSession) | |
{ | |
$Script:Selected = @("CurrentUser", "LocalMachine") | Out-GridView -Title "Choose a hive" -OutputMode Single | |
} | |
else | |
{ | |
$Script:Selected = @("CurrentUser") | Out-GridView -Title "Choose a hive" -OutputMode Single | |
} | |
if ($null -eq $Script:Selected) | |
{ | |
Write-Output "No hives selected." | |
return | |
} | |
else | |
{ | |
Write-Output $Script:Selected | |
} | |
# No need to use 'Entries' parameter as the GridView provides filtering options | |
try | |
{ | |
Read-RegistryPolicies -Division $Script:Selected | Out-GridView -Title "Registry.Pol Content [$Script:Selected]" -Wait -Verbose | |
} | |
catch | |
{ | |
$null = [System.Windows.Forms.MessageBox]::Show($Error[0].Exception.Message, "Warning", [System.Windows.Forms.MessageBoxButton]::OK, [System.Windows.Forms.MessageBoxImage]::Exclamation) | |
} | |
} | |
else | |
{ | |
$Script:dialog = [System.Windows.Forms.OpenFileDialog]::new() | |
$Script:dialog.CheckFileExists = $true | |
$Script:dialog.CheckPathExists = $true | |
$Script:dialog.DefaultExt = '.pol' | |
$Script:dialog.Filter = 'Registry Policy file (*.pol)|*.pol' | |
$Script:dialog.Title = 'Open a registry.pol file' | |
$Script:dialog.Multiselect = $false | |
$Script:response = $Script:dialog.ShowDialog() | |
if($Script:response -eq 'OK') | |
{ | |
try | |
{ | |
Read-PolFile -Path $Script:dialog.FileName | Out-GridView -Title "Registry.Pol Content [$($Script:dialog.FileName)]" -Wait -Verbose | |
} | |
catch | |
{ | |
$null = [System.Windows.Forms.MessageBox]::Show($Error[0].Exception.Message, "Warning", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Exclamation) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following is required on line 6 if you want to be able to run this directly from PowerShell Console instead of ISE.
Add-Type -AssemblyName PresentationFramework
Read More about it here:
https://inthetechpit.com/2019/12/05/unable-to-find-type-system-windows-messagebox-error-powershell/