PreparePlacesGroups.ps1
<#PSScriptInfo .VERSION 3.0 .GUID b9e7fb23-a071-4441-97fe-a13c71e9975c .AUTHOR jayam, syhaider .COMPANYNAME .COPYRIGHT .TAGS .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES .PRIVATEDATA #> <# .DESCRIPTION This script creates mail-enabled security groups for Places features. #> Param() $modules = Get-Module $exoInstalled = $false foreach ($module in $modules) { if ($module -contains "ExchangeOnline") { $exoInstalled = true } } if ($false -eq $exoInstalled) { Write-Host "Adding the Exchange module" Install-Module -Name ExchangeOnlineManagement Connect-ExchangeOnline } $displayNameCore = "Places Users [8C8BF34B-6BB8-4441-A911-3A990C9D838B]" $displayNamePrem = "Places Advanced Users [8C8BF34B-6BB8-4441-A911-3A990C9D838B]" $displayNameMobile = "Places Mobile Users [8C8BF34B-6BB8-4441-A911-3A990C9D838B]" $displayNameAnalytics = "Places Analytics Users [8C8BF34B-6BB8-4441-A911-3A990C9D838B]" $displayNamePlacesFinder = "Places Finder Users [8C8BF34B-6BB8-4441-A911-3A990C9D838B]" $placesUsers = Get-distributionGroup $displayNameCore -ErrorAction 'silentlycontinue' if (!$placesUsers) { Write-Host "Creating a security group - Places Users" $placesUsers = New-DistributionGroup -Alias "placesUsers" -DisplayName $displayNameCore -Name "Places Users" -Type Security } $mobileUsers = Get-distributionGroup $displayNameMobile -ErrorAction 'silentlycontinue' if (!$mobileUsers) { Write-Host "Creating a security group - Places Mobile Users" $mobileUsers = New-DistributionGroup -Alias "placesMobile" -DisplayName $displayNameMobile -Name "Places Mobile Users" -Type Security } $analyticsUsers = Get-distributionGroup $displayNameAnalytics -ErrorAction 'silentlycontinue' if (!$analyticsUsers) { Write-Host "Creating a security group - Places Analytics Users" $analyticsUsers = New-DistributionGroup -Alias "placesAnalytics" -DisplayName $displayNameAnalytics -Name "Places Analytics Users" -Type Security } $premGroup = Get-distributionGroup $displayNamePrem -ErrorAction 'silentlycontinue' if (!$premGroup) { Write-Host "Creating a security group - Places Advanced Features" $premGroup = New-DistributionGroup -Alias "placesAdvanced" -DisplayName $displayNamePrem -Name "Places Advanced Users" -Type Security } $placesFinderUsers = Get-distributionGroup $displayNamePlacesFinder -ErrorAction 'silentlycontinue' if (!$placesFinderUsers) { Write-Host "Creating a security group - Places Finder Users" $placesFinderUsers = New-DistributionGroup -Alias "placesFinder" -DisplayName $displayNamePlacesFinder -Name "Places Finder Users" -Type Security } $placesUsersMembers = Get-DistributionGroupMember $placesUsers $premGroupAdded = $false foreach($placesUser in $placesUsersMembers) { if ($placesUser.Id -eq $premGroup.Id) { $premGroupAdded = $true } } if ($false -eq $premGroupAdded) { Write-Host "Adding Places Advanced Feature Users to the Places Users group" Add-DistributionGroupMember $placesUsers.Id -Member $premGroup } $dgMembers = Get-DistributionGroupMember $premGroup.Id $addMobileToDG = $true $addAnalyticsToDG = $true $addPlacesFinderToDG = $true foreach($dgMem in $dgMembers) { if ($dgMem.Id -eq $mobileUsers.Id) { $addMobileToDG = $false } if ($dgMem.Id -eq $analyticsUsers.Id) { $addAnalyticsToDG = $false } if ($dgMem.Id -eq $placesFinderUsers.Id) { $addPlacesFinderToDG = $false } } if ($addMobileToDG) { Write-Host "Adding Places Mobile Users to the Places Advanced Features group" Add-DistributionGroupMember $premGroup.Id -Member $mobileUsers } if ($addAnalyticsToDG) { Write-Host "Adding Places Analytics Users to the Places Advanced Features group" Add-DistributionGroupMember $premGroup.Id -Member $analyticsUsers } if ($addPlacesFinderToDG) { Write-Host "Adding Places Finder Users to the Places Advanced Features group" Add-DistributionGroupMember $premGroup.Id -Member $placesFinderUsers } Write-Host "Places Security Groups have been created." |