Get Public Unified Groups

With the ramping up of Microsoft Teams and its intergration with SharePoint, you can understand that Administrators need a way to observe and ultimatley control the stream of creation of the Unified Groups that glue together the above technologies. A request came through recently to have a Scheduled Task running that sends an email to Administrators of all Public Unified Groups created within the last day, understanding the Manager, the Alias of the group and the SharePoint Site URL.

Note; you can find a little more on the first lines of this code here.

Code is below:

#Read-Host –AsSecureString | ConvertFrom-SecureString | Out-File C:\temp\EXOpassword.txt 

  

$password = Get-Content C:\temp\EXOpassword.txt | ConvertTo-SecureString

$userid =‘hpo@mysmartplace.net’
 

$cred = New-Object System.Management.Automation.PSCredential $userid,$password 

$session = New-PSSession ConfigurationName Microsoft.Exchange ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred -Authentication basic AllowRedirection

Import-PSSession $session AllowClobber

#Connect to O365 Tenant 

Connect-MsolService -Credential $cred 

  

$Groups = Get-UnifiedGroup | Where-Object {$_.WhenCreated ge ((Get-Date).AddDays(-1)) -and ($_.AccessType eq “Public”)} 

if ($Groups eq $null){

“”

} else {

$Body = $Groups | select Alias, AccessType, ManagedBy, SharePointSiteURL | fl 

$Body = $Body | Out-String 

$body = “The following PUBLIC groups were created in the last 24 hours. Please check with group owner that this is necessary.`n + $Body

Send-MailMessage -Body $Body -From Office365Reports@yourdom.ain -Subject “Office 365 Teams and Groups created in the last day” -To Administrator@yourdom.ain  

 SmtpServer SMTP.your.domain

} 

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s