Private/Format-VoiceRoutingChainOutput.ps1
# Module: TeamsFunctions # Function: Teams Voice Routing Chain # Author: David Eberhardt # Updated: 26-AUG-2022 # Status: BETA function Format-VoiceRoutingChainOutput { <# .SYNOPSIS Helper function to construct the Voice Routing Chain Name string .DESCRIPTION Helper function to construct the Voice Routing Chain Name string Used in New-TeamsVoiceRoutingChain .PARAMETER Object The Output object from Format-VoiceRoutingChainInput .PARAMETER Region GeoRegion: AMER, EMEA or APAC .PARAMETER Country String. ISO 3166-alpha2 or -alpha3 2/3-digit Country Code .PARAMETER Site Optional String (3-10 digits). Site Identifier .PARAMETER CallRestriction Optional String. Unrestricted, International, National, EmergencyOnly or Custom .PARAMETER CustomRestrictionName Required String (3-10 digits) for Custom CallRestrictions only. .INPUTS PSCustomObject .OUTPUTS System.String .NOTES Step 1 - Format-VoiceRoutingChainInput - Deconstructs the string based on input. Step 2 - Format-VoiceRoutingChainOutput - Construct new name based on requirement .LINK https://github.com/DEberhardt/TeamsFunctions/tree/main/docs/ .LINK New-TeamsVoiceRoutingChain #> [CmdletBinding()] [OutputType([System.String])] param( [Parameter(Mandatory)] [Object]$Object, [Parameter()] [GeoRegion]$Region, [Parameter(HelpMessage = 'ISO 3166-alpha2 Country Code')] [string]$Country, [Parameter(HelpMessage = 'Site-Specific name')] [String]$Site, [Parameter(HelpMessage = 'Call Restriction Level')] [String]$CallRestriction, [Parameter(HelpMessage = 'Custom Name for the Call Restriction Level')] [String]$CustomRestrictionName ) #param begin { #Show-FunctionStatus -Level Live Write-Verbose -Message "[BEGIN ] $($MyInvocation.MyCommand)" # Setting Preference Variables according to Upstream settings if (-not $PSBoundParameters.ContainsKey('Verbose')) { $VerbosePreference = $PSCmdlet.SessionState.PSVariable.GetValue('VerbosePreference') } if (-not $PSBoundParameters.ContainsKey('Confirm')) { $ConfirmPreference = $PSCmdlet.SessionState.PSVariable.GetValue('ConfirmPreference') } if (-not $PSBoundParameters.ContainsKey('WhatIf')) { $WhatIfPreference = $PSCmdlet.SessionState.PSVariable.GetValue('WhatIfPreference') } if (-not $PSBoundParameters.ContainsKey('Debug')) { $DebugPreference = $PSCmdlet.SessionState.PSVariable.GetValue('DebugPreference') } else { $DebugPreference = 'Continue' } if ( $PSBoundParameters.ContainsKey('InformationAction')) { $InformationPreference = $PSCmdlet.SessionState.PSVariable.GetValue('InformationAction') } else { $InformationPreference = 'Continue' } if ( $PSBoundParameters.ContainsKey('CallRestriction') ) { if ( -not $PSBoundParameters.ContainsKey('CustomRestrictionName') ) { $CustomRestrictionName = 'Restricted' } } else { $CallRestriction = 'Unrestricted' } } #begin process { Write-Verbose -Message "[PROCESS] $($MyInvocation.MyCommand) - Processing Voice Routing Chain Name '$($Object.Name)'" # Step 1: Adding Region before remaining Name fragment (if any) [string]$ProtoName = [string]$Region + "$(if ( $Object.Name -ne '' ) { '-' + "$($Object.Name)" })" Write-Verbose -Message "Constructing String with Region: $ProtoName" # Step 2: Adding Site if provided AND if CallRestriction is not Unrestricted OR Site was replaced during deconstruction [string]$ProtoName = $ProtoName + "$(if ( $PSBoundParameters.ContainsKey('Site') -and ($CallRestriction -ne 'Unrestricted' -or $Object.Site )) { '-' + $Site })" Write-Verbose -Message "Constructing String with Site: $ProtoName" # Step 3: Adding Country if CallRestriction is not Unrestricted OR Site was provided and Site Code does not match the CountryCode $SiteAndCountry = ( $PSBoundParameters.ContainsKey('Country') -and $PSBoundParameters.ContainsKey('Site') ) $AddCountryIfSiteNotMatchingCountry = ( $SiteAndCountry -and $Site -notmatch "^$Country" ) $AddCountry = ($PSBoundParameters.ContainsKey('Country') -and $CallRestriction -ne 'Unrestricted') [string]$ProtoName = $ProtoName + "$(if($AddCountry -or $AddCountryIfSiteNotMatchingCountry ) { '-' + $Country })" Write-Verbose -Message "Constructing String with Country: $ProtoName" # Step 4: Adding CallRestriction if it is not Unrestricted; Adding CustomRestrictionName if provided, otherwise CallRestriction [string]$ProtoName = $ProtoName + "$(if ( $CallRestriction -ne 'Unrestricted' ) { '-' + $(if ($CallRestriction -eq 'Custom') { $CustomRestrictionName } else { $CallRestriction }) })" Write-Verbose -Message "Constructing String with CallRestriction: $ProtoName" # Output Write-Verbose -Message "[FINISH] $($MyInvocation.MyCommand) - Processing Voice Routing Chain Name '$ProtoName'" return $ProtoName } #process end { Write-Verbose -Message "[END ] $($MyInvocation.MyCommand)" } #end } # Format-VoiceRoutingChainOutput |