Skip to content
KBHost
Menu
216.73.216.170
KBHost
FileHost
Home
/
Knowledgebase
/
Office 365 & Azure
/
PowerShell & cmd
/
Create Mailbox with shared Calendar
Create Mailbox with shared Calendar
0
0
# Set user variables $TenantUser="admin@tenant.onmicrosoft.com" $UserDomain="@domain.com" $FirstName="Firstname" $LastName="Lastname" $Username="$FirstName" $Password="P@ssW0rd!" $License="O365_BUSINESS_ESSENTIALS" # Set UserUPN $UserUPN="$Username$UserDomain" # Connect to Exchange Online Import-Module ExchangeOnlineManagement Connect-ExchangeOnline -UserPrincipalName $TenantUser # Create user mailbox New-Mailbox -Alias $Username -Name $Username -FirstName $FirstName -LastName $LastName -DisplayName "$FirstName $LastName" -MicrosoftOnlineServicesID $UserUPN -Password (ConvertTo-SecureString -String $Password -AsPlainText -Force) -ResetPasswordOnNextLogon $false # Wait 20 seconds before next step Start-Sleep -s 20 # Connect to AzureAD Connect-AzureAD -AccountId $TenantUser # Set UsageLocation NL Set-AzureADUser -ObjectID $UserUPN -UsageLocation "NL" $AddSKU = $License,"" $RemoveSKU = "" # Create the objects we need to add and remove licenses $AddLicense = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense $RemoveLicense = "" $Licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses # Find the SkuID of the license we want to add and remove [string[]]$AddLicenseSkuId = (Get-AzureADSubscribedSku | Where-Object -Property SkuPartNumber -Value $AddSKU -IN).SkuID [string[]]$RemoveLicenseSkuiD = (Get-AzureADSubscribedSku | Where-Object -Property SkuPartNumber -Value $RemoveSKU -IN).SkuID # remove licenses foreach ($SkuId in $RemoveLicenseSkuiD) { [string]$RemoveLicense = $SkuId $Licenses.AddLicenses = @() $Licenses.RemoveLicenses = @() $Licenses.RemoveLicenses = $RemoveLicense $user_licenses = (Get-AzureADUser -ObjectId "O365.Test@domain.com").AssignedLicenses.SkuId $SkuPartNumber = Get-AzureADSubscribedSku | where {$_.SkuID -like $SkuId} | select -ExpandProperty SkuPartNumber if ($SkuId -in $user_licenses) { Set-AzureADUserLicense -ObjectId $UserUPN -AssignedLicenses $licenses Write-Host $SkuPartNumber "license has been removed!" -BackgroundColor Black -ForegroundColor Red } else { Write-Host $SkuPartNumber "was not assigned! - Skipping" -BackgroundColor Black -ForegroundColor Yellow } } # add licenses foreach ($SkuId in $AddLicenseSkuId) { $AddLicense.SkuId = $SkuId $Licenses.AddLicenses = @() $Licenses.RemoveLicenses = @() $Licenses.AddLicenses = $AddLicense $user_licenses = (Get-AzureADUser -ObjectId $UserUPN).AssignedLicenses.SkuId $SkuPartNumber = Get-AzureADSubscribedSku | where {$_.SkuID -like $SkuId} | select -ExpandProperty SkuPartNumber if ($SkuId -notin $user_licenses) { Set-AzureADUserLicense -ObjectId $UserUPN -AssignedLicenses $licenses Write-Host "Assigned license:"$SkuPartNumber -BackgroundColor Black -ForegroundColor Green } else { Write-Host $SkuPartNumber "was already assigned! - Skipping" -BackgroundColor Black -ForegroundColor Yellow } } # Wait 80 seconds before next step Start-Sleep -s 80 # Connect to Exchange Online Connect-ExchangeOnline -UserPrincipalName $TenantUser # Set user mailbox language NL Set-MailboxRegionalConfiguration -Identity $UserUPN -Language nl-nl -LocalizeDefaultFolderName -TimeZone "W. Europe Standard Time" # Set default calendar permissions Set-MailboxFolderPermission -Identity ${UserUPN}:\Agenda -User Default -AccessRights PublishingEditor
No sleep -
00:00
Password Generator
Most viewed
Connect to Office 365 with PowerShell
Silent update Microsoft Remote Desktop
Add Microsoft Photos app to Server 2019
Enable NFS client in Windows 10
Clear Outlook filter for all folders
Asus ZenWiFi LED color status
Ventoy Windows 11 To Go
Find and delete all snapshots
Most recent
Install or Update reMarkable
TrueNAS Clear failed jobs history
TrueNAS SSH Hetzner Storage Box Rsync
Print Screen from PowerShell
Create local user during Windows Setup
Force Microsoft 365 installation
Enable MailTips in Microsoft 365
Get Home Assistant Logs
We use cookies to ensure the best experience on our website. If you continue to use this site, we assume that you are happy with this.
Ok