Skip to content

Instantly share code, notes, and snippets.

@matt2005
Created August 1, 2017 12:03
Show Gist options
  • Save matt2005/8f773a42c0757cd36ec332c6b8d546b1 to your computer and use it in GitHub Desktop.
Save matt2005/8f773a42c0757cd36ec332c6b8d546b1 to your computer and use it in GitHub Desktop.
Get-RegistryKeyType
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