Prepare-PlacesEnablement.ps1

<#PSScriptInfo

.VERSION 7.0

.GUID 4426682f-fed2-47fe-9a75-7d61f1764139

.AUTHOR jayam, syhaider

.COMPANYNAME

.COPYRIGHT

.TAGS

.LICENSEURI

.PROJECTURI

.ICONURI

.EXTERNALMODULEDEPENDENCIES

.REQUIREDSCRIPTS

.EXTERNALSCRIPTDEPENDENCIES

.RELEASENOTES


.PRIVATEDATA

#>


<#

.DESCRIPTION
 This script enables the groups created by the PreparePlacesGroups script with their corresponding Places features.

#>


param (
    [Alias("Places Web", "Places Web App")]
    [bool]$PlacesWebApp = $false,
    [Alias("Places Advanced Features", "PlacesPremium")]
    [bool]$PlacesAdvancedFeatures = $false,
    [Alias("Places Mobile", "PlacesMobile")]
    [bool]$PlacesMobileApp = $false,
    [Alias("Places Analytics Users", "AnalyticsUsers")]
    [bool]$PlacesAnalytics = $false,
    [Alias("Places Finder Users", "PlacesFinderUsers")]
    [bool]$PlacesFinder = $false
)

$modules = Get-Module
$placesInstalled = $false
#$azAccountInstalled = $false
foreach ($module in $modules)
{
    if ($module.Name -contains "MicrosoftPlaces")
    {
        $placesInstalled = $true
    }
}

if ($false -eq $placesInstalled)
{
    Write-Error "Please run the PreparePlacesPowershell7 script first" -ErrorAction Stop
}


$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]"

$tenants = Get-AzTenant
if ($tenants -is [array]) {
    $i = 0
    Write-Host "List of Tenants"
    Write-Host "---------------"
    foreach ($t in $tenants) {
        Write-Host "$($i+1) - $($t.TenantId) - $($t.Name)"
        $i++
    }
    Write-Host "------------------------------"
    $tenantNumber = Read-Host "Please enter the tenant number you want to use: "
    $tenant = $tenants[$tenantNumber-1]
}
else {
    $tenant = $tenants
}

function SetPlacesCore {
    Write-Host "Do you want to use the default group for Places Users (Created in step1)?"
    $useDefault = Read-Host "Enter [Y] for Yes or [N] for No: "
    if ($useDefault -eq "Y") {
        Write-Host "Using the default group for Places Users"
    }
    else {
        $displayNameCore = Read-Host "Please enter the display name of the group you want to use for Places Users: "
    }

    Write-Host "Searching for group - $displayNameCore"

    $plCoreGroup = Get-AzADGroup -DisplayName $displayNameCore
    if ($null -eq $plCoreGroup) {
        Write-Error -Message "Please create a DL with Display Name - $displayNameCore" -ErrorAction Stop
    }

    if ('Unified' -eq $plCoreGroup.GroupType){
        Write-Error -Message "Please create a distribution or security group $displayNameCore is a M365 group which is not supported" -ErrorAction Stop
    }

    Write-Host "Found Group $displayNameCore"

    $oidtidCoreGroup=$plCoreGroup.Id + "@" + $tenant.TenantId
    $groupstring = "Default:false,OID:" + $oidtidCoreGroup + ":true"

    Write-Host "Enabling Places Web App"

    Set-PlacesSettings -Collection Places -EnablePlacesWebApp  $groupstring | Out-Null

    Set-PlacesSettings -Collection Places -EnableBuildings 'Default:true'
}

function SetPremiumFeatures {
    param([bool]$settingValue)
    Write-Host "Enabling Places Advanced Features for the tenant"
    
    Write-Host "Do you want to use the default group for Places Advanced Users (Created in step1)?"
    $useDefault = Read-Host "Enter [Y] for Yes or [N] for No: "
    if ($useDefault -eq "Y") {
        Write-Host "Using the default group for Places Advanced Users"
    }
    else {
        $displayNamePrem = Read-Host "Please enter the display name of the group you want to use for Places Advanced Users: "
    }

    Write-Host -Message "Looking for group - $displayNamePrem"

    $plGroup = Get-AzADGroup -DisplayName $displayNamePrem 
    if ($null -eq $plGroup) {
        Write-Error -Message "Unable to find a group with Display Name $displayNamePrem" -ErrorAction Stop        
    }

    Write-Host -Message "Tenant being used - $tenant.TenantId"
    $oidtidGroup=$plGroup.Id + "@" + $tenant.TenantId
    if ($settingValue)
    {
        $groupstring = "Default:false,OID:" + $oidtidGroup + ":true"
    }
    else
    {
        Write-Host "Setting Places Advanced to false"
        $groupstring = "Default:false,OID:" + $oidtidGroup + ":false"
        Write-Host $groupstring
    }
        
    Write-Host "Enabling Advanced Places features"

    Set-PlacesSettings -Collection Places -PlacesEnabled $groupstring -ErrorAction SilentlyContinue
}
function EnablePlacesMobileApp {
    Write-Host "Enabling the group that can use the Places iOS App"

    Write-Host "Do you want to use the default group for Places Mobile Users (Created in step1)?"
    $useDefault = Read-Host "Enter [Y] for Yes or [N] for No: "
    if ($useDefault -eq "Y") {
        Write-Host "Using the default group for Places Mobile Users"
    }
    else {
        $displayNameMobile = Read-Host "Please enter the display name of the group you want to use for Places Mobile Users: "
    }

    Write-Host "Looking for group - $displayNameMobile"
    $plGroup = Get-AzADGroup -DisplayName $displayNameMobile 
    if ($null -eq $plGroup) 
    {
        Write-Error -Message "Unable to find a group with Display Name $displayNameMobile" -ErrorAction Stop        
    }

    $oidtidGroup=$plGroup.Id + "@" + $tenant.TenantId
    $groupstring = "Default:false,OID:" + $oidtidGroup + ":true"

    Set-PlacesSettings -Collection Places -EnablePlacesMobileApp $groupstring
}

function EnablePlacesAnalytics {
    Write-Host "Enabling the group that can see Places Analytics"
    
    Write-Host "Do you want to use the default group for Places Analytics Users (Created in step1)?"
    $useDefault = Read-Host "Enter [Y] for Yes or [N] for No: "
    if ($useDefault -eq "Y") {
        Write-Information "Using the default group for Places Analytics Users"
    }
    else {
        $displayNameAnalytics = Read-Host "Please enter the display name of the group you want to use for Places Analytics Users: "
    }

    Write-Host "Looking for group - $displayNameAnalytics"
    $plGroup = Get-AzADGroup -DisplayName $displayNameAnalytics
    if ($null -eq $plGroup) {
        Write-Error -Message "Unable to find a group with Display Name $displayNameAnalytics" -ErrorAction Stop
    }

    $oidtidGroup=$plGroup.Id + "@" + $tenant.TenantId
    $groupstring = "Default:false,OID:" + $oidtidGroup + ":true"

    Set-PlacesSettings -Collection Places -SpaceAnalyticsEnabled $groupstring
}

function EnablePlacesFinder {
    Write-Host "Enabling the group that can see Places Finder"

    Write-Host "Do you want to use the default group for Places Finder Users (Created in step1)?"
    $useDefault = Read-Host "Enter [Y] for Yes or [N] for No: "
    if ($useDefault -eq "Y") {
        Write-Host "Using the default group for Places Finder Users"
    }
    else {
        $displayNamePlacesFinder = Read-Host "Please enter the display name of the group you want to use for Places Finder Users: "
    }

    Write-Host "Looking for group - $displayNamePlacesFinder"
    $plGroup = Get-AzADGroup -DisplayName $displayNamePlacesFinder
    if ($null -eq $plGroup) {
        Write-Error -Message "Unable to find a group with Display Name $displayNamePlacesFinder" -ErrorAction Stop
    }

    $oidtidGroup=$plGroup.Id + "@" + $tenant.TenantId
    $groupstring = "Default:false,OID:" + $oidtidGroup + ":true"

    Set-PlacesSettings -Collection Places -PlacesFinderEnabled $groupstring
}


$settingEnabled = $false
function GetPlacesSetting {
    param([string]$placesSetting)
    $settings = Get-PlacesSettings -Collection Places -ReadFromPrimary

    Write-Information $placesSetting
    foreach ($setting in $settings)
    {
        if ($setting.Name -eq $placesSetting)
        {
            $scopedValues = $setting.ScopedValues;
            foreach($scope in $scopedValues)
            {
                if ($scope.ScopeValue.BoolValue)
                {
                    $settingEnabled = $true;
                    break;
                }
            }
        }

        if ($settingEnabled)
        {
            break;
        }
    }
    return $settingEnabled
}

Write-Host $

$coreRun = $false;
if ($PlacesWebApp)
{
    SetPlacesCore
    $coreRun = $true;
}
if ($PlacesAdvancedFeatures)
{
    Write-Host "PlacesAdvancedFeatures set to $PlacesAdvancedFeatures"
    if (!$coreRun)
    {
        SetPlacesCore
    }
    SetPremiumFeatures($PlacesAdvancedFeatures)
}

if ($PlacesMobileApp)
{
    $a = "Places.PlacesEnabled"
    $enabledSetting = GetPlacesSetting $a
    if (!$enabledSetting)
    {
        Write-Error -Message "To enable Places Mobile, please enable PlacesAdvancedFeatures first" -Exception ([System.IO.FileNotFoundException]::new()) -ErrorAction Stop
    }
    EnablePlacesMobileApp
}
if ($PlacesAnalytics)
{
    $a = "Places.PlacesEnabled"
    $enabledSetting = GetPlacesSetting $a
    if (!$enabledSetting)
    {
        Write-Error -Message "To enable Analytics, please enable PlacesAdvancedFeatures first" -Exception ([System.IO.FileNotFoundException]::new()) -ErrorAction Stop
    }
    EnablePlacesAnalytics
}
if ($PlacesFinder)
{
    $a = "Places.PlacesEnabled"
    $enabledSetting = GetPlacesSetting $a
    if (!$enabledSetting)
    {
        Write-Error -Message "To enable Places Finder, please enable PlacesAdvancedFeatures first" -Exception ([System.IO.FileNotFoundException]::new()) -ErrorAction Stop
    }
    EnablePlacesFinder
}

Write-Host "The Prepare-PlacesEnablement script version is 7.0"