Guest User

Untitled

a guest
Jun 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #################################################################
  2. # Script that allows to get all the users for all the Site Collections in a SharePoint Online Tenant
  3. # Required Parameters:
  4. # -> $sUserName: User Name to connect to the SharePoint Admin Center.
  5. # -> $sMessage: Message to show in the user credentials prompt.
  6. # -> $sSPOAdminCenterUrl: SharePoint Admin Center Url
  7.  
  8. ##################################################################
  9.  
  10. $host.Runspace.ThreadOptions = "ReuseThread"
  11.  
  12. #Definition of the function that gets all the site collections information in a SharePoint Online tenant
  13. function Get-SPOUsersAllSiteCollections
  14. {
  15. param ($sUserName,$sMessage)
  16. try
  17. {
  18. Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
  19. Write-Host "Getting the information for all the site colletions in the Office 365 tenant" -foregroundcolor Green
  20. Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
  21. $msolcred = get-credential -UserName $sUserName -Message $sMessage
  22. Connect-SPOService -Url $sSPOAdminCenterUrl -Credential $msolcred
  23. $spoSites=Get-SPOSite | Select *
  24. foreach($spoSite in $spoSites)
  25. {
  26. Write-Host "Users for " $spoSite.Url -foregroundcolor Blue
  27. Get-SPOUser -Site $spoSite.Url
  28. Write-Host
  29. }
  30. Write-Host "Getting users" -ForegroundColor Green
  31. Get-SPOUser -Site "<SiteCollection URL>" | Out-File "C:UsersAdministratorDownloadsSharePoint OnlineUsers.txt" -Append;
  32.  
  33. }
  34. catch [System.Exception]
  35. {
  36. write-host -f red $_.Exception.ToString()
  37. }
  38. }
  39.  
  40. #Connection to Office 365
  41. $sUserName="<user account>"
  42. $sMessage="SPO Credential Please"
  43. $sSPOAdminCenterUrl="https://<Domain>-admin.sharepoint.com"
  44. #Get-SPOUser -Site "https://<Domain>.sharepoint.com/" -LoginName "<user>"
  45.  
  46. Get-SPOUsersAllSiteCollections -sUserName $sUserName -sMessage $sMessage
Add Comment
Please, Sign In to add comment