Script Repository


Assign Conferencing Policy in Skype for Business Online

April 28, 2020
4203

The script assigns a Conferencing Policy to a user in Skype for Business Online.

Skype for Business Online Connector Module is required to communicate with Skype for Business Online. Download and install it on the computer where your Adaxes service runs.

Parameter:

  • $policyName - specifies the name of the Conferencing Policy to assign.
Edit Remove
PowerShell
$policyName = "Tag:BposSAllModalityNoRecNoVideo" # TODO: uncomment the policy you need
# $policyName = "Tag:BposSAllModality"
# $policyName = "Tag:BposSAllModalityNoVideo"
# $policyName = "Tag:BposSAllModalityMinVideoBW"
# $policyName = "Tag:BposSAllModalityNoDialout"
# $policyName = "Tag:BposSAllModalityNoDialoutNoVideo"
# $policyName = "Tag:BposSAllModalityNoDialoutMinVideoBW"
# $policyName = "Tag:BposSAllModalityNoFT"
# $policyName = "Tag:BposSAllModalityNoFTNoVideo"
# $policyName = "Tag:BposSAllModalityNoFTMinVideoBW"
# $policyName = "Tag:BposSAllModalityNoFTNoDialout"
# $policyName = "Tag:BposSAllModalityNoFTNoDialoutNoVideo"
# $policyName = "Tag:BposSAllModalityNoFTNoDialoutMinVideoBW"
# $policyName = "Tag:BposSAllModalityNoRec"
# $policyName = "Tag:BposSAllModalityNoRecMinVideoBW"
# $policyName = "Tag:BposSAllModalityNoRecNoDialout"
# $policyName = "Tag:BposSAllModalityNoRecNoDialoutNoVideo"
# $policyName = "Tag:BposSAllModalityNoRecNoDialoutMinVideoBW"
# $policyName = "Tag:BposSDataProtection"
# $policyName = "Tag:BposSDataProtectionNoVideo"
# $policyName = "Tag:BposSDataProtectionMinVideoBW"
# $policyName = "Tag:BposSDataProtectionNoDialout"
# $policyName = "Tag:BposSDataProtectionNoDialoutNoVideo"
# $policyName = "Tag:BposSDataProtectionNoDialoutMinVideoBW"
# $policyName = "Tag:BposSIMPOnly"
# $policyName = "Tag:BposSIMPOnlyNoDialout"
# $policyName = "Tag:BposSIMPOnlyNoRec"
# $policyName = "Tag:BposSIMPOnlyNoRecNoDialout"
# $policyName = "Tag:BposSVoipDisabled"
# $policyName = "Tag:BposSVoipDisabledNoDialout"
# $policyName = "Tag:BposSVoipDisabledNoRec"
# $policyName = "Tag:BposSVoipDisabledNoRecNoDialout"
# $policyName = "Tag:BposSAllModalityWithPPANoFT"
# $policyName = "Tag:BposSVoipDisabledWithPPANoFT"

# Get the user ID in Microsoft 365
try
{
    $objectId = [Guid]$Context.TargetObject.Get("adm-O365ObjectId")
}
catch
{
    $Context.LogMessage("The user doesn't have a Microsoft 365 Account", "Warning")
    return
}

# Script block to assign a Conferencing Policy to a user
$scriptBlock = {
    Import-Module LyncOnlineConnector

    # Connection to Microsoft 365
    $password = ConvertTo-SecureString -AsPlainText -Force -String $password
    $credential = New-Object System.Management.Automation.PsCredential($adminName,$password)
    
    try
    {
        # Connect to Skype for Business Online
        $session = New-CsOnlineSession -Credential $credential
        Import-PSSession $session -AllowClobber | Out-Null
        
        # Assign the policy
        Grant-CsConferencingPolicy $objectId -PolicyName $policyName
    }
    finally
    {
        # Close the remote session and release resources
        Remove-PSSession $session
    }
}

# Get credential to connect to Microsoft 365 with
$microsoft365Cred = $Context.GetOffice365Credential()
$adminName = $microsoft365Cred.Username
$password = $microsoft365Cred.GetNetworkCredential().Password

# Start Windows PowerShell as a separate process and run the script block in that process
$powershellPath = "$env:windir\system32\windowspowershell\v1.0\powershell.exe"
$arguments = @("-noninteractive", "-noprofile", "-executionpolicy bypass", "-Command `$adminName = '$adminName'; `$password = '$password'; `$objectId = '$objectId'; `$policyName = '$policyName'; $scriptBlock")
$starProcessInfo = New-Object System.Diagnostics.ProcessStartInfo
$starProcessInfo.FileName = $powershellPath
$starProcessInfo.Arguments = $arguments
$starProcessInfo.WindowStyle = "Hidden"
$starProcessInfo.CreateNoWindow = $True
$starProcessInfo.UseShellExecute = $False
$starProcessInfo.RedirectStandardOutput = $True 
$starProcessInfo.RedirectStandardError = $True
$process = [System.Diagnostics.Process]::Start($starProcessInfo)
$resultErrors = $process.StandardError.ReadToEnd()
$resultOutput = $process.StandardOutput.ReadToEnd()

# Add operation result to the Execution Log
# Add errors
if (-not([System.String]::IsNullOrEmpty($resultErrors)))
{
    $Context.LogMessage($resultErrors, "Error")
}

# Add information messages and warnings
if (-not([System.String]::IsNullOrEmpty($resultOutput)))
{
    $Context.LogMessage($resultOutput, "Warning")
}

See Also: Assign Conferencing Policy in Skype for Business On-Premises.


Comments ( 2 )
avatar
Fabian Flamme
Jul 16, 2020
I replaced LyncOnlineConnector with SkypeOnlineConnector:

Import-Module SkypeOnlineConnector

The module is installed on the server where Adaxes Service is running.

I get this error:

Import-Module : The specified module 'SkypeOnlineConnector' was not loaded because no valid module file was found in any module directory. At line:2 char:2 + Import-Module SkypeOnlineConnector + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (SkypeOnlineConnector:String) [Import-Module], FileNotFoundExceptio n + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand Remove-PSSession : Cannot validate argument on parameter 'Id'. The argument is null. Provide a valid value for the argument, and then try running the command again. At line:25 char:19 + Remove-PSSession $session + ~~~~~~~~ + CategoryInfo : InvalidData: (:) [Remove-PSSession], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.RemovePSSessionCommand New-CsOnlineSession : The term 'New-CsOnlineSession' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:11 char:13 + $session = New-CsOnlineSession -Credential $credential + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (New-CsOnlineSession:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

Any ideas?
avatar
Support
Jul 17, 2020

Hello Fabian,

It looks like the SkypeOnlineConnector module is not added to the Windows PowerShell profile on the computer where the Adaxes service runs. Please, check whether the module can be successfully imported in Windows PowerShell on the computer. If it cannot, add the module to the profile, restart Softerra Adaxes Service and check whether the issue persists. For information on how to add the module to the profile, please, have a look at the following Microsoft article: https://docs.microsoft.com/en-us/skypeforbusiness/set-up-your-computer-for-windows-powershell/download-and-install-the-skype-for-business-online-connector. If the module is already added to the profile, just restart Softerra Adaxes Service and check whether the issue persists.

Leave a comment

Related Scripts