{"id":8951,"date":"2012-06-24T00:01:00","date_gmt":"2012-06-24T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2012\/06\/24\/weekend-scripter-an-insiders-guide-to-powershell-arrays\/"},"modified":"2012-06-24T00:01:00","modified_gmt":"2012-06-24T00:01:00","slug":"weekend-scripter-an-insiders-guide-to-powershell-arrays","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-an-insiders-guide-to-powershell-arrays\/","title":{"rendered":"Weekend Scripter: An Insider&#8217;s Guide to PowerShell Arrays"},"content":{"rendered":"<p><b>Summary<\/b>: Microsoft Scripting Guy, Ed Wilson, provides an insider&rsquo;s guide to Windows PowerShell arrays.\nMicrosoft Scripting Guy, Ed Wilson, is here. It is a quiet weekend in Charlotte, North Carolina in the United States. I am about to get back into the swing of things following nearly two weeks on the road for our Florida Windows PowerShell Road Show. The Scripting Wife has made herself scarce the past couple of days, and I am certain she is also trying to get back into a routine. I do not have any more public appearances, other than the <a href=\"http:\/\/www.powershellgroup.org\/charlotte.nc\" target=\"_blank\">Charlotte Windows PowerShell User Group<\/a> meeting on July 5, 2012. We will be doing another &ldquo;mini Scripting Games&rdquo; type of meeting. The last one was WAY COOL! If you are in the area, you should definitely check it out. Even if you have to drive a bit, it will be worth the trip.\nToday, I thought I would go through the Hey, Scripting Guy! Blog archive, and list and review Hey, Scripting Guy! blogs that are related to arrays.\nWindows PowerShell makes working with arrays much easier than the methodology used from other languages. As a result, arrays often receive little attention. I tried to close this gap with a few blogs. In this resource guide, I detail these blogs.<\/p>\n<h2>Background of arrays<\/h2>\n<p><a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2010\/11\/09\/using-powershell-get-member-to-explore-the-net-framework.aspx\" target=\"_blank\">Using PowerShell Get-Member to Explore the .NET Framework<\/a><i> <\/i>\nOK. So this blog does not have the word <i>array <\/i>in the title. But it provides excellent background information about the System.Array .NET Framework class. Windows PowerShell arrays come from the System.Array .NET Framework class, and it is one reason I chose this class to illustrate working with <b>Get-Member<\/b>.\n<a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/12\/05\/learn-simple-ways-to-handle-windows-powershell-arrays.aspx\" target=\"_blank\">Learn Simple Ways to Handle Windows PowerShell Arrays<\/a>\nWe begin with the question, &ldquo;What is an Array?&rdquo; then progress to discussing elements, indexes, and values. It describes the concepts of array boundaries, and examines the <b>Count<\/b> and the <b>Length<\/b> properties. The blog also discusses using the <b>for<\/b><i> <\/i>statement and the <b>Foreach-Object<\/b> cmdlet to access members of an array. This is the first in a series of foundational blogs about arrays.\n<a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/12\/06\/add-modify-verify-and-sort-your-powershell-array.aspx\" target=\"_blank\">Add, Modify, Verify, and Sort your PowerShell Array<\/a><i> <\/i>\nThis<i> <\/i>continues the previous blog and dives into working with array elements, changing the values of elements, and adding to a previously existing array. I talk about searching an array for specific values and about two ways of sorting an array. This is a great blog, and is the second foundational post about arrays.\n<a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/12\/07\/find-the-index-number-of-a-value-in-a-powershell-array.aspx\" target=\"_blank\">Find the Index Number of a Value in a PowerShell Array<\/a>\nIn part three of the foundational posts about arrays, I talk about using the <b>for<\/b><i> <\/i>statement to find the index number of a value in an array. Following that discussion, I talk about using the <b>IndexOf<\/b><i> <\/i>static method from the System.Array .NET Framework class. This class was discussed in <i>Using PowerShell Get-Member to Explore the .NET Framework<\/i>, which is<i> <\/i>mentioned at the top of this section. Finally, I discuss working with only one-half of the array. This is a great blog, and you should definitely spend time mastering the techniques mentioned here.\n<a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/12\/09\/easily-create-and-manipulate-an-array-of-arrays-in-powershell.aspx\" target=\"_blank\">Easily Create and Manipulate an Array of Arrays in PowerShell<\/a><i> <\/i>\nThis is part five in the multiple part array foundations series. In this blog, I first discuss creating an array of arrays. Next, I talk about how to access specific elements in an array of arrays. Using an array of arrays is a powerful technique&mdash;a bit advanced, but powerful nonetheless. This is a great introduction to that topic.\n&nbsp;<\/p>\n<h2>Array techniques<\/h2>\n<p><a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/02\/18\/speed-up-array-comparisons-in-powershell-with-a-runtime-regex.aspx\" target=\"_blank\">Speed Up Array Comparisons in PowerShell with a Runtime RegEx<\/a>\nAn excellent blog written by Scripting Guys Forum moderator and guest blogger, Rob Campbell. This blog compares using the <b>Contains<\/b><i> <\/i>and the <b>NotContains<\/b><i> <\/i>operators with the <b>Match<\/b><i> <\/i>operator and a regular expression pattern. He uses the <b>Measure-Command<\/b> cmdlet to compare the time the two operations use. This is a special application, but it is a great trick to have in your tool pouch.\n<a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/09\/22\/format-multilevel-arrays-in-powershell.aspx\" target=\"_blank\">Format Multilevel Arrays in PowerShell<\/a>\nIn this blog, I discuss using Windows PowerShell to work with multilevel arrays. I talk about creating arrays, adding additional elements to arrays, and creating arrays of other arrays. This is a really cool and foundational blog.\n<a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/12\/08\/read-a-csv-file-and-build-distinguished-names-on-the-fly-by-using-powershell.aspx\" target=\"_blank\">Read a CSV File and Build Distinguished Names on the Fly by Using PowerShell<\/a><i> <\/i>\nThe fourth blog in the Windows PowerShell arrays foundations series begins by reading a CSV file by using the <b>Import-CSV<\/b> cmdlet. Next I pipe the CSV contents to the <b>Foreach-Object<\/b> cmdlet and build a distinguished name. It is a cool technique.\n<a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/12\/11\/combine-arrays-and-hash-tables-in-powershell-for-fun-and-profit.aspx\" target=\"_blank\">Combine Arrays and Hash Tables in PowerShell for Fun and Profit<\/a>\nI discuss creating an array that contains hash tables in the various elements. This is a great technique, and it is an interesting blog.\nWell, that is about it for Hey, Scripting Guy! blogs about Windows PowerShell arrays. Hopefully the information will prime you with ideas and help you utilize these powerful techniques in your Windows PowerShell scripts.\nI invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, provides an insider&rsquo;s guide to Windows PowerShell arrays. Microsoft Scripting Guy, Ed Wilson, is here. It is a quiet weekend in Charlotte, North Carolina in the United States. I am about to get back into the swing of things following nearly two weeks on the road for our Florida [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[292,341,3,4,45],"class_list":["post-8951","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-arrays-hashtables-and-dictionary-objects","tag-resource-guide","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, provides an insider&rsquo;s guide to Windows PowerShell arrays. Microsoft Scripting Guy, Ed Wilson, is here. It is a quiet weekend in Charlotte, North Carolina in the United States. I am about to get back into the swing of things following nearly two weeks on the road for our Florida [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/8951","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\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=8951"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/8951\/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=8951"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=8951"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=8951"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}