Memoru

System Engineering and Programming and IT

1908-powershell-hashtable

1908-powershell-hashtable

overview

Image from Gyazo

jupyter notebook

Usage

basic

In [1]:
$d = @{
  'script' = 'powershell'
  'os' = 'windows 10'
  'date' = Get-Date
}

In [2]:
$d
Name                           Value                                                                                   
----                           -----                                                                                   
date                           02/09/2019 13:47:21                                                                     
script                         powershell                                                                              
os                             windows 10                                                                              


In [3]:
$d['script']
In [4]:
$d.GetType()
IsPublic IsSerial Name                                     BaseType                                                    
-------- -------- ----                                     --------                                                    
True     True     Hashtable                                System.Object                                               


In [5]:
$d['os'].GetType()
IsPublic IsSerial Name                                     BaseType                                                    
-------- -------- ----                                     --------                                                    
True     True     String                                   System.Object                                               


In [6]:
$d['date'].GetType()
IsPublic IsSerial Name                                     BaseType                                                    
-------- -------- ----                                     --------                                                    
True     True     DateTime                                 System.ValueType                                            


Get-Help

In [7]:
Get-Help -Category HelpFile | where-object {$_.Name -match "hash"}
Name                              Category  Module                    Synopsis                                         
----                              --------  ------                    --------                                         
about_Hash_Tables                 HelpFile                            Describes how to create, use, and sort hash ta...


In [72]:
Get-Help about_Hash* | set -Name store
$store -split "`r`n" | set -Name ary_store
$ary_store[0..25] + 'and more .....'
Get-Help about_Hash* | set -Name store
$store -split "`r`n" | set -Name ary_store
$ary_store[0..25] + 'and more .....'
TOPIC
    about_Hash_Tables

SHORT DESCRIPTION
    Describes how to create, use, and sort hash tables in Windows PowerShell.


LONG DESCRIPTION
    A hash table, also known as a dictionary or associative array, is a
    compact data structure that stores one or more key/value pairs. For
    example, a hash table might contain a series of IP addresses and
    computer names, where the IP addresses are the keys and the computer
    names are the values, or vice versa.

    In Windows PowerShell, each hash table is a Hashtable 
    (System.Collections.Hashtable) object.  You can use the properties
    and methods of Hashtable objects in Windows PowerShell.

    Beginning in Windows PowerShell 3.0, you can use the [ordered]
    attribute to create an ordered dictionary
    (System.Collections.Specialized.OrderedDictionary) in Windows PowerShell.
    
    Ordered dictionaries differ from hash tables in that the keys always
    appear in the order in which you list them. The order of keys in a hash
    table is not determined.

and more .....


Initialize

Empty object

In [74]:
$dic = @{}

truthiness and falsiness
In [10]:
if($dic){'true'}else{'false'}
true
In [11]:
if($dic.Count){'true'}else{'false'}
false
In [12]:
$dic.Count
0

Get-Member

In [78]:
$dic | Get-Member -MemberType Property | select Name, Definition
Name           Definition                                  
----           ----------                                  
Count          int Count {get;}                            
IsFixedSize    bool IsFixedSize {get;}                     
IsReadOnly     bool IsReadOnly {get;}                      
IsSynchronized bool IsSynchronized {get;}                  
Keys           System.Collections.ICollection Keys {get;}  
SyncRoot       System.Object SyncRoot {get;}               
Values         System.Collections.ICollection Values {get;}


In [14]:
$dic | Get-Member -MemberType Method | Format-Table Name, Definition
Name              Definition                                                                                           
----              ----------                                                                                           
Add               void Add(System.Object key, System.Object value), void IDictionary.Add(System.Object key, System.O...
Clear             void Clear(), void IDictionary.Clear()                                                               
Clone             System.Object Clone(), System.Object ICloneable.Clone()                                              
Contains          bool Contains(System.Object key), bool IDictionary.Contains(System.Object key)                       
ContainsKey       bool ContainsKey(System.Object key)                                                                  
ContainsValue     bool ContainsValue(System.Object value)                                                              
CopyTo            void CopyTo(array array, int arrayIndex), void ICollection.CopyTo(array array, int index)            
Equals            bool Equals(System.Object obj)                                                                       
GetEnumerator     System.Collections.IDictionaryEnumerator GetEnumerator(), System.Collections.IDictionaryEnumerator...
GetHashCode       int GetHashCode()                                                                                    
GetObjectData     void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serializati...
GetType           type GetType()                                                                                       
OnDeserialization void OnDeserialization(System.Object sender), void IDeserializationCallback.OnDeserialization(Syst...
Remove            void Remove(System.Object key), void IDictionary.Remove(System.Object key)                           
ToString          string ToString()                                                                                    


Methods

In [15]:
$dic = @{}
$dic | Get-Member -MemberType Method | foreach-object { $_.Name}
$dic = @{}
$dic | Get-Member -MemberType Method | foreach-object { $_.Name} 
Add
Clear
Clone
Contains
ContainsKey
ContainsValue
CopyTo
Equals
GetEnumerator
GetHashCode
GetObjectData
GetType
OnDeserialization
Remove
ToString


Add

In [18]:
$dic = @{}

In [19]:
$dic.Add('one', 1)
$dic.Add('Two', 2)
$dic.Add('Three', 3)
$dic.Add('one', 1)
$dic.Add('Two', 2)
$dic.Add('Three', 3)

In [20]:
$dic
Name                           Value                                                                                   
----                           -----                                                                                   
one                            1                                                                                       
Three                          3                                                                                       
Two                            2                                                                                       


foreach

In [21]:
foreach($itm in $dic.GetEnumerator())
{
  echo $itm.Key $itm.Value
}
one
1
Three
3
Two
2
In [22]:
foreach($key in $dic.Keys)
{
  echo $Key ($dic[$key] + 10)
}
one
11
Three
13
Two
12

contains

In [23]:
$dic
Name                           Value                                                                                   
----                           -----                                                                                   
one                            1                                                                                       
Three                          3                                                                                       
Two                            2                                                                                       


In [24]:
$dic.Contains('one')
True
In [25]:
$dic.Contains('four')
False
In [26]:
$dic.ContainsValue(4)
False
In [27]:
$dic.ContainsValue(2)
True

Remove and Clear

In [28]:
$dic
Name                           Value                                                                                   
----                           -----                                                                                   
one                            1                                                                                       
Three                          3                                                                                       
Two                            2                                                                                       


In [29]:
$dic.Remove('Two')

In [30]:
$dic
Name                           Value                                                                                   
----                           -----                                                                                   
one                            1                                                                                       
Three                          3                                                                                       


In [31]:
$dic.Remove('Four')

In [32]:
$dic
Name                           Value                                                                                   
----                           -----                                                                                   
one                            1                                                                                       
Three                          3                                                                                       


In [33]:
$dic.Clear()

In [34]:
echo "dic = $dic"
dic = System.Collections.Hashtable
In [35]:
echo "dic---" $dic "+++"
dic---
+++

Clone

In [36]:
$dic_org = @{
  'first' = '1st'
  'second' = '2nd'
  'third' = '3rd'
  'fourth' = '4th'
}

In [37]:
$dic_org
Name                           Value                                                                                   
----                           -----                                                                                   
third                          3rd                                                                                     
first                          1st                                                                                     
second                         2nd                                                                                     
fourth                         4th                                                                                     


In [38]:
$dic_dist = $dic_org

In [39]:
$dic_dist['first'] = '1st step'

In [40]:
$dic_dist
Name                           Value                                                                                   
----                           -----                                                                                   
third                          3rd                                                                                     
first                          1st step                                                                                
second                         2nd                                                                                     
fourth                         4th                                                                                     


In [41]:
$dic_org
Name                           Value                                                                                   
----                           -----                                                                                   
third                          3rd                                                                                     
first                          1st step                                                                                
second                         2nd                                                                                     
fourth                         4th                                                                                     


In [42]:
$dic_dist_deep = $dic_org.Clone()
$dic_dist_deep['first'] = '1st'
$dic_dist_deep = $dic_org.Clone()
$dic_dist_deep['first'] = '1st'

In [43]:
$dic_dist_deep['first']
1st
In [44]:
$dic_org['first']
1st step

hash -> string

In [45]:
$dic_for_conv = @{
  'one' = 1
  'two' = 2
  'three' = 3
}
$dic_for_conv = @{
>>   'one' = 1
>>   'two' = 2
>>   'three' = 3
>> }
>> 

In [46]:
$dic_for_conv
Name                           Value                                                                                   
----                           -----                                                                                   
one                            1                                                                                       
three                          3                                                                                       
two                            2                                                                                       


In [47]:
write-host $dic_for_conv
System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry
In [48]:
echo "dic_for_conv = $dic_for_conv"
dic_for_conv = System.Collections.Hashtable
In [49]:
echo "dic_for_conv = " $dic_for_conv
dic_for_conv = 

Name                           Value                                                                                   
----                           -----                                                                                   
one                            1                                                                                       
three                          3                                                                                       
two                            2                                                                                       


In [50]:
$dic_for_conv.ToString()
System.Collections.Hashtable
In [51]:
$dic_for_conv | Convertto-Csv
#TYPE System.Collections.Hashtable
"IsReadOnly","IsFixedSize","IsSynchronized","Keys","Values","SyncRoot","Count"
"False","False","False","System.Collections.Hashtable+KeyCollection","System.Collections.Hashtable+ValueCollection","System.Object","3"
  • Convertto-Csv Image from Gyazo
In [52]:
$dic_for_conv | Convertto-Csv -NoTypeInformation
"IsReadOnly","IsFixedSize","IsSynchronized","Keys","Values","SyncRoot","Count"
"False","False","False","System.Collections.Hashtable+KeyCollection","System.Collections.Hashtable+ValueCollection","System.Object","3"
In [53]:
$dic_for_conv | Get-Member -MemberType Property

   TypeName: System.Collections.Hashtable

Name           MemberType Definition                                  
----           ---------- ----------                                  
Count          Property   int Count {get;}                            
IsFixedSize    Property   bool IsFixedSize {get;}                     
IsReadOnly     Property   bool IsReadOnly {get;}                      
IsSynchronized Property   bool IsSynchronized {get;}                  
Keys           Property   System.Collections.ICollection Keys {get;}  
SyncRoot       Property   System.Object SyncRoot {get;}               
Values         Property   System.Collections.ICollection Values {get;}


In [54]:
$dic_for_conv | Convertto-Json
{
    "one":  1,
    "three":  3,
    "two":  2
}

Convertto-Json Convertto-Json

In [55]:
echo "dic_for_conv Json = " ; $dic_for_conv | Convertto-Json
dic_for_conv Json = 
{
    "one":  1,
    "three":  3,
    "two":  2
}

hash -> psobj

In [56]:
$jsn = $dic_for_conv | Convertto-Json -Compress

In [57]:
echo "dic_for_conv Json = $jsn"
dic_for_conv Json = {"one":1,"three":3,"two":2}
In [58]:
$psobj = $jsn | ConvertFrom-Json
$psobj
$psobj = $jsn | ConvertFrom-Json
$psobj

one three two
--- ----- ---
  1     3   2



In [59]:
$psobj.ToString()

In [60]:
$psobj | Convertto-Csv -NoType
"one","three","two"
"1","3","2"
In [61]:
$psobj | Convertto-Json -Compre
{"one":1,"three":3,"two":2}
In [82]:
$dic_for_conv | Convertto-Json | ConvertFrom-Json | set -Name psobj2
$dic_for_conv | Convertto-Json | ConvertFrom-Json | set -Name psobj2


In [84]:
$psobj2
one three two
--- ----- ---
  1     3   2


Serialize

In [62]:
$dic_for_serialized = @{
  'one' = '1st'
  'two' = '2nd'
  'three' = '3rd'
}
$dic_for_serialized = @{
>>   'one' = '1st'
>>   'two' = '2nd'
>>   'three' = '3rd'
>> }
>> 

In [63]:
$dic_for_serialized | Export-Clixml dic_for_serialized.clixml

In [64]:
Path                 
----                 
G:\workspace\pwshnote


In [65]:
dir $pwd/*.clixml

    Directory: G:\workspace\pwshnote


Mode                LastWriteTime         Length Name                                                                  
----                -------------         ------ ----                                                                  
-a----       02/09/2019     13:47            990 dic_for_serialized.clixml                                             


In [66]:
cat dic_for_serialized.clixml
<Objs Version="1.1.0.1" xmlns="">http://schemas.microsoft.com/powershell/2004/04">
  <Obj RefId="0">
    <TN RefId="0">
      <T>System.Collections.Hashtable</T>
      <T>System.Object</T>
    </TN>
    <DCT>
      <En>
        <S N="Key">one</S>
        <S N="Value">1st</S>
      </En>
      <En>
        <S N="Key">three</S>
        <S N="Value">3rd</S>
      </En>
      <En>
        <S N="Key">two</S>
        <S N="Value">2nd</S>
      </En>
    </DCT>
  </Obj>
</Objs>
In [67]:
$dic_for_deserialized = Import-Clixml dic_for_serialized.clixml

In [68]:
$dic_for_deserialized
Name                           Value                                                                                   
----                           -----                                                                                   
one                            1st                                                                                     
three                          3rd                                                                                     
two                            2nd                                                                                     


appendix

In [69]:
Get-Help about_Hash_Tables
TOPIC
    about_Hash_Tables

SHORT DESCRIPTION
    Describes how to create, use, and sort hash tables in Windows PowerShell.


LONG DESCRIPTION
    A hash table, also known as a dictionary or associative array, is a
    compact data structure that stores one or more key/value pairs. For
    example, a hash table might contain a series of IP addresses and
    computer names, where the IP addresses are the keys and the computer
    names are the values, or vice versa.

    In Windows PowerShell, each hash table is a Hashtable 
    (System.Collections.Hashtable) object.  You can use the properties
    and methods of Hashtable objects in Windows PowerShell.

    Beginning in Windows PowerShell 3.0, you can use the [ordered]
    attribute to create an ordered dictionary
    (System.Collections.Specialized.OrderedDictionary) in Windows PowerShell.
    
    Ordered dictionaries differ from hash tables in that the keys always
    appear in the order in which you list them. The order of keys in a hash
    table is not determined.

    The keys and value in hash tables are also .NET objects. They are most
    often strings or integers, but they can have any object type. You can also
    create nested hash tables, in which the value of a key is another hash table.

    Hash tables are frequently used because they are very efficient for finding
    and retrieving data. You can use hash tables to store lists and to create
    calculated properties in Windows PowerShell. And, Windows PowerShell has a
    cmdlet, ConvertFrom-StringData, that converts strings to a hash table.


  Syntax
     The syntax of a hash table is as follows:

          @{ <name> = <value>; [<name> = <value> ] ...}

     The syntax of an ordered dictionary is as follows:

          [ordered]@{ <name> = <value>; [<name> = <value> ] ...}

     The [ordered] attribute was introduced in Windows PowerShell 3.0.


  Creating Hash Tables
     To create a hash table, follow these guidelines:

          - Begin the hash table with an at sign (@).

          - Enclose the hash table in braces ({}).

          - Enter one or more key/value pairs for the content of the hash 
            table.

          - Use an equal sign (=) to separate each key from its value.

          - Use a semicolon (;) or a line break to separate the
            key/value pairs.

          - Key that contains spaces must be enclosed in quotation marks.
            Values must be valid Windows PowerShell expressions. Strings 
            must appear in quotation marks, even if they do not include
            spaces.

          - To manage the hash table, save it in a variable.
          
          - When assigning an ordered hash table to a variable, place
            the [ordered] attribute before the "@" symbol. If you place
            it before the variable name, the command fails.


      To create an empty hash table in the value of $hash, type:

          $hash = @{}


      You can also add keys and values to a hash table when you create it. For
      example, the following statement creates a hash table with three keys.

          $hash = @{ Number = 1; Shape = "Square"; Color = "Blue"}


  Creating Ordered Dictionaries
    You can create an ordered dictionary by adding an object of the 
    OrderedDictiory type, but the easiest way to create an ordered 
    dictionary is use the [Ordered] attribute.

    The [ordered] attribute is introduced in Windows PowerShell 3.0.

    Place the attribute immediately before the "@" symbol.

          $hash = [ordered]@{ Number = 1; Shape = "Square"; Color = "Blue"}
    
    You can use ordered dictionaries in the same way that you use hash tables.
    Either type can be used as the value of parameters that take a hash table
    or dictionary (iDictionary). 


    You cannot use the [ordered] attribute to convert or cast a hash
    hash table. If you place the ordered attribute before the variable 
    name, the command fails with the following error message.

        PS C:\> [ordered]$hash = @{}
        At line:1 char:1
        + [ordered]$hash = @{}
        + ~~~~~~~~~~~~~~
        The ordered attribute can be specified only on a hash literal node.
        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : OrderedAttributeOnlyOnHashLiteralNode

    To correct the expression, move the [ordered] attribute.     
        PS C:\> $hash = [ordered]@{}


    You can cast an ordered dictionary to a hash table, but you cannot 
    recover the ordered attribute, even if you clear the variable and 
    enter new values. To re-establish the order, you must remove and
    recreate the variable.

        PS C:\> [hashtable]$hash = [ordered]@{ Number = 1; Shape = "Square"; Color = "Blue"}
        PS C:\ps-test> $hash

        Name                           Value
        ----                           -----
        Color                          Blue
        Shape                          Square
        Number                         1


  Displaying Hash Tables 
     To display a hash table that is saved in a variable, type the variable
     name. By default, a hash tables is displayed as a table with one column 
     for keys and one for values.

          C:\PS> $hash
        
          Name                           Value
          ----                           -----
          Shape                          Square
          Color                          Blue
          Number                         1


     Hash tables have Keys and Values properties. Use dot notation to display
     all of the keys or all of the values.

          C:\PS> $hash.keys
          Number
          Shape
          Color
        
          C:\PS> $hash.values
          1
          Square
          Blue
         

     Each key name is also a property of the hash table, and its value is 
     the value of the key-name property. Use the following format to display the
     property values.

          $hashtable.<key>
          <value>     

     For example:

          C:\PS> $hash.Number
          1

          C:\PS> $hash.Color
          Blue
     
    
     Hash tables have a Count property that indicates the number of key-value
     pairs in the hash table.

          C:\PS> $hash.count
          3


     Hash table tables are not arrays, so you cannot use an integer as an
     index into the hash table, but you can use a key name to index into the
     hash table. If the key is a string value, enclose the key name in quotation
     marks.

     For example:

          C:\PS> $hash["Number"]
          1


  Adding and Removing Keys and Values
      To add keys and values to a hash table, use the following command
      format.  

          $hash["<key>"] = "<value>"

      For example, to add a "Time" key with a value of "Now" to the hash
      table, use the following statement format.

          $hash["Time"] = "Now"

      You can also add keys and values to a hash table by using the Add
      method of the System.Collections.Hashtable object. The Add method 
      has the following syntax:

          Add(Key, Value)

      For example, to add a "Time" key with a value of "Now" to the hash
      table, use the following statement format.

          $hash = $hash.Add("Time", "Now")

      And, you can add keys and values to a hash table by using the addition 
      operator (+) to add a hash table to an existing hash table. For example,
      the following statement adds a "Time" key with a value of "Now" to the 
      hash table in the $hash variable.

          $hash = $hash + @{Time="Now"}


      You can also add values that are stored in variables.
      
          $t = "Today"
          $now = (Get-Date)
          
          $hash.Add($t, $now)      

      
      You cannot use a subtraction operator to remove a key/value pair from
      a hash table, but you can use the Remove method of the Hashtable object.
      The Remove method takes the key as its value. 

      The Remove method has the following syntax:

          Remove(Key)          
     

      For example, to remove the Time=Now key/value pair from the hash table in
      the value of the $hash variable, type: 

          $hash.$Remove("Time")


      You can use all of the properties and methods of Hashtable objects in
      Windows PowerShell, including Contains, Clear, Clone, and CopyTo. For
      more information about Hashtable objects, see 
      "System.Collections.Hashtable" on MSDN.



  Object Types in HashTables  
      The keys and values in a hash table can have any .NET object type, 
      and a single hash table can have keys and values of multiple types.

      The following statement creates a hash table of process name strings
      and process object values and saves it in the $p variable.


          $p = @{"PowerShell" = (get-process PowerShell); 
          "Notepad" = (get-process notepad)}


      You can display the hash table in $p and use the key-name properties
      to display the values.


          C:\PS> $p

          Name                           Value
          ----                           -----
          PowerShell                     System.Diagnostics.Process (PowerShell)
          Notepad                        System.Diagnostics.Process (notepad)

     

          C:\PS> $p.PowerShell        
      
          Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
          -------  ------    -----      ----- -----   ------     -- -----------
              441      24    54196      54012   571     5.10   1788 PowerShell


          C:\PS> $p.keys | foreach {$p.$_.handles}
          441
          251


       The keys in a hash table can also be any .NET type. The following
       statement adds a key/value pair to the hash table in the $p variable.
       The key is a Service object that represents the WinRM service, and the
       value is the current status of the service.

        
           C:\PS> $p = $p + @{(Get-Service WinRM) = ((Get-Service WinRM).Status)}


       You can display and access the new key/value pair by using the same
       methods that you use for other pairs in the hash table.

           C:\PS> $p

           Name                           Value
           ----                           -----
           PowerShell                     System.Diagnostics.Process (PowerShell)
           Notepad                        System.Diagnostics.Process (notepad)
           System.ServiceProcess.Servi... Running

       
           C:\PS> $p.keys
           PowerShell
           Notepad

           Status   Name               DisplayName
           ------   ----               -----------
           Running  winrm              Windows Remote Management (WS-Manag...

            
           C:\PS> $p.keys | foreach {$_.name}
           winrm        


       
       The keys and values in a hash table can also be Hashtable objects. The
       following statement adds key/value pair to the hash table in the $p 
       variable in which the key is a string, Hash2, and the value is a hash
       table with three key/value pairs.


          C:\PS> $p = $p + @{"Hash2"= @{a=1; b=2; c=3}}


       You can display and access the new values by using the same methods.

          C:\PS> $p


          Name                           Value
          ----                           -----
          PowerShell                     System.Diagnostics.Process (PowerShell)
          Notepad                        System.Diagnostics.Process (notepad)
          System.ServiceProcess.Servi... Running
          Hash2                          {a, b, c}


          C:\PS> $p.Hash2

          Name                           Value
          ----                           -----
          a                              1
          b                              2
          c                              3


          C:\PS> $p.Hash2.b
          2
     


  Sorting Keys and Values
      The items in a hash table are intrinsically unordered. The key/value
      pairs might appear in a different order each time that you display
      them.

      Although you cannot sort a hash table, you can use the GetEnumerator
      method of hash tables to enumerate the keys and values, and then use
      the Sort-Object cmdlet to sort the enumerated values for display.

      For example, the following commands enumerate the keys and values
      in the hash table in the $p variable and then sort the keys in 
      alphabetical order.

          C:\PS> $p.GetEnumerator() | Sort-Object -Property key

          Name                           Value
          ----                           -----
          Notepad                        System.Diagnostics.Process (notepad)
          PowerShell                     System.Diagnostics.Process (PowerShell)
          System.ServiceProcess.Servi... Running


          
      The following command uses the same procedure to sort the hash values in 
      descending order.


          C:\PS> $p.getenumerator() | Sort-Object -Property Value -Descending

          Name                           Value
          ----                           -----
          PowerShell                     System.Diagnostics.Process (PowerShell)
          Notepad                        System.Diagnostics.Process (notepad)
          System.ServiceProcess.Servi... Running


  Creating Objects from Hash Tables
      Beginning in Windows PowerShell 3.0, you can create an object from a
      hash table of properties and property values.

       The syntax is as follows:
        [<class-name>]@{<property-name>=<property-value>;<property-name>=<property-value>}

      This method works only for classes that have a null 
      constructor, that is, a constructor that has no parameters. 
      The object properties must be public and settable.

      For more information, see about_Object_Creation.


  ConvertFrom-StringData
      The ConvertFrom-StringData cmdlet converts a string or a here-string of 
      key/value pairs into a hash table. You can use the 
      ConvertFrom-StringData cmdlet safely in the Data section of a script, 
      and you can use it with the Import-LocalizedData cmdlet to display user
      messages in the user-interface (UI) culture of the current user.


      Here-strings are especially useful when the values in the hash table 
      include quotation marks. (For more information about here-strings, see
      about_Quoting_Rules.)


      The following example shows how to create a here-string of the user 
      messages in the previous example and how to use ConvertFrom-StringData
      to convert them from a string into a hash table.


      The following command creates a here-string of the key/value pairs and
      then saves it in the $string variable.


          C:\PS> $string = @"
          Msg1 = Type "Windows".
          Msg2 = She said, "Hello, World."
          Msg3 = Enter an alias (or "nickname").
          "@

   
    This command uses the ConvertFrom-StringData cmdlet to convert the 
    here-string into a hash table.


        C:\PS> ConvertFrom-StringData $string

        Name                           Value
        ----                           -----
        Msg3                           Enter an alias (or "nickname").
        Msg2                           She said, "Hello, World."
        Msg1                           Type "Windows".

    For more information about here-strings, see about_Quoting_Rules.


SEE ALSO
    about_Arrays
    about_Object_Creation
    about_Quoting_Rules
    about_Script_Internationalization 
    ConvertFrom-StringData
    Import-LocalizedData
    "System.Collections.Hashtable" on MSDN












In [ ]:

</div>