programming4us
programming4us
WEBSITE

PowerShell for Microsoft SharePoint 2010 : Variables, Arrays, and Hashtables - Hashtables in Windows PowerShell

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Windows PowerShell also includes hashtables, or associative arrays. Hashtables use key/value pairs instead of a numeric index to access the elements.

You can create a hashtable by placing one or more key/value pairs inside @{}.

PS > $hashTable = @{"FirstName"="Jean-Luc";"LastName"="Picard"}
PS > $hashTable

Name Value
---- -----
FirstName Jean-Luc
LastName Picard

You can access specific elements in a hashtable in two ways: using dot notation or by typing the key within square brackets. Here’s how to use dot notation:

PS > $hashTable.FirstName
Jean-Luc
PS > $hashTable.LastName
Picard

And here’s the square bracket form:

PS > $hashTable["FirstName"]
Jean-Luc
PS > $hashTable["LastName"]
Picard

You can also send a hashtable down a pipeline and use the Select-Object cmdlet to retrieve specific elements.

PS > $hashTable | Select @{Name="Name";Expression={$_["FirstName"]}}

Name
----
Jean-Luc

To change a key/value pair in a hashtable, you can use either form to access it and assign the new value, as in these examples:

PS > $hashTable.FirstName = "William"
PS > $hashTable["LastName"] = "Riker"
PS > $hashTable

Name Value
---- -----
LastName Riker
FirstName William

You can also store multiple hashtables in an array. In this example, we store two hashtables in an array.

PS > $hashTable = @{"FirstName"="Jean-Luc";"LastName"="Picard"},
@{"FirstName"="William";"LastName"="Riker"}
PS > $hashTable

Name Value
---- -----
LastName Picard
FirstName Jean-Luc
LastName Riker
FirstName William

When multiple hashtables are in an array, to access elements in the hashtable, you need to index into a specific element; otherwise, Windows PowerShell will not know which element you want to retrieve.

PS > $hashTable[0]
PS > $hashTable[0].FirstName

Name Value
---- -----
LastName Picard
FirstName Jean-Luc

In this example, we retrieve the first hashtable in the array and return the key/value pair.

Other  
  •  PowerShell for Microsoft SharePoint 2010 : Variables, Arrays, and Hashtables - Arrays in Windows PowerShell
  •  Sharepoint 2010 : Administering Enterprise Content Management - Document Management (part 12) - Digital Asset Management
  •  Sharepoint 2010 : Administering Enterprise Content Management - Document Management (part 11) - eDiscovery and Hold , Retention
  •  Sharepoint 2010 : Administering Enterprise Content Management - Document Management (part 10) - In-Place Records Management
  •  Sharepoint 2010 : Administering Enterprise Content Management - Document Management (part 9) - Improved Records Center Site
  •  Sharepoint 2010 : Administering Enterprise Content Management - Document Management (part 8) - Content Type Syndication
  •  Sharepoint 2010 : Administering Enterprise Content Management - Document Management (part 7) - Term Store and Term Sets
  •  Sharepoint 2010 : Administering Enterprise Content Management - Document Management (part 6) - Managed Metadata Fields
  •  Sharepoint 2010 : Administering Enterprise Content Management - Document Management (part 5) - Content Types and Columns
  •  Sharepoint 2010 : Administering Enterprise Content Management - Document Management (part 4) - Document Sets , Location-Based Metadata Default Values
  •  
    Top 10
    Free Mobile And Desktop Apps For Accessing Restricted Websites
    MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
    TOYOTA CAMRY 2; 2.5 : Camry now more comely
    KIA SORENTO 2.2CRDi : Fuel-sipping slugger
    How To Setup, Password Protect & Encrypt Wireless Internet Connection
    Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
    Backup & Restore Game Progress From Any Game With SaveGameProgress
    Generate A Facebook Timeline Cover Using A Free App
    New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
    SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
    - Messages forwarded by Outlook rule go nowhere
    - Create and Deploy Windows 7 Image
    - How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
    - Creating and using an unencrypted cookie in ASP.NET
    - Directories
    - Poor Performance on Sharepoint 2010 Server
    - SBS 2008 ~ The e-mail alias already exists...
    - Public to Private IP - DNS Changes
    - Send Email from Winform application
    - How to create a .mdb file from ms sql server database.......
    programming4us programming4us
    programming4us
     
     
    programming4us