{"id":255,"date":"2014-12-02T11:59:00","date_gmt":"2014-12-02T11:59:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/12\/02\/powertip-use-powershell-to-remove-an-item-from-an-array\/"},"modified":"2019-02-18T10:36:48","modified_gmt":"2019-02-18T17:36:48","slug":"powertip-use-powershell-to-remove-an-item-from-an-array","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-use-powershell-to-remove-an-item-from-an-array\/","title":{"rendered":"PowerTip: Use PowerShell to Remove an Item from an Array"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Use Windows PowerShell&nbsp;<span>remove an item from an array.<\/span><\/span><\/p>\n<p><span style=\"font-size:12px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\">&nbsp;How can I remove an item from an array?<\/span><\/p>\n<p style=\"margin-left:30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\">Use the&nbsp;<b>ArrayList<\/b>&nbsp;class, which has the&nbsp;<b>Remove()<\/b>&nbsp;method (instead of using&nbsp;<b>System.Array<\/b>, <br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;which does not have this method):<\/p>\n<p style=\"margin-left:120px\">PS &gt; $ArrayList = New-Object System.Collections.ArrayList<\/p>\n<p style=\"margin-left:120px\">PS &gt; [void]$ArrayList.AddRange((1..10))<\/p>\n<p style=\"margin-left:120px\">PS &gt; $ArrayList<\/p>\n<p style=\"margin-left:120px\">1<\/p>\n<p style=\"margin-left:120px\">2<\/p>\n<p style=\"margin-left:120px\">3<\/p>\n<p style=\"margin-left:120px\">4<\/p>\n<p style=\"margin-left:120px\">5<\/p>\n<p style=\"margin-left:120px\">6<\/p>\n<p style=\"margin-left:120px\">7<\/p>\n<p style=\"margin-left:120px\">8<\/p>\n<p style=\"margin-left:120px\">9<\/p>\n<p style=\"margin-left:120px\">10<\/p>\n<p style=\"margin-left:120px\">PS &gt; 1..10 | % {If ($_%2){[void]$ArrayList.Remove($_)}}<\/p>\n<p style=\"margin-left:120px\">PS &gt; $ArrayList<\/p>\n<p style=\"margin-left:120px\">2<\/p>\n<p style=\"margin-left:120px\">4<\/p>\n<p style=\"margin-left:120px\">6<\/p>\n<p style=\"margin-left:120px\">8<\/p>\n<p style=\"margin-left:120px\">10<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Use Windows PowerShell&nbsp;remove an item from an array. &nbsp;How can I remove an item from an array? Use the&nbsp;ArrayList&nbsp;class, which has the&nbsp;Remove()&nbsp;method (instead of using&nbsp;System.Array, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;which does not have this method): PS &gt; $ArrayList = New-Object System.Collections.ArrayList PS &gt; [void]$ArrayList.AddRange((1..10)) PS &gt; $ArrayList 1 2 3 4 5 6 [&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":[560,162,356,3,45],"class_list":["post-255","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-array","tag-boe-prox","tag-powertip","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Use Windows PowerShell&nbsp;remove an item from an array. &nbsp;How can I remove an item from an array? Use the&nbsp;ArrayList&nbsp;class, which has the&nbsp;Remove()&nbsp;method (instead of using&nbsp;System.Array, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;which does not have this method): PS &gt; $ArrayList = New-Object System.Collections.ArrayList PS &gt; [void]$ArrayList.AddRange((1..10)) PS &gt; $ArrayList 1 2 3 4 5 6 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/255","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=255"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/255\/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=255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}