Skip to content

Instantly share code, notes, and snippets.

@mcc85s
Last active November 10, 2022 15:38
Show Gist options
  • Save mcc85s/5ddfac5899b31751156bca57d2091b79 to your computer and use it in GitHub Desktop.
Save mcc85s/5ddfac5899b31751156bca57d2091b79 to your computer and use it in GitHub Desktop.
Class CustomProperty
{
[UInt32] $Index
Hidden [String] $Path
Hidden [Object] $Property
[String] $Name
[Object] $Value
[UInt32] $Exists
[Object] $Target
[UInt32] $Compliant
CustomProperty([UInt32]$Index,[String]$Path,[String]$Name,[Object]$Target)
{
$This.Index = $Index
$This.Path = $Path
$This.Name = $Name
$This.Target = $Target
$This.GetProperty()
}
GetProperty()
{
$This.Property = Get-ItemProperty -Path $This.Path -Name $This.Name -EA 0
If (!$This.Property)
{
$This.Exists = 0
$This.Value = $Null
$This.Compliant = 0
}
Else
{
$This.Exists = 1
$This.Value = $This.Property.$($This.Name)
$This.Compliant = $This.Current -eq $This.Target
}
}
[Void] SetProperty()
{
Set-Property -Path $This.Path -Name $This.Name -Value $This.Value -Verbose
$This.GetProperty()
}
[Void] NewProperty()
{
New-ItemProperty -Path $This.Path -Name $This.Name -Verbose
$This.GetProperty()
}
}
Class CustomPropertyList
{
[String] $Path
[UInt32] $Exists
[Object] $Output
CustomPropertyList([String]$Path)
{
$This.Path = $Path
$This.Exists = Test-Path $This.Path
$This.Output = @( )
}
Add([String]$Name,[Object]$Target)
{
$This.Output += [CustomProperty]::New($This.Output.Count,$This.Path,$Name,$Target)
}
Set()
{
ForEach ($Item in $This.Output)
{
$Item.GetProperty()
If (!$Item.Exists)
{
$Item.NewProperty()
}
If (!$Item.Compliant)
{
$Item.SetProperty()
}
}
}
}
$List = [CustomPropertyList]::New("HKCU:\Control Panel\Desktop")
$List.Add("Win8DPIScaling",1)
$List.Add("LogPixels",120)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment