{"id":54653,"date":"2009-01-08T11:52:00","date_gmt":"2009-01-08T11:52:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2009\/01\/08\/hey-scripting-guy-how-can-i-configure-the-cmd-console-via-the-registry\/"},"modified":"2009-01-08T11:52:00","modified_gmt":"2009-01-08T11:52:00","slug":"hey-scripting-guy-how-can-i-configure-the-cmd-console-via-the-registry","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-configure-the-cmd-console-via-the-registry\/","title":{"rendered":"Hey, Scripting Guy! How Can I Configure the Cmd Console via the Registry?"},"content":{"rendered":"<h2><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> <\/h2>\n<p>Hey, Scripting Guy! You know, it just dawned on me that Windows PowerShell uses the old-fashioned <a href=\"http:\/\/en.wikipedia.org\/wiki\/Fred_Flintstone\" target=\"_blank\">Fred Flintstone<\/a> cmd console for its host application. Because this thing has been around forever, are there any registry settings I can use to configure this beast? The reason I am asking is that every time I go to a new machine, I need to right-click the little icon, open up the property page, and make my configuration settings. I would love to be able to run a script that would set things up the way I wish. Can you help?<\/p>\n<p>&#8211; BP<\/p>\n<p><img decoding=\"async\" height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"><\/p>\n<p>Hi BP,<\/p>\n<p>Fred Flintstone does DOS (dinosaur operating system). You are, however, correct that Windows PowerShell uses the old-fashioned cmd console and as such can be configured via the registry. But before we get too far into answering your question, please stand by for a few words from our sponsors. <\/p>\n<table class=\"dataTable\" id=\"E2C\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\"><b>Standard disclaimer<\/b>: The script today talks about editing the registry. <b>Microsoft does not support editing the registry, because you can really mess stuff up if you are not careful.<\/b> If your script causes your computer to jump off your desk and bite the postman, please send us the script because we would love to see something like that. If you gain massive amounts of weight and all your hair falls out, don\u2019t send us your script; we already have enough problems in that arena. If your pet rabbit gets an unquenchable desire for <a href=\"http:\/\/www.aussieslang.com\/features\/anzac-biscuits.asp\" target=\"_blank\">Anzak biscuits<\/a> and starts listening to Olivia Newton John songs, don&#8217;t say we didn&#8217;t warn you. <b>Please back up your registry before proceeding to run the script.<\/b> Back up everything you don&#8217;t want to lose just to be on the safe side. <\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>The first thing you should do before working with the registry is make sure you are either working in a virtual machine that allows you to roll back changes if you wish, or ensure you have a good backup of the registry. Jerry Honeycutt has written a number of <a href=\"http:\/\/www.microsoft.com\/learning\/en\/us\/books\/8762.aspx\" target=\"_blank\">good books about the registry<\/a> for Microsoft Press, as well as a number of excellent articles <a href=\"http:\/\/www.microsoft.com\/windowsxp\/using\/setup\/expert\/honeycutt_03march17.mspx\" target=\"_blank\">such as this one<\/a>. By the way, in case you do not know, you can download <a href=\"http:\/\/www.microsoft.com\/windows\/downloads\/virtualpc\/default.mspx\" target=\"_blank\">Microsoft Virtual PC 2007<\/a> for free. <\/p>\n<p>For a good overview of the registry, you can refer to <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/guide\/sas_reg_fzit.mspx?mfr=true\" target=\"_blank\">this article<\/a>. To explore the registry, you can use the <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/tools\/twkmatic.mspx\" target=\"_blank\">Tweakomatic<\/a>, which produces scripts in VBScript. Here is a good <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/begin\/ss0807.mspx\" target=\"_blank\">Sesame Script article<\/a> that gives an overview of the registry. And here is the <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/scripts\/os\/registry\/default.mspx\" target=\"_blank\">Script Center registry archive<\/a>. <\/p>\n<p>Today&#8217;s script allows us to retrieve and configure a number of console settings. In this script, we will also illustrate using a class from the .NET Framework. Here\u2019s today\u2019s&nbsp;script:<\/p>\n<pre class=\"codeSample\">Param([switch]$get,[switch]$set)\nFunction Get-Settings()\n{\n $hklm = \"HKEY_CURRENT_USER\"\n $key = \"Console\"\n $properties = \"QuickEdit\",\"FullScreen\",\"InsertMode\"\n Foreach ($property in $properties)\n  {\n   $property + \": \" + [Microsoft.Win32.Registry]::GetValue(\"$hklm\\$key\",$property,$null)\n  }\n} #end Get-Settings\nFunction Set-Settings()\n{\n $hklm = \"HKEY_CURRENT_USER\"\n $key = \"Console\"\n $hash = @{\"QuickEdit\" = 1 ; \"FullScreen\" = 0 ; \"InsertMode\" = 1 }\n Foreach($name in $hash.keys)\n {\n  \"Changing \" + $name + \" to \" + $hash[$name]\n  [Microsoft.Win32.Registry]::SetValue(\"$hklm\\$key\",$name,$hash[$name])\n }\n} #end Set-Settings\n# *** Entry Point To Script ***\nif($get) {Get-Settings}\nif($set) {Set-Settings}\n<\/pre>\n<p>As mentioned earlier, the cmd console has a number of properties that can be configured via the registry. These settings are seen here:<\/p>\n<p><img decoding=\"async\" height=\"362\" alt=\"Image of cmd console properties that can be configured via the registry\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/january\/hey0108\/hsg_1_8_09_01.jpg\" width=\"500\" border=\"0\"><\/p>\n<p>&nbsp;<\/p>\n<p>In our script, the first thing we do is create a couple of command-line parameters. To do this, we use the <b>Param<\/b> statement. This statement must be the first non-commented line in the script. We use the <b>switchparameter<\/b> structure, which has a type alias of <b>[switch]<\/b> to convert our command-line parameter into a switched parameter. A switched parameter only has effect when it is present on the command line. Suppose, for example, we run the script with a command line such as the one seen here:<\/p>\n<pre class=\"codeSample\">GetSetConsoleSettings.ps1 \u2013get<\/pre>\n<p>Then the script will only retrieve the console settings. If we run it with the <b>\u2013set<\/b> switch, it will only set the console settings. One of the cool things about command-line parameters is that you do not need to type the entire parameter name. You can, for instance, run the script as shown here: <\/p>\n<pre class=\"codeSample\">GetSetConsoleSettings.ps1 \u2013g -s<\/pre>\n<p>The line of code that creates the command-line parameters is shown here: <\/p>\n<pre class=\"codeSample\">Param([switch]$get,[switch]$set)<\/pre>\n<p>We now need to create the <b>Get-Settings<\/b> function. To do this, we use the <b>function<\/b> key word as illustrated here: <\/p>\n<pre class=\"codeSample\">Function Get-Settings()<\/pre>\n<p>We then create a few variables. The first variable, <b>$hklm<\/b>, represents the registry hive of HKEY_CURRENT_USER, although we could have called it anything we wish. The second variable is the registry key we wish to work with, which is the console key. These two variables are seen&nbsp;here:<\/p>\n<pre class=\"codeSample\"> $hklm = \"HKEY_CURRENT_USER\"\n $key = \"Console\"\n<\/pre>\n<p>We also create an array of property names. This will allow us to minimize the amount of code that we need to write, and it is actually a pretty cool way to retrieve the property values. To create an array in Windows PowerShell, we need only assign more than one item to the variable. As seen here, when we assign multiple items to the variable, it is automatically an array. When we query the variable, it will spit out all of the items by default:<\/p>\n<pre class=\"codeSample\">PS C:\\&gt; $a = 1,2,3\nPS C:\\&gt; $a\n1\n2\n3\n<\/pre>\n<p>If we need to retrieve a specific item from the array, we can do so by using the element number, beginning with 0. This is seen&nbsp;here: <\/p>\n<pre class=\"codeSample\">PS C:\\&gt; $a[0]\n1\nPS C:\\&gt; $a[1]\n2\nPS C:\\&gt; $a[2]\n3\n<\/pre>\n<p>If we are interested in seeing all of the items, one element at a time, we could use the <b>For\u2026Next<\/b> loop (except that Windows PowerShell does not use a <b>next<\/b> at the end of the <b>for<\/b> loop; so I guess it is really only a <b>for<\/b> loop.) This is seen here:<\/p>\n<pre class=\"codeSample\">for($i = 0 ; $i -le $a.length -1 ; $i++) {$a[$i]}<\/pre>\n<p>It might make more sense, if we used the <b>foreach<\/b> statement. This is because the <b>foreach<\/b> statement does not require us to increment a counter variable, as the <b>for<\/b> statement did. Notice how much simpler this code&nbsp;appears:<\/p>\n<pre class=\"codeSample\">PS C:\\&gt; Foreach($i in $a) {$i}\n1\n2\n3\n<\/pre>\n<p>The array of property names is shown here: <\/p>\n<pre class=\"codeSample\"> $properties = \"QuickEdit\",\"FullScreen\",\"InsertMode\"<\/pre>\n<p>To work through the array of property names, we decide to use the <b>foreach<\/b> statement, as seen here: <\/p>\n<pre class=\"codeSample\"> Foreach ($property in $properties)<\/pre>\n<p>Then we call the static <b>GetValue<\/b> method from the <b>Microsoft.Win32.Registry<\/b> .NET Framework class. When we do this, we need to give the <b>GetValue<\/b> the registry root name with the key name, the property name, and a default value for the registry key, if it is not present. Valid root names are listed here:<\/p>\n<table class=\"\" cellSpacing=\"0\" cellPadding=\"0\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"listBullet\" vAlign=\"top\">\u2022<\/td>\n<td class=\"listItem\">\n<p>HKEY_CURRENT_USER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"listBullet\" vAlign=\"top\">\u2022<\/td>\n<td class=\"listItem\">\n<p>HKEY_LOCAL_MACHINE<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"listBullet\" vAlign=\"top\">\u2022<\/td>\n<td class=\"listItem\">\n<p>HKEY_CLASSES_ROOT<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"listBullet\" vAlign=\"top\">\u2022<\/td>\n<td class=\"listItem\">\n<p>HKEY_USERS<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"listBullet\" vAlign=\"top\">\u2022<\/td>\n<td class=\"listItem\">\n<p>HKEY_PERFORMANCE_DATA<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"listBullet\" vAlign=\"top\">\u2022<\/td>\n<td class=\"listItem\">\n<p>HKEY_CURRENT_CONFIG<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"listBullet\" vAlign=\"top\">\u2022<\/td>\n<td class=\"listItem\">\n<p>HKEY_DYN_DATA<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>In our script, we are interested in printing out the value that is contained in the registry key property. We use the variable <b>$property<\/b> and concatenate the string with the value returned from the <b>GetValue<\/b> static method. This is shown here: <\/p>\n<pre class=\"codeSample\">  {\n   $property + \": \" + [Microsoft.Win32.Registry]::GetValue(\"$hklm\\$key\",$property,$null)\n  }\n} #end Get-Settings\n<\/pre>\n<p>It is time to create the <b>Set-Settings<\/b> function. We once again use the function key word: <\/p>\n<pre class=\"codeSample\">Function Set-Settings()<\/pre>\n<p>You can probably guess what comes next. Sure, we need to define some more variables and set their associated values. These are the same two variables we used in the previous&nbsp;function:<\/p>\n<pre class=\"codeSample\">{\n $hklm = \"HKEY_CURRENT_USER\"\n $key = \"Console\"\n<\/pre>\n<p>Now let&#8217;s get a bit more sophisticated. Yes, it is time for a spot of tea in my new tea pot the Scripting Wife gave me for Christmas, complete with an assortment of loose leaf teas in their own little tin canisters. I think that Earl Grey tea will do nicely on this rainy Charlotte, NC, USA, afternoon. If only I could steal some Anzak biscuits from the neighbor\u2019s pet rabbit. I am back. The little dude ate all the biscuits. Oh, well.<\/p>\n<p>When we create a hash table, we use a variable to hold it, and use the special ampersand character followed with a couple of curly brackets. Each name\/value pair is assigned by using the equal sign and separated by a semicolon. As seen here, when you call the variable by itself, it prints out all the name\/value&nbsp;pairs: <\/p>\n<pre class=\"codeSample\">PS C:\\&gt; $hash = @{\"QuickEdit\" = 1 ; \"FullScreen\" = 0 ; \"InsertMode\" = 1 }\nPS C:\\&gt; $hash\nName                           Value\n----                           -----\nInsertMode                     1\nQuickEdit                      1\nFullScreen                     0\n<\/pre>\n<p>Because this is Windows PowerShell and everything in Windows PowerShell is an object, this means that the <b>$hash<\/b> variable contains an object. In fact, it is the same object you would use in C# or in VB.NET: the <b>System.Collections.Hashtable<\/b> class. The <b>System.Collections.Hashtable<\/b> class has the members shown in Table 1.<\/p>\n<p><b>Table 1 WMI registry tree values<\/b><\/p>\n<table class=\"dataTable\" id=\"E5AAC\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead>\n<tr class=\"stdHeader\" vAlign=\"top\">\n<td class=\"\" id=\"colEABAC\">Name<\/td>\n<td class=\"\" id=\"colEEBAC\">Member Type<\/td>\n<td class=\"\" id=\"colEIBAC\">Definition<\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Add<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Void Add(Object key, Object value)<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Clear<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Void Clear()<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Clone<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Object Clone()<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Contains<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean Contains(Object key)<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">ContainsKey<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean ContainsKey(Object key)<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">ContainsValue<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean ContainsValue(Object value)<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">CopyTo<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Void CopyTo(Array array, Int32 arrayIndex)<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Equals<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean Equals(Object obj)<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">GetEnumerator<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Collections.IDictionaryEnumerator GetEnumerator()<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">GetHashCode<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Int32 GetHashCode()<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">GetObjectData<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Void GetObjectData(SerializationInfo info, StreamingContext context)<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">GetType<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Type GetType()<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">get_Count<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Int32 get_Count()<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">get_IsFixedSize<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean get_IsFixedSize()<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">get_IsReadOnly<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean get_IsReadOnly()<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">get_IsSynchronized<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean get_IsSynchronized()<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">get_Item<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Object get_Item(Object key)<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">get_Keys<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Collections.ICollection get_Keys()<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">get_SyncRoot<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Object get_SyncRoot()<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">get_Values<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Collections.ICollection get_Values()<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">On_Deserialization<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Void OnDeserialization(Object sender)<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Remove<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Void Remove(Object key)<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">set_Item<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Void set_Item(Object key, Object value)<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">ToString<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String ToString()<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Item<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">ParameterizedProperty<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Object Item(Object key) {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Count<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Int32 Count {get;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">IsFixedSize<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean IsFixedSize {get;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">IsReadOnly<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean IsReadOnly {get;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">IsSynchronized<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean IsSynchronized {get;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Keys<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Collections.ICollection Keys {get;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">SyncRoot<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Object SyncRoot {get;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Values<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Collections.ICollection Values {get;} <\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>By playing around with the methods and properties from the <b>HashTable<\/b> class, you can leverage this object to allow you to do some rather clever things. As an example, see how easy it is to find out if we have the value <b>5<\/b> in our hash&nbsp;table:<\/p>\n<pre class=\"codeSample\">PS C:\\&gt; $hash.ContainsValue(1)\nTrue\nPS C:\\&gt; $hash.ContainsValue(5)\nFalse\n<\/pre>\n<p>At any rate, here is the line of code that creates the <b>HashTable<\/b> for our script:<\/p>\n<pre class=\"codeSample\">$hash = @{\"QuickEdit\" = 1 ; \"FullScreen\" = 0 ; \"InsertMode\" = 1 }<\/pre>\n<p>To walk through the <b>HashTable<\/b>, we can use <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/begin\/ss0906.mspx\" target=\"_blank\">this trick<\/a> from the VBScript days. We obtain a collection of all the keys in the <b>HashTable<\/b> by using the keys property, and we use the <b>$name<\/b> variable with the <b>foreach<\/b> statement as our enumerator. This is seen here: <\/p>\n<pre class=\"codeSample\"> Foreach($name in $hash.keys)<\/pre>\n<p>We now print out just a bit of confirmation by indexing into the <b>HashTable<\/b> via the <b>$name<\/b> variable. We also concatenate the <b>$name<\/b> variable with the value associated with name from the hash table. This is seen here: <\/p>\n<pre class=\"codeSample\"> {  \"Changing \" + $name + \" to \" + $hash[$name] <\/pre>\n<p>Next we use the <b>SetValue<\/b> static method from the <b>Microsoft.Win32.Registry<\/b> .NET Framework class. The <b>SetValue<\/b> static method takes the registry hive and registry key in the first position. The second position is the name of the property, and the third position is the value to assign to that property. This is seen here: <\/p>\n<pre class=\"codeSample\">  [Microsoft.Win32.Registry]::SetValue(\"$hklm\\$key\",$name,$hash[$name])\n }\n} #end Set-Settings\n<\/pre>\n<p>Now we need to check the command-line parameters. To do this, we use an <b>if<\/b> statement. If the variable exists, we call the appropriate function. This is seen&nbsp;here:<\/p>\n<pre class=\"codeSample\">if($get) {Get-Settings}\nif($set) {Set-Settings}\n<\/pre>\n<p>Well&nbsp;BP, I hope you have enjoyed registry week. I tried to show you different ways to do the same kinds of things. Along the way, we also picked up some decent tricks for working with Windows PowerShell. Join us tomorrow for Quick-Hits Friday where we will explore some more hot topics fresh from the <b>scripter@microsoft.com<\/b> inbox (I have finally caught it up by the way). Until then, take care and don&#8217;t download any <a href=\"http:\/\/en.wikipedia.org\/wiki\/Dancing_baby\" target=\"_blank\">dancing babies<\/a>.<\/p>\n<p><font class=\"Apple-style-span\" face=\"Verdana\" size=\"3\"><span class=\"Apple-style-span\"><b><b>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/b><\/b><\/span><\/font><\/p>\n<p><font class=\"Apple-style-span\" face=\"Verdana\" size=\"3\"><b><\/b><\/font><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! You know, it just dawned on me that Windows PowerShell uses the old-fashioned Fred Flintstone cmd console for its host application. Because this thing has been around forever, are there any registry settings I can use to configure this beast? The reason I am asking is that every time I go to [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[16,31,26,3,45],"class_list":["post-54653","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-desktop-management","tag-operating-system","tag-registry","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! You know, it just dawned on me that Windows PowerShell uses the old-fashioned Fred Flintstone cmd console for its host application. Because this thing has been around forever, are there any registry settings I can use to configure this beast? The reason I am asking is that every time I go to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/54653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=54653"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/54653\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=54653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=54653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=54653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}