# How to pick certain word from an array?

**URL:** <https://forums.powershell.org/t/how-to-pick-certain-word-from-an-array/7125>\
**Category:** PowerShell Help\
**Created:** [September 2, 2016, 8:26am UTC](https://forums.powershell.org/t/how-to-pick-certain-word-from-an-array/7125 "2016-09-02T08:26:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nitheesh-babu](https://avatars.discourse-cdn.com/v4/letter/n/ecae2f/32.png) [@nitheesh-babu](https://forums.powershell.org/u/nitheesh-babu)\
**Post date:** [September 2, 2016, 8:26am UTC](https://forums.powershell.org/t/how-to-pick-certain-word-from-an-array/7125/1 "2016-09-02T08:26:38Z")

</div>

I am trying to return certain column of an array

My array looks like this(with all these number of spaces in between):  
Soft One server01 1156  
Soft One server04 1172  
Soft One server03 1137  
Soft One server02 1184

I only need to read the value of last column(that is the number) and supply it for other commands.

```
$xaload = qfarm /load /continue /app "Soft One" 
for ($i = 4; $i -lt $xaload.Length; $i++)
{ 
   $line = ([string]$xaload[$i]).Split(',')[0];
   $line.split()[0] #what number I should give in the square braces to get the last column value only?
#when I select 0 it returns the first word of each line which is "soft"
#when I select 1 it returns the second word which is"one"
}
```

Thanks in advance for attending.

---

<div class="post-metadata">

**Author:** ![powershellish](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@powershellish](https://forums.powershell.org/u/powershellish)\
**Post date:** [September 2, 2016, 8:36am UTC](https://forums.powershell.org/t/how-to-pick-certain-word-from-an-array/7125/2 "2016-09-02T08:36:01Z")

</div>

You can count backwards from the end with negatives, so -1

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [September 2, 2016, 8:45am UTC](https://forums.powershell.org/t/how-to-pick-certain-word-from-an-array/7125/3 "2016-09-02T08:45:07Z")

</div>

If you always want the last item, then you typically use upperbound to get highest part of the array. In this case, you have 4 items in the array, so you could also use a static index value like $arrRow[3].

```
$array = @(
"Soft One server01 1156",
"Soft One server04 1172",
"Soft One server03 1137",
"Soft One server02 1184"
)

$results = foreach ($row in $array) {
    $arrRow = $row -Split " "
    $arrRow[$arrRow.Count -1]
    #or
    $arrRow[$arrRow.Length -1]
    #or
    $arrRow[$arrRow.getupperbound(0)]
}

$results
```

---

<div class="post-metadata">

**Author:** ![daniel-krebs](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/daniel-krebs/32/484_2.png) [@daniel-krebs](https://forums.powershell.org/u/daniel-krebs)\
**Post date:** [September 2, 2016, 9:45am UTC](https://forums.powershell.org/t/how-to-pick-certain-word-from-an-array/7125/4 "2016-09-02T09:45:01Z")

</div>

Have you looked at using the Citrix XenApp PowerShell SDK and its cmdlets to get the details as proper PowerShell objects instead of doing prayer based text parsing of the qfarm command line tool output?

> **[Powershell SDK - Citrix](https://www.citrix.com/downloads/xenapp/sdks/powershell-sdk.html)**
>
> XenApp 6 Powershell SDK

[http://powerschill.com/citrix/using-powershell-to-get-xenapp-server-load/](http://powerschill.com/citrix/using-powershell-to-get-xenapp-server-load/)  
[https://www.citrix.com/blogs/2010/08/17/getting-a-farm-inventory-with-xenapp-6-powershell-scripting/](https://www.citrix.com/blogs/2010/08/17/getting-a-farm-inventory-with-xenapp-6-powershell-scripting/)  
[http://www.virtuaprod.fr/?p=259](http://www.virtuaprod.fr/?p=259)

---

<div class="post-metadata">

**Author:** ![nitheesh-babu](https://avatars.discourse-cdn.com/v4/letter/n/ecae2f/32.png) [@nitheesh-babu](https://forums.powershell.org/u/nitheesh-babu)\
**Post date:** [September 2, 2016, 9:45am UTC](https://forums.powershell.org/t/how-to-pick-certain-word-from-an-array/7125/5 "2016-09-02T09:45:37Z")

</div>

Thanks Craig. Thanks Rob. That was really helpful.

---

<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:40pm UTC](https://forums.powershell.org/t/how-to-pick-certain-word-from-an-array/7125/6 "2024-05-16T20:40:51Z")

</div>


