How To Edit The Windows Registry In PowerShell

Question

How can I access the Windows Registry in PowerShell so I can create, update and delete keys and values?

Short Answer

Use the Get-ItemProperty and Set-ItemProperty Cmdlets:

# get the data from a specific registry key value
Get-ItemProperty "HKLM:\SOFTWARE\MyRegistryKey" |
    % { $_.MyKeyValue };

# set the data for a specific registry key value
Set-ItemProperty "HKLM:\SOFTWARE\MyRegistryKey" -Name "MyKeyValue" -Value "Some Data";

Long Answer

When playing with the Windows Registry, the common Item Cmdlets are our friends:

Continue reading “How To Edit The Windows Registry In PowerShell”

Advertisements

How To Grab Windows SIDs with PowerShell

There are those times where you just need those SIDs, no matter what door you knock on.
For those fateful times, you can use this snippet of code to grab the SID from a given target user.

#this is the target user name
$username = "SomeDomainSomeUserName";

# get the account object
$account = New-Object System.Security.Principal.NTAccount $username;

# then get the sid value from it
$sid = $account.Translate([System.Security.Principal.SecurityIdentifier]).Value;

# or just do it all at once
$sid = (New-Object System.Security.Principal.NTAccount $username).Translate([System.Security.Principal.SecurityIdentifier]).Value;

Index: PowerShell HowTo’s