Office 365 Group Sites ownership Report

This script is extension to the SharePoint Online Site Collection owner Report

https://gallery.technet.microsoft.com/scriptcenter/SharePoint-Online-fd31f576

It includes office 365 groups, Classic team Sites, Communication Sites & other sites except Office 365 video.

Download and extract the Script solution from below link.

https://gallery.technet.microsoft.com/scriptcenter/Office-365-Group-Sites-2a4f2179

Update the .ps1 file with organization name

##########################Load variables & Logs###################

$log = Write-Log -Name “process_SpSiteonlineOwnerReport” -folder logs -Ext log

$output1 = Write-Log -Name “SPOCollection” -folder Report -Ext html

$orgname = “orgname”

$collection1 = @()

$collection = @()

##########################################################

Run the batch file , it will prompt you with user id & password for Sharepoint online/Exchange online administrator, For my setup single account has all the required rights.

Office 365 group sites are setup with owner information as office 365 group object so to extract actual owner We require access to exchange Shell.

After extracting the office 365 group site owner, from sharepoint, Script is replacing _o with “” to get guid of the unified group and than connecting to exchnage to get the actual owner.

###########

$own = (Get-SPOSite $url).owner

 $own = $own -replace “_o”, “”

############

 

 

Logs folder contains transcript log & report folder will contain HTML report information. On the root of the wroking folder you will also get the report in the form of aspx that you can upload to Sharepoint site so that other can view.( In future I will add more code to the script to auto upload it to sharepoint document library using CSOM)

PowerShell
<#     
    .NOTES 
    =========================================================================== 
     Created on:       8/17/2017 2:26 PM 
     Updated on: 12/8/2017 
     Created by:       Vikas Sukhija (http://SysCloudPro.com) 
     Organization:      
     Filename:         SpOnlineOwnerReport.ps1 
     Update: SharePoint Online Site Collections including Group Sites excluding Videos, OneDrive 
    =========================================================================== 
    .DESCRIPTION 
        This will report All owners of Sharepoint SItecollections 
#> 
#############Load Functions################# 
$error.clear() 
try { stop-transcript | out-null } 
catch { $error.clear() } 
 
function Write-Log 
{ 
    [CmdletBinding()] 
    param 
    ( 
        [Parameter(Mandatory = $true)] 
        [array]$Name, 
        [Parameter(Mandatory = $true)] 
        [string]$Ext, 
        [Parameter(Mandatory = $true)] 
        [string]$folder 
    ) 
     
    $log = @() 
    $date1 = get-date -format d 
    $date1 = $date1.ToString().Replace("/""-") 
    $time = get-date -format t 
     
    $time = $time.ToString().Replace(":""-") 
    $time = $time.ToString().Replace(" """) 
     
    foreach ($n in $name) 
    { 
         
        $log += (Get-Location).Path + "\" + $folder + "\" + $n + "_" + $date1 + "_" + $time + "_.$Ext" 
    } 
    return $log 
} 
 
function LaunchSHO 
{ 
    param 
    ( 
        $orgName, 
        $cred 
    ) 
     
    Write-Host "Enter Sharepoint Online Credentials" -ForegroundColor Green 
    $userCredential = $cred 
    Connect-SPOService -Url "https://$orgName-admin.sharepoint.com" -Credential $userCredential 
} 
 
Function RemoveSHO 
{ 
     
    disconnect-sposervice 
} 
 
function LaunchEOL 
{ 
    param 
    ( 
        $cred 
    ) 
     
    $UserCredential = $cred 
     
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection 
     
    Import-PSSession $Session -Prefix "EOL" -AllowClobber 
} 
 
 
 
Function RemoveEOL 
{ 
     
    $Session = Get-PSSession | where { $_.ComputerName -like "outlook.office365.com" } 
    Remove-PSSession $Session 
     
} 
##########################Load variables & Logs#################### 
$log = Write-Log -Name "process_SpSiteonlineOwnerReport" -folder logs -Ext log 
$output1 = Write-Log -Name "SPOCollection" -folder Report -Ext html 
$orgname = "orgname" 
$collection1 = @() 
$collection = @() 
 
##########Start Script main############## 
 
Start-Transcript -Path $log 
$cred = Get-Credential 
try 
{ 
    LaunchSHO -orgName $orgname -cred $cred 
} 
catch 
{ 
    write-host "$($_.Exception.Message)" -foregroundcolor red 
    Send-MailMessage -SmtpServer $smtpserver -From $from -To $erroremail -Subject "SP Online ConnectionError Site owner Report" -Body $($_.Exception.Message) 
    break 
} 
#-Filter { Template -ne "Group#0" } 
$collection1 = Get-SPOSite -Limit All | where{($_.lockstate -eq "Unlock"-and ($_.Url -notlike "*/portals/*")} | select url, owner, template, StorageUsageCurrent, StorageQuota 
 
try 
{ 
    Write-Host "Connecting to EOL" -ForegroundColor Green 
    LaunchEOL -cred $cred 
} 
catch 
{ 
    write-host "$($_.Exception.Message)" -foregroundcolor red 
    Send-MailMessage -SmtpServer $smtpserver -From $from -To $erroremail -Subject "SP Online -EOL Connection Error Site owner Report" -Body $($_.Exception.Message) 
    break 
} 
$collection1 | ForEach-Object{ 
    $url = $_.url 
    $Owner = $_.owner 
    $Template = $_.template 
    $StorageUsageCurrent = $_.StorageUsageCurrent 
    $StorageQuota = $_.StorageQuota 
    Write-Host "processing...............$url" -ForegroundColor Green 
    if (($Template -eq "GROUP#0"-and ($Owner -eq "")) 
    { 
        $own = (Get-SPOSite $url).owner 
        $own = $own -replace "_o""" 
        $managedby = (Get-EOLUnifiedGroup $own).managedby 
        $Owner = $managedby 
    } 
    if ($Template -eq "GROUP#0") { $Template = "Office 365 Group Site"} 
    if ($Template -eq "STS#0") { $Template = "Classic Team Site"} 
    if ($Template -eq "SITEPAGEPUBLISHING#0") { $Template = "Communication Site" } 
     
    <#$owner 
    $Template 
    $StorageUsageCurrent 
    $StorageQuota#> 
     
    $coll = "" | select url, owner, template, StorageUsageCurrent, StorageQuota 
    $coll.url = $url 
    $coll.owner = $Owner 
    $coll.template = $Template 
    $coll.StorageUsageCurrent = $StorageUsageCurrent 
    $coll.StorageQuota = $StorageQuota 
    $collection+=$coll 
} 
RemoveSHO 
RemoveEOL 
############Format HTML########### 
$HTMLFormat = "<!--mce:0-->" 
################################ 
 
$collection | ConvertTo-HTML -Head $HTMLFormat -Body "<H2><Font Size = 4,Color = DarkCyan>SharePoint Online Site Collections including Group Sites excluding Videos, OneDrive</Font></H2>" -AS Table | 
Set-Content $output1 
copy-item $output1 .\SPOCollection.aspx 
 
Stop-Transcript 
##############################################################################

 

Thanks for downloading

Sukhija Vikas

http://SysCloudpro.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s