Create NEW_Assign_Teams_AU_or_NZ_DDI.ps1
This commit is contained in:
172
Powershell/From Evernote/NEW_Assign_Teams_AU_or_NZ_DDI.ps1
Normal file
172
Powershell/From Evernote/NEW_Assign_Teams_AU_or_NZ_DDI.ps1
Normal file
@@ -0,0 +1,172 @@
|
||||
$MainMenu = {
|
||||
Write-Host " ************************************************"
|
||||
Write-Host " * Assign Teams Calling Number to AU or NZ User *"
|
||||
Write-Host " ************************************************"
|
||||
Write-Host
|
||||
Write-Host " 1.) Connect To Teams Online"
|
||||
Write-Host " 2.) Export Currently Assigned Numbers"
|
||||
Write-Host " 3.) Assign AU Number"
|
||||
Write-Host " 4.) Assign NZ Number"
|
||||
Write-Host " 5.) Quit"
|
||||
Write-Host
|
||||
Write-Host " Select an option and press Enter: " -nonewline
|
||||
}
|
||||
cls
|
||||
$psc = '@pscconsulting.com'
|
||||
Do {
|
||||
cls
|
||||
Invoke-Command $MainMenu
|
||||
$Select = Read-Host
|
||||
Switch ($Select)
|
||||
{
|
||||
1 {
|
||||
Write-Host "Checking For Teams Module"
|
||||
if (Get-Module -ListAvailable -Name MicrosoftTeams) {
|
||||
Write-Host "MicrosoftTeams Module Already Installed - Importing"
|
||||
Import-Module MicrosoftTeams
|
||||
Connect-MicrosoftTeams
|
||||
}
|
||||
else {
|
||||
Write-Host "MicrosoftTeams Module does not exist - Installing"
|
||||
Install-Module MicrosoftTeams -Force -AllowClobber
|
||||
Import-Module MicrosoftTeams
|
||||
Connect-MicrosoftTeams
|
||||
}
|
||||
}
|
||||
2 {
|
||||
|
||||
function Write-ProgressHelper {
|
||||
param (
|
||||
[int]$StepNumber,
|
||||
[string]$Message
|
||||
)
|
||||
Write-Progress -Activity 'Export All Current DDI Numbers That Are In Use to C:\Temp\' -Status $Message -PercentComplete (($StepNumber / $steps) * 100)
|
||||
}
|
||||
$script:steps = ([System.Management.Automation.PsParser]::Tokenize((gc "$PSScriptRoot\$($MyInvocation.MyCommand.Name)"), [ref]$null) | where { $_.Type -eq 'Command' -and $_.Content -eq 'Write-ProgressHelper' }).Count
|
||||
$stepCounter = 0
|
||||
Write-ProgressHelper -Message 'Checking For Temp Direcory' -StepNumber ($stepCounter++)
|
||||
Start-Sleep -Seconds 2.5
|
||||
$ErrorActionPreference="SilentlyContinue"
|
||||
#Check If Directory Exists #############
|
||||
$DirectoryToCreate = "C:\Temp\"
|
||||
if (-not (Test-Path -LiteralPath $DirectoryToCreate)) {
|
||||
Write-Host "Directory does not exist - creating..."
|
||||
New-Item -Path $DirectoryToCreate -ItemType Directory -ErrorAction Stop | Out-Null #-Force
|
||||
Write-Host "Successfully created directory '$DirectoryToCreate'."
|
||||
}
|
||||
else {
|
||||
Write-Host "Directory already exists"
|
||||
}
|
||||
Write-ProgressHelper -Message 'Checking For Temp Direcory' -StepNumber ($stepCounter++)
|
||||
Start-Sleep -Seconds 2.5
|
||||
#Connect to Teams
|
||||
Write-Host "Connecting to MS Teams"
|
||||
Connect-MicrosoftTeams
|
||||
Write-ProgressHelper -Message 'Getting Used Numbers and Exporting to CSV' -StepNumber ($stepCounter++)
|
||||
Start-Sleep -Seconds 2.5
|
||||
#Settings ##############################
|
||||
#. "_Settings.ps1" | Out-Null
|
||||
$FileName = "TeamsAssignedNumbers_" + (Get-Date -Format s).replace(":","-") +".csv"
|
||||
$FilePath = "C:\Temp\$FileName"
|
||||
$OutputType = "CSV" #OPTIONS: CSV - Outputs CSV to specified FilePath, CONSOLE - Outputs to console
|
||||
##############################
|
||||
$Regex1 = '^(?:tel:)?(?:\+)?(\d+)(?:;ext=(\d+))?(?:;([\w-]+))?$'
|
||||
$Array1 = @()
|
||||
#Get Users with LineURI
|
||||
$UsersLineURI = Get-CsOnlineUser -Filter {LineURI -ne $Null}
|
||||
if($UsersLineURI -ne $null)
|
||||
{
|
||||
foreach($item in $UsersLineURI)
|
||||
{
|
||||
$Matches = @()
|
||||
$Item.LineURI -match $Regex1 | out-null
|
||||
|
||||
$myObject1 = New-Object System.Object
|
||||
$myObject1 | Add-Member -type NoteProperty -name "LineURI" -Value $Item.LineURI
|
||||
$myObject1 | Add-Member -type NoteProperty -name "DDI" -Value $Matches[1]
|
||||
# $myObject1 | Add-Member -type NoteProperty -name "Ext" -Value $Matches[2]
|
||||
$myObject1 | Add-Member -type NoteProperty -name "DisplayName" -Value $Item.DisplayName
|
||||
# $myObject1 | Add-Member -type NoteProperty -name "FirstName" -Value $Item.FirstName
|
||||
# $myObject1 | Add-Member -type NoteProperty -name "LastName" -Value $Item.LastName
|
||||
$myObject1 | Add-Member -type NoteProperty -name "Type" -Value "User"
|
||||
$Array1 += $myObject1
|
||||
}
|
||||
}
|
||||
#Get meeting room numbers
|
||||
$MeetingRoomLineURI = Get-CsMeetingRoom -Filter {LineURI -ne $Null}
|
||||
if($MeetingRoomLineURI -ne $null)
|
||||
{
|
||||
Write-Verbose "Processing Meeting Room Numbers"
|
||||
foreach($Item in $MeetingRoomLineURI)
|
||||
{
|
||||
$Matches = @()
|
||||
$Item.LineURI -match $Regex1 | out-null
|
||||
|
||||
$myObject1 = New-Object System.Object
|
||||
$myObject1 | Add-Member -type NoteProperty -name "LineURI" -Value $Item.LineURI
|
||||
$myObject1 | Add-Member -type NoteProperty -name "DDI" -Value $Matches[1]
|
||||
$myObject1 | Add-Member -type NoteProperty -name "Ext" -Value $Matches[2]
|
||||
$myObject1 | Add-Member -type NoteProperty -name "DisplayName" -Value $Item.DisplayName
|
||||
$myObject1 | Add-Member -type NoteProperty -name "Type" -Value "MeetingRoom"
|
||||
$Array1 += $myObject1
|
||||
}
|
||||
}
|
||||
#Get online resource accounts
|
||||
$OnlineApplicationInstanceLineURI = Get-CsOnlineApplicationInstance | where {$_.PhoneNumber -ne $Null}
|
||||
if($OnlineApplicationInstanceLineURI -ne $null)
|
||||
{
|
||||
Write-Verbose "Processing Online Application Instances (Resource Accounts) Numbers"
|
||||
foreach($Item in $OnlineApplicationInstanceLineURI)
|
||||
{
|
||||
$Matches = @()
|
||||
$Item.PhoneNumber -match $Regex1 | out-null
|
||||
|
||||
$myObject1 = New-Object System.Object
|
||||
$myObject1 | Add-Member -type NoteProperty -name "LineURI" -Value $Item.PhoneNumber
|
||||
$myObject1 | Add-Member -type NoteProperty -name "DDI" -Value $Matches[1]
|
||||
$myObject1 | Add-Member -type NoteProperty -name "Ext" -Value $Matches[2]
|
||||
$myObject1 | Add-Member -type NoteProperty -name "DisplayName" -Value $Item.DisplayName
|
||||
$myObject1 | Add-Member -type NoteProperty -name "Type" -Value $(if ($item.ApplicationId -eq "ce933385-9390-45d1-9512-c8d228074e07") {"Auto Attendant Resource Account"} elseif ($item.ApplicationId -eq "11cd3e2e-fccb-42ad-ad00-878b93575e07") {"Call Queue Resource Account"} else {"Unknown Resource Account"})
|
||||
$Array1 += $myObject1
|
||||
}
|
||||
}
|
||||
if($OutputType -eq "CSV")
|
||||
{
|
||||
$Array1 | export-csv $FilePath -NoTypeInformation
|
||||
Write-Host "ALL DONE!! Your file has been saved to $FilePath."
|
||||
}
|
||||
elseif($OutputType -eq "CONSOLE")
|
||||
{
|
||||
$Array1 | FT -AutoSize -Property LineURI,DDI,Ext,DisplayName,Type
|
||||
Write-Host "ALL DONE!!"
|
||||
}
|
||||
else
|
||||
{
|
||||
$Array1 | FT -AutoSize -Property LineURI,DDI,Ext,DisplayName,Type
|
||||
Write-Host "WARNING: Valid output type not set, defaulted to console."
|
||||
Read-Host -Prompt "Press any key to continue..."
|
||||
}
|
||||
}
|
||||
3 {
|
||||
$firstname = Read-Host -Prompt "Enter User First Name"
|
||||
$lastname = Read-Host -Prompt "Enter User Last Name"
|
||||
$AUPhone = Read-Host -Prompt "Enter User Phone Number, Including Single Digit Area Code Only. Country Code Not Required"
|
||||
$Name = "$firstname.$lastname@pscconsulting.com"
|
||||
Set-CsPhoneNumberAssignment -Identity $Name -PhoneNumber +61$AUPhone -PhoneNumberType DirectRouting
|
||||
Set-CsPhoneNumberAssignment -Identity $Name -EnterpriseVoiceEnabled $true
|
||||
Grant-CsOnlineVoiceRoutingPolicy -Identity $Name -PolicyName MacTelAustralia
|
||||
Read-Host -Prompt "Press any key to continue..."
|
||||
}
|
||||
4 {
|
||||
$firstname = Read-Host -Prompt "Enter User First Name"
|
||||
$lastname = Read-Host -Prompt "Enter User Last Name"
|
||||
$NZPhone = Read-Host -Prompt "Enter User Phone Number, Including Single Digit Area Code Only. Country Code Not Required"
|
||||
$Name = "$firstname.$lastname@pscconsulting.com"
|
||||
Set-CsPhoneNumberAssignment -Identity $Name -PhoneNumber +64$NZPhone -PhoneNumberType DirectRouting
|
||||
Set-CsPhoneNumberAssignment -Identity $Name -EnterpriseVoiceEnabled $true
|
||||
Grant-CsOnlineVoiceRoutingPolicy -Identity $Name -PolicyName "Vocus NZ International"
|
||||
Read-Host -Prompt "Press any key to continue..."
|
||||
}
|
||||
}
|
||||
}
|
||||
While ($Select -ne 5)
|
||||
Reference in New Issue
Block a user