# Array pipeline issue

**URL:** <https://forums.powershell.org/t/array-pipeline-issue/4249>\
**Category:** PowerShell Help\
**Created:** [May 21, 2015, 8:24am UTC](https://forums.powershell.org/t/array-pipeline-issue/4249 "2015-05-21T08:24:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthew-tisdel](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/matthew-tisdel/32/781_2.png) [@matthew-tisdel](https://forums.powershell.org/u/matthew-tisdel)\
**Post date:** [May 21, 2015, 8:24am UTC](https://forums.powershell.org/t/array-pipeline-issue/4249/1 "2015-05-21T08:24:22Z")

</div>

Something about arrays is killing me, and this example would have saved me hours of work today. However, I could not make it work.  
This script was “supposed to run” on a Server 2012 R2 IIS server. I attempted a foreach statement, and it would resolve the variable with extra characters. (I wanted “[website.com](http://website.com)” but what I got was @{[name.website.com](http://name.website.com)} ) If this is the total wrong approach, then I am good with that. If you can point me to resources that educate me on this, then that would be the best result.

$SiteArray = (get-website | select name)

$SiteArray | foreach-object {New-WebVirtualDirectory -Site $\_ -name “WebSiteLinks” -PhysicalPath ‘E:\Websites\Links’ -force}

Thanks,  
Matt

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [May 21, 2015, 8:26am UTC](https://forums.powershell.org/t/array-pipeline-issue/4249/2 "2015-05-21T08:26:42Z")

</div>

There are a couple of ways you could address that. One is to use Select-Object -ExpandProperty (instead of -Property, which is the default position parameter when you just do “select name”). Or, you could put -Site $\_.Name in your ForEach-Object block, instead of just -Site $\_

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [May 21, 2015, 8:28am UTC](https://forums.powershell.org/t/array-pipeline-issue/4249/3 "2015-05-21T08:28:10Z")

</div>

Incidentally, this is one of the items mentioned in the “Big Book of PowerShell Gotchas”, which is free and available from this site. 🙂[https://www.penflip.com/powershellorg/the-big-book-of-powershell-gotchas/blob/master/properties-vs-values.txt](https://www.penflip.com/powershellorg/the-big-book-of-powershell-gotchas/blob/master/properties-vs-values.txt)

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [May 21, 2015, 8:45am UTC](https://forums.powershell.org/t/array-pipeline-issue/4249/4 "2015-05-21T08:45:26Z")

</div>

The underlying problem here isn’t arrays.

Your original Select-Object was producing an object, which had a single property Name, which contained a String. Those vexing curly braces are PowerShell’s way of representing an object; the shell is hardcoded to look for a Name property simply because most objects have one. Dave’s -ExpandProperty is different, in that it _extracts_ the value from the property and leaves just the simple string value, which is probably what you wanted.

And +1 to the Gotchas book!

---

<div class="post-metadata">

**Author:** ![matthew-tisdel](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/matthew-tisdel/32/781_2.png) [@matthew-tisdel](https://forums.powershell.org/u/matthew-tisdel)\
**Post date:** [May 21, 2015, 11:35pm UTC](https://forums.powershell.org/t/array-pipeline-issue/4249/5 "2015-05-21T23:35:22Z")

</div>

That worked great, and I have learned something very useful. I am going to put the Gotcha book on my study list.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:45pm UTC](https://forums.powershell.org/t/array-pipeline-issue/4249/6 "2024-05-16T20:45:16Z")

</div>

Closed on May 16, 2024, 8:45pm UTC


