Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##############################################################################
- ##
- ## Get-RemoteRegistryKeyProperty.ps1
- ##
- ## Get the value of a remote registry key property
- ##
- ## ie:
- ##
- ## PS >$registryPath =
- ## "HKLM:\software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell"
- ## PS >Get-RemoteRegistryKeyProperty LEE-DESK $registryPath "ExecutionPolicy"
- ##
- ##############################################################################
- param(
- $ComputerName = $(Throw "Please specify a ComputerName name."),
- $path = $(Throw "Please specify a registry path"),
- $property = "*"
- )
- ## Validate and extract out the registry key
- if($path -match "^HKLM:\\(.*)")
- {
- $baseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(
- "LocalMachine", $ComputerName)
- }
- elseif($path -match "^HKCU:\\(.*)")
- {
- $baseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(
- "CurrentUser", $ComputerName)
- }
- else
- {
- Write-Error ("Please specify a fully-qualified registry path " +
- "(i.e.: HKLM:\Software) of the registry key to open.")
- return
- }
- ## Open the key
- $key = $baseKey.OpenSubKey($matches[1])
- $returnObject = New-Object PsObject
- ## Go through each of the properties in the key
- foreach($keyProperty in $key.GetValueNames())
- {
- ## If the property matches the search term, add it as a
- ## property to the output
- if($keyProperty -like $property)
- {
- $returnObject |
- Add-Member NoteProperty $keyProperty $key.GetValue($keyProperty)
- }
- }
- ## Return the resulting object
- $returnObject
- ## Close the key and base keys
- $key.Close()
- $baseKey.Close()
Advertisement
Add Comment
Please, Sign In to add comment