Need help with Powershell Script to export list of OneDrive for business site collection owners.
-
Hello, I am new to this site. I am the SharePoint Online Administrator. In our organisation we need to perform the audit. we would like to know the user names that are having full control or are in owners group in all the OneDrive for business site collections in office 365 SharePoint Online. I was trying to create the script but at some point it is throwing an error. the script is mentioned below.
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue Import-Module ‘C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell’ -DisableNameChecking $Fulldomain="makaveli.onmicrosoft.com" #Step2: Connect to SharePoint Online and MsolService $credential = get-credential Connect-SPOService -Url “https://makaveli-admin.sharepoint.com/” -Credential $credential Connect-MsolService -Credential $credential #Step3: Set OneDrive Storage Quota for all Office 365 Users $users=Get-MsolUser $users | Foreach-Object{ $user=$_ $username=($user.userprincipalname –Split “@”)[0] $Dname=($Fulldomain -Split "\.") If($Dname[2] -ne $null) { $Firstname=$Dname[0] $Secondname=$Dname[1] $thirdname=$Dname[2] $sitename= "https://"+$Firstname+"-my.sharepoint.com/personal/"+$username+"_"+$Firstname+"_"+$Secondname+"_"+$thirdname } Else { $Firstname=$Dname[0] $Secondname=$Dname[1] $sitename= "https://"+$Firstname+"-my.sharepoint.com/personal/"+$username+"_"+$Firstname+"_"+$Secondname } $Groups = Get-SPOSiteGroup -Site $sitename Foreach($Group in $Groups){ Foreach($Role in $Group.Roles){ If ($Role.Contains(“Full Control”)) { Write-Host $Group.Title Write-Host $Group.Users $users = $Group.Users -join ‘ ‘ $title = $Group.Title $props = @{Title = $title Users = $users Website = $sitename } $temp = New-Object psobject -Property $props $temp | export-csv –append –path C:\SiteOwnerandSites.csv } }}}
================================================== by running the above script I am getting the following error message:Get-SPOSiteGroup : Cannot get site https://makaveli-my.sharepoint.com/personal/Mohammed_makaveli_onmicrosoft_com. At line:32 char:11 + $Groups = Get-SPOSiteGroup -Site $sitename + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-SPOSiteGroup], ServerException + FullyQualifiedErrorId : Microsoft.SharePoint.Client.ServerException,Microsoft.Online.SharePoint.PowerShell.GetSPOSiteGroup
I am able