private void CreateKeyCmd(StringBuilder builder, string parentKey, WindowsRegistrySubKey key) { string keyPath = parentKey + @"\" + key.KeyName; builder.AppendLine(string.Format(@"New-Item -Path ""Microsoft.PowerShell.Core\Registry::{0}"" {1} -force", keyPath, string.IsNullOrWhiteSpace(key.DefaultValue) ? "" : "-Value " + "\"" + key.DefaultValue + "\"")); foreach (var value in key.Values) { CreateValueCmd(builder, keyPath, value); } foreach (var subKey in key.Keys) { CreateKeyCmd(builder, keyPath, subKey); } }