0

I need to export from SharePoint Online (365) a complete list of all links of sharing created in the past. I need it to verify if external users can access to some files on SharePoint.

I already tried the command:

$SiteCollections = Get-SPOSite https://mytenant.sharepoint.com/ -Limit All
foreach ($site in $SiteCollections)
{
    $ExternalUsers += Get-SPOUser -Limit All -Site $site.Url | Where {$_.LoginName -like "*urn:spo:guest*" -or $_.LoginName -like "*"} | Select DisplayName,LoginName,@{Name = "Url"; Expression = { $site.url }}
}
$ExternalUsers | Export-Csv -Path "C:\PowerShell\ExternalUsers.csv" -NoTypeInformation

But this extracted only the external users that can access to my "home link" https://mytenant.sharepoint.com/ (I suppose… but maybe I'm wrong). I need all links for sharings generated, not only my principal site path… is it possible to do so? I don't know all the links generated, so I need a list of it with users (internal and external) which can access it.

Someone can help me please? I have no idea how to do it.

Thanks in advance, Alessandro

0

No help to your issue, but some hints on coding:

  • using $ExternalUsers += in a ForEach is very inefficient as it rebuilds the array variable on every iteration
  • coding one endless line makes it hard to read and discover flaws (here the 2nd where clause includes the 1st one)
  • whenever PowerShell expects a continuation you may insert line breaks (without a trailing backtick ` ) like after a | or , or operator -or

So this should work:

$SiteCollections  = Get-SPOSite https://mytenant.sharepoint.com/ -Limit All

$ExternalUsers = ForEach ($Site in $SiteCollections){
    Get-SPOUser -Limit All -Site $site.Url | 
      Where-Object {$_.LoginName -like "*urn:spo:guest*" -or 
                    $_.LoginName -like "*"} | ForEach-Object {
        [PSCutomObject]@{
          DisplayName = $_.DisplayName
          LoginName   = $_.LoginName
          Url         = $site.url
        }
    }
}
$ExternalUsers | Export-Csv -Path "C:\PowerShell\ExternalUsers.csv" -NoTypeInformation
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.