2

Currently I have this script:

$SiteURL="https://contoso.sharepoint.com/sites/contoso"
$UserID="j.doe@contoso.nl"

#Get Credentials to connect
$Cred = Get-Credential

#Connect to SharePoint Online Admin Site
Connect-SPOService -Url $AdminSiteURL -Credential $cred

#sharepoint online powershell remove user permissions from site collection
Get-SPOUser -Site $SiteURL -LoginName $UserID

But I have multiple site collections that it needs to find that user in:

https://contoso.sharepoint.com/sites/Projecten
https://contoso.sharepoint.com/sites/PFO

How can I do this using a for loop so it finds the user in each site collection?

mklement0
  • 382,024
  • 64
  • 607
  • 775
klaas123
  • 147
  • 1
  • 10

1 Answers1

2

Already figured it out:

$UserID="j.doe@contoso.nl"

$sitecollectios = @("https://contoso.sharepoint.com/sites/Extranet","https://contoso.sharepoint.com/sites/contoso","https://contoso.sharepoint.com/sites/Projecten","https://contoso.sharepoint.com/sites/PFO","https://contoso.sharepoint.com/sites/beheer","https://contoso.sharepoint.com/sites/Intranet")

#Get Credentials to connect
$Cred = Get-Credential

#Connect to SharePoint Online Admin Site

Connect-SPOService -Url $AdminSiteURL -Credential $cred

foreach ($collectie in $sitecollectios)
{ 
    Get-SPOUser -Site $collectie -LoginName $UserID
}
mklement0
  • 382,024
  • 64
  • 607
  • 775
klaas123
  • 147
  • 1
  • 10
  • As an aside: I suggest avoiding `@(...)` for array literals; e.g., instead of `@('a', 'b')`, use just `'a', 'b'`. Not only is `@(...)` unnecessary, it is inefficient in PowerShell versions up to 5.0, but - more importantly - it invites conceptual confusion by falsely suggesting that it _constructs_ arrays. For more information, see the bottom section of [this answer](https://stackoverflow.com/a/45091504/45375). – mklement0 Apr 01 '20 at 12:59