Created
August 1, 2017 12:03
-
-
Save matt2005/8f773a42c0757cd36ec332c6b8d546b1 to your computer and use it in GitHub Desktop.
Get-RegistryKeyType
This file contains hidden or 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
Function Get-RegistryKeyType | |
{ | |
# https://msdn.microsoft.com/en-us/library/windows/desktop/ms724884(v=vs.85).aspx | |
param( | |
$Path, | |
$key | |
) | |
$SplitRegPath = $Path.Split(':\') | |
$Path = $Path.Replace($('{0}:\' -f $SplitRegPath[0]),'') | |
Switch -regex ($SplitRegPath[0]){ | |
HKLM | |
{ | |
$main = 'LocalMachine' | |
} | |
HKCU | |
{ | |
$main = 'CurrentUser' | |
} | |
HKU | |
{ | |
$main = 'Users' | |
} | |
Default | |
{ | |
$main = 'LocalMachine' | |
} | |
} | |
$reg = [Microsoft.Win32.RegistryKey]::OpenBaseKey($main,'Default') | |
$regKey = $reg.OpenSubKey($Path,$True) | |
Switch ($regKey.GetValueKind($key)){ | |
'Binary' | |
{ | |
return 'REG_BINARY' | |
} | |
'Dword' | |
{ | |
return 'REG_DWORD' | |
} | |
'Qword' | |
{ | |
return 'REG_QWORD' | |
} | |
'MultiString' | |
{ | |
return 'REG_MULTI_SZ' | |
} | |
'ExpandString' | |
{ | |
return 'REG_EXPAND_SZ' | |
} | |
'String' | |
{ | |
return 'REG_SZ' | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment