Class/TeamsFunctions.ArgumentCompleter.psm1
# Module: TeamsFunctions # Function: ArgumentCompleter # Author: David Eberhardt # Updated: 10-JUL 2022 # Status: Live # ArgumentCompleter # Defines scripts blocks to be used either through [ArgumentCompleter] in the Function or through Register-ArgumentCompleter # Naming convention TeamsFunctionsArgumentCompleterScriptBlock (TfAcSb) followed by the logical name. <# Usage [Parameter(ParameterSetName = 'OVP', HelpMessage = 'Filters based on OnlineVoiceRoutingPolicy')] [AllowNull()] [Alias('OVP')] [ValidateScript( { if ($_ -in $(&$global:TfAcSbVoiceRoutingPolicy)) { return $true } else { throw [System.Management.Automation.ValidationMetadataException] "Value must be a valid Policy in the Tenant. Use Intellisense for options" } })] [ArgumentCompleter({ &$global:TfAcSbVoiceRoutingPolicy })] [String]$OnlineVoiceRoutingPolicy, #> # CsOnlinePSTNGateway $global:TfAcSbTeasmsPSTNGateway = { $null = Assert-MicrosoftTeamsConnection (Get-CsOnlinePSTNGateway | Select-Object Identity).Identity } # CsOnlineVoiceRoute $global:TfAcSbOnlineVoiceRoute = { $null = Assert-MicrosoftTeamsConnection (Get-CsOnlineVoiceRoute | Select-Object Identity).Identity } # CsOnlinePstnUsage $global:TfAcSbOnlinePstnUsage = { $null = Assert-MicrosoftTeamsConnection (Get-CsOnlinePstnUsage Global).Usage } # CsOnlineVoiceRoutingPolicy $global:TfAcSbVoiceRoutingPolicy = { $null = Assert-MicrosoftTeamsConnection $((Get-CsOnlineVoiceRoutingPolicy | Where-Object Identity -NE Global | Sort-Object -Property Identity).Identity -replace 'Tag:', '') } # CsTenantDialPlan $global:TfAcSbTenantDialPlan = { $null = Assert-MicrosoftTeamsConnection $((Get-CsTenantDialPlan | Sort-Object -Property Identity).Identity -replace 'Tag:', '') } # NormalizationRules - replacement for CsVoiceNormalizationRule #TEST how long this would take without caching $global:TfAcSbTenantDialPlanNormalizationRuleIds = { $null = Assert-MicrosoftTeamsConnection if (-not $global:TeamsFunctionsTenantDialPlanNormalizationRuleIds) { $global:TeamsFunctionsTenantDialPlanNormalizationRuleIds = (Get-CsTenantDialPlan | Sort-Object -Property Identity).Identity -replace 'Tag:', '' | ForEach-Object { $DPName = $_.Identity -replace 'Tag:', '' $_.NormalizationRules | ForEach-Object { "$DPName\$($_.Name)" } } } $global:TeamsFunctionsTenantDialPlanNormalizationRuleIds } # CsTeamsIPPhonePolicy $global:TfAcSbTeamsIPPhonePolicy = { $null = Assert-MicrosoftTeamsConnection (Get-CsTeamsIPPhonePolicy | Sort-Object -Property Identity).Identity -replace 'Tag:', '' } # CsCallingLineIdentity $global:TfAcSbTeamsCallingLineIdentity = { $null = Assert-MicrosoftTeamsConnection (Get-CsCallingLineIdentity | Sort-Object -Property Identity).Identity -replace 'Tag:', '' } # CsTeamsCallingPolicy $global:TfAcSbTeamsCallingPolicy = { $null = Assert-MicrosoftTeamsConnection (Get-CsTeamsCallingPolicy | Sort-Object -Property Identity).Identity -replace 'Tag:', '' } # CsTeamsCallParkPolicy $global:TfAcSbTeamsCallParkPolicy = { $null = Assert-MicrosoftTeamsConnection (Get-CsTeamsCallParkPolicy | Sort-Object -Property Identity).Identity -replace 'Tag:', '' } # CsTeamsEmergencyCallingPolicy $global:TfAcSbEmergencyCallingPolicy = { $null = Assert-MicrosoftTeamsConnection (Get-CsTeamsEmergencyCallingPolicy | Sort-Object -Property Identity).Identity -replace 'Tag:', '' } # CsTeamsEmergencyCallRoutingPolicy $global:TfAcSbEmergencyCallRoutingPolicy = { $null = Assert-MicrosoftTeamsConnection (Get-CsTeamsEmergencyCallRoutingPolicy | Sort-Object -Property Identity).Identity -replace 'Tag:', '' } # ISO3166Country $global:TfAcSbTwoLetterCountryCode = { if (-not $global:TeamsFunctionsCountryTable) { $global:TeamsFunctionsCountryTable = (Get-ISO3166Country | Select-Object TwoLetterCode).TwoLetterCode } $global:TeamsFunctionsCountryTable } # PublicHolidayCountry - Subset of ISO3166Country (supported by Nager.API) $global:TfAcSbNagerAPICountryCode = { (Get-PublicHolidayCountry | Sort-Object CountryCode).CountryCode } # TeamsFunctionsMSAzureAdLicenses - License $global:TfAcSbAzureAdLicense = { if (-not $global:TeamsFunctionsMSAzureAdLicenses) { $global:TeamsFunctionsMSAzureAdLicenses = Get-AzureAdLicense -WarningAction SilentlyContinue } ($global:TeamsFunctionsMSAzureAdLicenses).ParameterName.Split('', [System.StringSplitOptions]::RemoveEmptyEntries) | Sort-Object } # TeamsFunctionsMSAzureAdLicenses - CallingPlanLicense $global:TfAcSbCallingPlanLicense = { if (-not $global:TeamsFunctionsMSAzureAdLicenses) { $global:TeamsFunctionsMSAzureAdLicenses = Get-AzureAdLicense -WarningAction SilentlyContinue } $global:TeamsFunctionsMSAzureAdCallingPlan = ($global:TeamsFunctionsMSAzureAdLicenses | Where-Object LicenseType -EQ 'CallingPlan') $global:TeamsFunctionsMSAzureAdCallingPlan.ParameterName.Split('', [System.StringSplitOptions]::RemoveEmptyEntries) | Sort-Object } # TeamsFunctionsMSAzureAdLicenseServicePlans - License Service Plan $global:TfAcSbAzureAdLicenseServicePlan = { if (-not $global:TeamsFunctionsMSAzureAdLicenseServicePlans) { $global:TeamsFunctionsMSAzureAdLicenseServicePlans = Get-AzureAdLicenseServicePlan -WarningAction SilentlyContinue } ($global:TeamsFunctionsMSAzureAdLicenseServicePlans).ServicePlanName.Split('', [System.StringSplitOptions]::RemoveEmptyEntries) | Sort-Object -Unique } # CsTenantNetworkSite - Network Site $global:TfAcSbTeamsNetworkSiteId = { $null = Assert-MicrosoftTeamsConnection (Get-CsTenantNetworkSite | Select-Object Identity).Identity } # CsTenantNetworkSubnet - Network Subnet $global:TfAcSbTeamsNetworkSubnetId = { $null = Assert-MicrosoftTeamsConnection (Get-CsTenantNetworkSubnet | Select-Object Identity).Identity } # CsAutoAttendantSupportedLanguage - AutoAttendant Language Id $global:TfAcSbSupportedLanguage = { $null = Assert-MicrosoftTeamsConnection if (-not $global:CsAutoAttendantSupportedLanguage) { $global:CsAutoAttendantSupportedLanguage = Get-CsAutoAttendantSupportedLanguage -ErrorAction SilentlyContinue } $($global:CsAutoAttendantSupportedLanguage) } # CsAutoAttendantSupportedTimeZone & TeamsFunctionsSupportedTimeZone - AutoAttendant TimeZone Id $global:TfAcSbSupportedTimeZone = { $null = Assert-MicrosoftTeamsConnection if (-not $global:CsAutoAttendantSupportedTimeZone) { $global:CsAutoAttendantSupportedTimeZone = Get-CsAutoAttendantSupportedTimeZone -ErrorAction SilentlyContinue } #[Collections.Generic.List[object]]$global:TeamsFunctionsSupportedTimeZone = $CsAutoAttendantSupportedTimeZone.DisplayName.Substring(1, $_.DisplayName.IndexOf(')')) | Get-Unique [Collections.Generic.List[object]]$global:TeamsFunctionsSupportedTimeZone = $CsAutoAttendantSupportedTimeZone.DisplayName | ForEach-Object { $_.Substring($_.IndexOf('(') + 1, $_.IndexOf(')') - 1) } | Get-Unique $global:TeamsFunctionsSupportedTimeZone } # CsAutoAttendantSupportedTimeZone & TeamsFunctionsSupportedTimeZone - AutoAttendant TimeZone Name #BODGE needs to b queried with 'if ("'$_'" -in $(&$global:TfAcSbSupportedTimeZoneName)) { $True } else {...}' #VALIDATE options without manually having to wrap this, either in Argumentcompleter itself or here. $global:TfAcSbSupportedTimeZoneName = { $null = Assert-MicrosoftTeamsConnection if (-not $global:CsAutoAttendantSupportedTimeZone) { $global:CsAutoAttendantSupportedTimeZone = Get-CsAutoAttendantSupportedTimeZone -ErrorAction SilentlyContinue } #[Collections.Generic.List[object]]$global:CsAutoAttendantSupportedTimeZoneName = $CsAutoAttendantSupportedTimeZone.DisplayName.Substring(1, $_.DisplayName.IndexOf(')')) | Get-Unique [Collections.Generic.List[string]]$global:CsAutoAttendantSupportedTimeZoneName = $CsAutoAttendantSupportedTimeZone.Id | ForEach-Object { "'$_'" } $global:CsAutoAttendantSupportedTimeZoneName } |