Public/Helper/Test-Microsoft365LicenseContainsServicePlan.ps1
# Module: Orbit.Users # Function: Testing # Author: David Eberhardt # Updated: 18-JUL-2021 # Status: Live function Test-Microsoft365LicenseContainsServicePlan { <# .SYNOPSIS Tests whether a specific ServicePlan is included in an Microsoft 365 License .DESCRIPTION If an Microsoft 365 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-Microsoft365LicenseContainsServicePlan -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 Microsoft 365 License .COMPONENT SupportingFunction Licensing .FUNCTIONALITY Tests whether the ServicePlan is included in the specified Plan License .LINK https://github.com/DEberhardt/Orbit/tree/main/docs/Orbit.Users/Test-Microsoft365LicenseContainsServicePlan.md .LINK https://github.com/DEberhardt/Orbit/tree/main/docs/about/about_Supporting_Functions.md .LINK https://github.com/DEberhardt/Orbit/tree/main/docs/ #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '', Justification = 'Required for performance. Removed with Disconnect-Me')] [CmdletBinding()] [Alias('Test-AzureAdLicenseContainsServicePlan', 'Test-LicenseContainsServicePlan')] [OutputType([Boolean])] param( [Parameter(Mandatory, HelpMessage = 'License to be tested')] [ValidateScript( { if ($_ -in $( Get-OrbitAcSbGraphLicense @args)) { return $true } else { throw [System.Management.Automation.ValidationMetadataException] 'Value must be a valid License. Use Intellisense for options or Get-Microsoft365License (ParameterName)' } })] [string]$License, [Parameter(Mandatory, HelpMessage = 'Microsoft 365 Service Plan')] [ValidateScript( { if ($_ -in $( Get-OrbitAcSbGraphLicenseServicePlan @args)) { return $true } else { throw [System.Management.Automation.ValidationMetadataException] 'Value must be a valid ServicePlan. Use Intellisense for options or Get-Microsoft365LicenseServicePlan (ServicePlanName)' } })] [string]$ServicePlan ) #param begin { Show-OrbitFunctionStatus -Level Live Write-Verbose -Message "[BEGIN ] $($MyInvocation.MyCommand)" $AllLicenses = $null $AllLicenses = $global:OrbitMicrosoft365Licenses } #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-Microsoft365LicenseContainsServicePlan |