programming4us
programming4us
WEBSITE

PowerShell for Microsoft SharePoint 2010 : Variables, Arrays, and Hashtables - Arrays 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

An array is a container that is used for storing a collection of data elements. An array in Windows PowerShell can contain objects of all types supported by .NET. All arrays are origin zero, meaning that the first element in an array is always at index 0, the second element is at index 1, and so on. Many cmdlets in Windows PowerShell return output in the form of an array.

Here is an example of creating a simple array containing numeric values:

PS > $array = 1,2,3
PS > $array
1
2
3

You can also create an array using the array subexpression operator @, as shown here:

PS > $array = @(1,2,3)

You can access specific elements in arrays. To retrieve the first element, type the following:

PS > $array[0]
1

Notice how we use the value 0 to retrieve the first element, since the indexing of array elements in Windows PowerShell starts with zero. If we used 1, the second element would be returned.

You can change an element in an array by assigning it a new value, as in this example:

PS > $array[1] = "Two"
PS > $array
1
Two
3

Use the += operator to add an element to an array.

PS > $array += "Four"
PS > $array
1
Two
3
Four

You can also count the number of elements in an array by using the Count property.

PS > $array.Count
4

Note

The Count property used in this example is actually an alias for the System.Array Length property. It is available through the types.ps1.xml file, which is a built-in XML file that adds several elements to the .NET Framework types in Windows PowerShell.


When cmdlets return more than one result, Windows PowerShell automatically wraps the result into an array. In the following example, we store the output of the Get-SPWebTemplate cmdlet in a variable and use the Count property to check how many elements the array contains.

PS > $SPWebTemplate = Get-SPWebTemplate
PS > $SPWebTemplate.Count
50

Again, if we want to retrieve the first element, we can simply type the following:

PS > $SPWebTemplate[0]

Name Title LocaleId Custom
---- ----- -------- ------
GLOBAL#0 Global template 1033 False

You can also use ranges when retrieving elements in an array.

PS > $SPWebTemplate[0..2]

Name Title LocaleId Custom
---- ----- -------- ------
GLOBAL#0 Global template 1033 False
STS#0 Team Site 1033 False
STS#1 Blank Site 1033 False

It is even possible to use negative numbers when working with arrays. To retrieve the last element in the array, use -1.

PS > $SPWebTemplate[-1]

Name Title LocaleId Custom
---- ----- -------- ------
visprus#0 Visio Process Repository 1033 False


Other  
  •  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
  •  Sharepoint 2010 : Administering Enterprise Content Management - Document Management (part 3) - Metadata Navigation and Filtering, The Content Organizer
  •  
    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