Skip to content

Instantly share code, notes, and snippets.

@CKurti-MCMTSG
Forked from zbalkan/RegistryPolViewer.ps1
Last active July 26, 2023 02:40
Show Gist options
  • Save CKurti-MCMTSG/3cf2bb22948907326d258ee0321ccd9d to your computer and use it in GitHub Desktop.
Save CKurti-MCMTSG/3cf2bb22948907326d258ee0321ccd9d to your computer and use it in GitHub Desktop.
Registry.Pol Viewer
#Requires -Modules GPRegistryPolicyParser
#Requires -Version 5
Import-Module -Name GPRegistryPolicyParser -WarningAction Ignore
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName PresentationFramework
$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