functions/Connect-O365.ps1
function Connect-O365 { [CmdletBinding()] PARAM ( [parameter(Mandatory = $true)] [ValidateSet("AzureActiveDirectory","Exchange","ComplianceCenter","Sharepoint","Skype","*")] [string[]] $Services, [parameter(Mandatory = $true)] [System.Management.Automation.Credential()] [System.Management.Automation.PSCredential] $Credential ) DYNAMICPARAM { if ($PSBoundParameters.Services -contains "Sharepoint" -or $PSBoundParameters.Services -contains "*") { $Name = "TenantName" $ParamAttr = [System.Management.Automation.ParameterAttribute]::new() $ParamAttr.Mandatory = $true $Attributes = [Collections.ObjectModel.Collection[System.Attribute]]::new() $Attributes.Add($ParamAttr) $Parameter = [System.Management.Automation.RuntimeDefinedParameter]::new($Name, [string], $Attributes) $Dictionary = [System.Management.Automation.RuntimeDefinedParameterDictionary]::new() $Dictionary.Add($Name, $Parameter) $Dictionary } } BEGIN { if ($Services -eq "*") { $Services = $AllServices } } PROCESS { switch ($Services) { { $_ -contains "AzureActiveDirectory" } { Connect-O365AzureAD -Credential $Credential } { $_ -contains "Exchange" } { Connect-O365Exchange -Credential $Credential } { $_ -contains "Skype" } { Connect-O365Skype -Credential $Credential } { $_ -contains "Sharepoint" } { Connect-O365Sharepoint -Credential $Credential -TenantName $PSBoundParameters.TenantName } { $_ -contains "ComplianceCenter" } { Connect-O365Compliance -Credential $Credential } } } } |