How to get SharePoint Online Group Sites URL & Owners from tenant!


My client implemented SharePoint Online;  One of the new feature of SharePoint Online is Users can create Group Sites(Team or Communication) Collection without any approval Process. There were more than 2000 Group Sites created by users across the organization.
Step 1: Is to get a report of how many sites are created by users by department, location details.
Step 2: is to implement some kind of governance related to who can create the Group Sites.

The following script is to extract Information regarding Group Site like  Title, URL, Created By, Location and export it to CSV.



$host.Runspace.ThreadOptions = "ReuseThread" #Definition of the function that allows to get all the members of all the Office 365 Groups in a tenant function Get-GroupsSites { <# .SYNOPSIS Gets all the Owners who created groups and details into a CSV file. .DESCRIPTION The function connects to tenant with Admin credentials and loops through each Groups. .EXAMPLE .\Get-GroupSites -$OutDirectoryPath "C:\temp" # the out put is found in the C:\temp\GroupSites.csv .NOTES Important to pass correct parameter example 'c:\temp' for the funciton to execute. #> param( [string] [Parameter(Mandatory=$true)] $OutDirectoryPath ) #Initialise all the tenant variables. $tenantUrl = "https://sptest-admin.sharepoint.com/" # $username = 'admin@sptest.test.com' # $password = ConvertTo-SecureString -String 'XXXXXX' -AsPlainText -Force $O365Cred= New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $username,$password Connect-AzureAD -Credential $O365Cred Connect-MsolService -Credential $O365Cred $PSSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $O365Cred -Authentication Basic -AllowRedirection Import-PSSession $PSSession Write-host "Getting Groups now.." Try { #Getting all the Office 365 Groups in the tenant Write-Host "Getting all the users who created each O365 Group in the tenant ..." -foregroundcolor Green $O365Groups = Get-UnifiedGroup $OutPut = foreach ($O365Group in $O365Groups) { $usr = Get-Recipient -Identity $O365Group.ManagedBy[0] $msg = $O365Group.DisplayName + ',' + $O365Group.SharePointSiteUrl +','+ $usr.Office +','+$usr.DisplayName +','+ $usr.PrimarySmtpAddress # $owners Get-UnifiedGroupLinks –Identity $O365Group.Identity –LinkType "Owners" Write-Host $msg -ForegroundColor Green Write-host New-Object -TypeName PSObject -Property @{ Title = $O365Group.DisplayName SharePointSiteUrl = $O365Group.SharePointSiteUrl Office = $usr.Office UserName = $usr.DisplayName UserEmail = $usr.PrimarySmtpAddress } | Select-Object Title,SharePointSiteUrl,Office,UserName,UserEmail } #Write to CSV. $OutPut | Export-CSV $OutDirectoryPath + \GroupSites.csv } catch [System.Exception] { Write-Host -ForegroundColor Red $_.Exception.ToString() } } Get-GroupsSites

CSOM PowerShell function to check if the a SharePoint Online site exits? It accepts credential and Url and return true or false.





$siteUrl = 'https://spo.sharepoint.com/sites/teamsite'
$credential = Get-Credential;

function CheckSiteExists($credential,$siteUrl){

 Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll" 
 Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll" 

     $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
     $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credential.UserName,$credential.Password);
     [System.Net.WebRequest]::DefaultWebProxy.Credentials = $Creds # needed for default gateway.
     $ctx.Credentials = $Creds;
     $web = $ctx.Web
      $ctx.Load($web)
      try{
            $ctx.ExecuteQuery()         
            return $true
         }
         catch{           
            return $false
        
         }  
        
}

#Calling the function: CheckSiteExits  $credentials $siteUrl

Update Logo using CSOM for SharePoint Online.



How to update the Update Logo using CSOM for SharePoint Online / 0365

The following PowerShell will update SharePoint Online logo for Site Collection /sites/sctest

function UpdateLogo(){

Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll"
try{

$siteUrl = "https://spdemo.sharepoint.com/sites/sctest"
$credential = Get-Credential
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credential.UserName,$credential.Password);

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
[System.Net.WebRequest]::DefaultWebProxy.Credentials = $Creds # needed for default gateway.
$ctx.Credentials = $Creds;
$ctx.Web.SiteLogoUrl = "/SiteAssets/banner.jpg";
$ctx.Web.Update();
$ctx.ExecuteQuery();
$ctx.Dispose();
Set-OutPut "Logo Updated.." "NO ERROR"
$OutMsg = $OutMsg + "QH Logo Updated." + "`r`n"
Write-host $OutMsg
}
catch{
$Outmsg = $OutMsg + "`r`n"
$Outmsg = $OutMsg + "Error in function: UpdateLogo" + "`r`n"
$OutMsg = $OutMsg + "Line : $($_.InvocationInfo.ScriptLineNumber)" + "`r`n"
$OutMsg = $OutMsg + "$($_.Exception)" + "`r`n"
$OutMsg = $OutMsg + "$($_.Exception.Message)" + "`r`n"
Write-host $OutMsg
}

}