/// <summary>Method for getting the basekey + subkeys from the path input as a Dictionary.</summary> internal static RegistryProperty[] GetRegistryProperty(RegistryKey regKey, RegistryValueOptions valueOptions, bool includeValueKind) { string[] valueNames = regKey.GetValueNames(); RegistryValueKind valueKind = RegistryValueKind.Unknown; RegistryProperty[] returnData = new RegistryProperty[valueNames.Length]; for (int i = 0; i < valueNames.Length; i++) { object value = regKey.GetValue(valueNames[i], null, valueOptions); if (includeValueKind) { valueKind = regKey.GetValueKind(valueNames[i]); } returnData[i] = new RegistryProperty() { Name = valueNames[i], ValueKind = valueKind, Value = value }; } return(returnData); }
/// <summary>Method for adding additional members to RegistryKey objects and writing them to the Powershell pipeline.</summary> internal static void WriteRegKeyToPipeline(Cmdlet cmdlet, RegistryKey regKey, string pcName, bool keyOnly, RegistryValueOptions valueOptions, bool includeValueKind) { PSObject objectToWrite = new PSObject(regKey); objectToWrite.TypeNames.Insert(0, "Microsoft.Win32.RegistryKey#PSRegistry"); objectToWrite.Members.Add(new PSNoteProperty("ComputerName", pcName), true); RegistryProperty[] registryProperties = new RegistryProperty[0]; if (!keyOnly) { try { registryProperties = GetRegistryProperty(regKey, valueOptions, includeValueKind); } catch (Exception e) when(e is PipelineStoppedException == false) { cmdlet.WriteError(new ErrorRecord(e, "UnableToGetProperties", GetErrorCategory(e), regKey)); } } objectToWrite.Members.Add(new PSNoteProperty("Property", registryProperties), true); cmdlet.WriteObject(objectToWrite); }