Skip to content

Instantly share code, notes, and snippets.

@melvinpetix
Last active November 14, 2022 04:14
Show Gist options
  • Save melvinpetix/b5aaaf31f3a234697cdfc076c5e28d00 to your computer and use it in GitHub Desktop.
Save melvinpetix/b5aaaf31f3a234697cdfc076c5e28d00 to your computer and use it in GitHub Desktop.
<#
Name = CreateMicrosoftTeamsRoomResource
Description = Create and setup a Microsoft Teams Room in Microsoft Office 365
Version = 2
#>
[CmdletBinding()]
param (
[int]$step,
[string]$name,
[string]$displayname,
[string]$submittedby
)
set-executionpolicy -scope CurrentUser -executionPolicy unrestricted -force
# REQUIRED!!!
Import-Module .\PSScript\mtr.psm1
[string] $log
[string] $err
# Script Variables
$rmdomain = 'novonordisk.com'
$RoomLicence = 'MTR_Device_License_Management'
$RoomUserPrincipalName = ($RoomAlias + '@' + $rmdomain)
$CsOnlineUserTemplate = ($CsOnlineUser + '@' + $rmdomain)
$CsOnlineUser = 'autouserw2k@novonordisk.com'
$submittedby = ($submittedby.substring($submittedby.length - 4, 4) + '@' + $rmdomain)
$genPass = Random-Password -Length 15 -SpecialChar 1
$newpassword =
try{
while($step -ge 1){
switch($step){
"0"{
# Function Import Modules and 0365 connect (mtr.psm1)
Connect-0ffice365
}
"1"{
# Create Mailbox
if(-not(Get-Mailbox -Identity $name)){
$parmNewMailbox = @{
Name = $name
Alias = $displayname
Room = $true
EnableRoomMailboxAccount = $true
MicrosoftOnlineServicesID = $RoomUserPrincipalName
RoomMailboxPassword = (ConvertTo-SecureString -String $newpassword -AsPlainText -Force)
}
New-Mailbox @paramNewMailbox -ErrorAction Stop -ErrorVariable 1
while (-not ($mbx = Get-EXOMailbox $RoomUserPrincipalName -ErrorAction SilentlyContinue)) {
Write-Host "Creating Mailbox.. Please wait"
Start-Sleep -Seconds 60
}Subject = 'Meeting Room $name Created'
$log += "$timestamp mailbox $name created.`r`n";
# Send password to email
Send-Email -To $displayname -From Body 'Meeting Room $name password: $newpassword'
$log += "$timestamp mailbox email sent.`r`n";
}
}
"2" {
#Calendar Setting
$paramSetCalendarProcessing = @{
Identity = $RoomName
AutomateProcessing = 'AutoAccept'
AddOrganizerToSubject = $false
DeleteComments = $false
DeleteSubject = $false
RemovePrivateProperty = $false
}
Set-CalendarProcessing @paramSetCalendarProcessing
log += "$timestamp Calendar setting completed.`r`n";
}
"3"{
# Enable 0365 mailbox
$paramSetMsolUser = @{
UserPrincipalName = $RoomUserPrincipalName
PasswordNeverExpires = $true
}
Set-MsolUser @$paramSetMsolUser
log += "$timestamp email enabled.`r`n";
}
"4"{
#Apply the license
$paramSetMsolUserLicense = @{
UserPrincipalName = $RoomUserPrincipalName
AddLicenses = $RoomLicence
}
Set-MsolUserLicense @paramSetMsolUserLicense
log += "$timestamp added license.`r`n";
}
"5"{
# Enable Skype for Business/Teams
$paramEnableCsMeetingRoom = @{
Identity = $RoomUserPrincipalName
RegistrarPool = (Get-CsOnlineUser -Identity $CsOnlineUserTemplate | Select-Object -ExpandProperty RegistrarPool)
SipAddressType = 'EmailAddress'
}
Enable-CsMeetingRoom @paramEnableCsMeetingRoom
log += "$timestamp enabled skype/teams connector.`r`n";
break;
}
}
}
}
catch {
$log += "$timestamp Error: $PSItem.`r`n";
}
Finally {
Disconnect-ExchangeOnline -Confirm:$false -InformationAction Ignore -ErrorAction SilentlyContinue
Disconnect-PSSession -Confirm:$false -InformationAction Ignore -ErrorAction SilentlyContinue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment