# Passing Array Variable from CSV to Identity for Get-SPOSite

**URL:** <https://forums.powershell.org/t/passing-array-variable-from-csv-to-identity-for-get-sposite/13568>\
**Category:** PowerShell Help\
**Created:** [December 19, 2019, 10:07am UTC](https://forums.powershell.org/t/passing-array-variable-from-csv-to-identity-for-get-sposite/13568 "2019-12-19T10:07:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpm](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rpm/32/1336_2.png) [@rpm](https://forums.powershell.org/u/rpm)\
**Post date:** [December 19, 2019, 10:07am UTC](https://forums.powershell.org/t/passing-array-variable-from-csv-to-identity-for-get-sposite/13568/1 "2019-12-19T10:07:20Z")

</div>

Good Morning Everyone,

I’m currently trying to find out information about specific user’s one drive folders.

If I test with just my username, it works just fine. When I attempt to pass the variable through from a CSV file, it keeps the array tags around the variable, and fails because that website is not found.

This works:

```auto
Get-SPOSite -Identity https://domain-my.sharepoint.com/personal/0240357_domain_com | Select-Object Title, Owner, StorageUsageCurrent, Url</code>
<code>
Title Owner StorageUsage	Current Url</code>
<code>----- ----- ------------------- ---</code>
<code>Martin, R 0240357@domain.com 61 https://domain-my.sharepoint.com/personal/0240357_doma...

```

These two options below do not work.

```auto
$users = import-csv C:\scripts\names.csv</code>
<code>foreach ($user in $users){Get-SPOSite -Identity https://domain-my.sharepoint.com/personal/"$user"_domain_com | Select-Object Title, Owner, StorageUsageCurrent, Url}

```

or

```auto
import-csv C:\Scripts\names.csv | ForEach-Object{Get-SPOSite -Identity https://domain-my.sharepoint.com/personal/"$user"_domain_com | Select-Object Title, Owner, StorageUsageCurrent, Url}

```

Both of the above one liners will give me the same error:

```auto
Get-SPOSite : Cannot get site https://domain-my.sharepoint.com/personal/@{User=0240357}_domain_com.</code>
<code>At line:1 char:56</code>
<code>+ ... Each-Object{Get-SPOSite -Identity https://domain-my.sharepoint.co ...</code>
<code>+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ </code>
<code>+ CategoryInfo : NotSpecified: (:) [Get-SPOSite], ServerException</code>
<code>+ FullyQualifiedErrorId : Microsoft.SharePoint.Client.ServerException,Microsoft.Online.SharePoint.PowerShell.GetSite

```

Is there anyway for me to pass that variable and also strip off the array tags so that it sits nicely inside the URL like I need it to?

&nbsp;

Thank you for your time,

Rob Martin

---

<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:** [December 19, 2019, 10:18am UTC](https://forums.powershell.org/t/passing-array-variable-from-csv-to-identity-for-get-sposite/13568/2 "2019-12-19T10:18:36Z")

</div>

The for loop is references $User, which is basically the row that is being processed, so you need to tell it what Property (i.e. Column) you want. With the error message, it appears to be User, so it would $user.User:

```
$users = import-csv C:\scripts\names.csv

foreach ($user in $users) {

     $Identity = "https://domain-my.sharepoint.com/personal/$($user.User)_domain_com"
     #or
     $Identity = 'https://domain-my.sharepoint.com/personal/{0}_domain_com' -f $user.User
     #or
     $Identity = 'https://domain-my.sharepoint.com/personal/{0}_domain_com' -f ($user | Select -ExpandProperty User)

    
    Get-SPOSite -Identity $Identity | 
    Select-Object Title, Owner, StorageUsageCurrent, Url
}
```

---

<div class="post-metadata">

**Author:** ![rpm](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rpm/32/1336_2.png) [@rpm](https://forums.powershell.org/u/rpm)\
**Post date:** [December 19, 2019, 12:52pm UTC](https://forums.powershell.org/t/passing-array-variable-from-csv-to-identity-for-get-sposite/13568/3 "2019-12-19T12:52:14Z")

</div>

Thank you Rob,

This worked just like I needed it to.

---

<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:30pm UTC](https://forums.powershell.org/t/passing-array-variable-from-csv-to-identity-for-get-sposite/13568/4 "2024-05-16T20:30:56Z")

</div>


