Public/Support/Licensing/Test-AzureAdLicenseContainsServicePlan.ps1
# Module: TeamsFunctions # Function: Testing # Author: David Eberhardt # Updated: 18-JUL-2021 # Status: Live function Test-AzureAdLicenseContainsServicePlan { <# .SYNOPSIS Tests whether a specific ServicePlan is included in an AzureAd License .DESCRIPTION If an AzureAd License contains a specific Service Plan thi function will return $TRUE, otherwise $FALSE .PARAMETER License Mandatory. The License to test .PARAMETER ServicePlan Mandatory. The ServicePlan to query .EXAMPLE Test-AzureAdLicenseContainsServicePlan -License Office365E5 -ServicePlan MCOEV Will Return $TRUE only if the ServicePlan is part of the License 'Office365E5' .INPUTS System.String .OUTPUTS Boolean .NOTES This CmdLet is a helper function to delegate validation tasks .FUNCTIONALITY Returns a boolean value for the presence of a ServicePlan in an AzureAd License .COMPONENT SupportingFunction Licensing .FUNCTIONALITY Tests whether the ServicePlan is included in the specified Plan License .LINK https://github.com/DEberhardt/TeamsFunctions/tree/main/docs/Test-AzureAdLicenseContainsServicePlan.md .LINK https://github.com/DEberhardt/TeamsFunctions/tree/main/docs/about_Supporting_Functions.md .LINK https://github.com/DEberhardt/TeamsFunctions/tree/main/docs/ #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '', Justification = 'Required for performance. Removed with Disconnect-Me')] [CmdletBinding()] [OutputType([Boolean])] param( [Parameter(Mandatory, HelpMessage = 'License to be tested')] [ValidateScript( { if ($_ -in $(&$global:TfAcSbAzureAdLicense)) { return $true } else { throw [System.Management.Automation.ValidationMetadataException] 'Value must be a valid License. Use Intellisense for options or Get-AzureAdLicense (ParameterName)' } })] [ArgumentCompleter({ &$global:TfAcSbAzureAdLicense })] [string]$License, [Parameter(Mandatory, HelpMessage = 'AzureAd Service Plan')] [ValidateScript( { if ($_ -in $(&$global:TfAcSbAzureAdLicenseServicePlan)) { return $true } else { throw [System.Management.Automation.ValidationMetadataException] 'Value must be a valid ServicePlan. Use Intellisense for options or Get-AzureAdLicenseServicePlan (ServicePlanName)' } })] [ArgumentCompleter({ &$global:TfAcSbAzureAdLicenseServicePlan })] [string]$ServicePlan ) #param begin { Show-FunctionStatus -Level Live Write-Verbose -Message "[BEGIN ] $($MyInvocation.MyCommand)" $AllLicenses = $null $AllLicenses = $global:TeamsFunctionsMSAzureAdLicenses } #begin process { Write-Verbose -Message "[PROCESS] $($MyInvocation.MyCommand)" $Lic = $AllLicenses | Where-Object ParameterName -EQ "$License" if ($ServicePlan -in $Lic.ServicePlans.ServicePlanName) { Write-Verbose -Message "License '$($Lic.ParameterName)'' ServicePlan '$ServicePlan' - Included" return $true } else { Write-Verbose -Message "License '$($Lic.ParameterName)'' ServicePlan '$ServicePlan' - NOT included" return $false } } #process end { Write-Verbose -Message "[END ] $($MyInvocation.MyCommand)" } #end } #Test-AzureAdLicenseContainsServicePlan |