User:Sfiggins/Teams & S4B Powershell

From Labrats.us
Jump to navigationJump to search

Set Execution Policy

Start Powershell as administrator.

Run Set-ExecutionPolicy command.

PS C:\> Set-ExecutionPolicy -ExecutionPolicy Bypass

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): A

Verify that the policy took affect.

PS C:\> Get-ExecutionPolicy -List

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine          Bypass

Install MS Teams Powershell Module

In powershell, run the following.

PS C:\> Install-Module MicrosoftTeams

Untrusted repository

You are installing the modules from an untrusted repository. If you trust this repository, change
its InstallationPolicy value by running the `Set-PSRepository` cmdlet.

Are you sure you want to install the modules from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"):

https://docs.microsoft.com/en-us/microsoftteams/teams-powershell-install

Connect / login to the MS Teams / S4B Connector

You can do the rest as the a non-administrator user.

   Import-Module MicrosoftTeams
   $credential = Get-Credential
   Connect-MicrosoftTeams -Credential $credential

Assign "Microsoft" as the Conference Provider

Run the Enable-CsOnlineDialInConferencingUser to turn on Microsoft's Audio conferncing.

PS C:\> Enable-CsOnlineDialInConferencingUser -Identity "user@labrats.us" -ReplaceProvider


RunspaceId            : 90419993-79b4-4c75-b7c7-f6e06e4676fc
Identity              : user@labrats.us
SipAddress            : sip:user@labrats.us
ServiceNumber         : 17203709609
TollFreeServiceNumber :
ConferenceId          : 0
BridgeId              : f862865b-d49e-42be-8c67-1952c9ca8644
BridgeName            : Conference Bridge
Tenant                : ce701975-2de8-4dbf-a876-0ab0e031fa9c
AllowPstnOnlyMeetings : False
AllowTollFreeDialIn   : True
LeaderPin             : *****


You can also tun the following script that will make it a little nicer to run and give output.

PS C:\> .\Script.ps1 -userlist "user@labrats.us"
Number of users to have their audio conferencing provider set to Microsoft:  1
WARNING: "OriginalRegistrarPool" with identity "1972340558" assigned to "sip:user@labrats.us" has been
removed from configuration store.
The provider of user@labrats.us has changed to Microsoft.


RunspaceId            : 90419993-79b4-4c75-b7c7-f6e06e4676fc
Identity              : ab2cf895-db4a-4a27-9e6a-74154fbed58b
SipAddress            : sip:user@labrats.us
ServiceNumber         : 17203709609
TollFreeServiceNumber :
ConferenceId          : 0
BridgeId              : f862865b-d49e-42be-8c67-1952c9ca8644
BridgeName            : Conference Bridge
Tenant                : ce701975-2de8-4dbf-a876-0ab0e031fa9c
AllowPstnOnlyMeetings : False
AllowTollFreeDialIn   : True
LeaderPin             : 50554

Contents of the script:

<#
.SYNOPSIS

This is a PowerShell script to set Microsoft as the audio conferencing provider of a set of users. It's required for applicable users to have a valid PSTN Conferencing license assigned before their provider is changed.

.DESCRIPTION
This is a PowerShell script to set Microsoft as the audio conferencing provider of a set of users. It's required for applicable users to have a valid PSTN Conferencing license assigned before their provider is changed.

.EXAMPLE

./Script.ps1 -UserList "user01@constoso.com, user02@contoso.com, user03@contoso.com"
./Script.ps1 -CsvFile ".\\CsvFile.csv"
./Script.ps1 -ACPProviderName ""Intercall""
#>
param (
[Parameter(Mandatory = $true, ParameterSetName = "CsvFile")]
 [string]$CsvFile,
 [Parameter(Mandatory = $true, ParameterSetName = "UserList")]
 [string]$UserList,
 [Parameter(Mandatory = $true, ParameterSetName = "ACPProviderName")]
[string]$ACPProviderName
)
if ($CsvFile)
{
if(!(Test-Path $CsvFile))
{
Write-Error "File does not exist."
Exit
 }
$users = Get-Content $CsvFile
}
if ($UserList)
{
$users = $UserList.Split(",")
}
if ($ACPProviderName)
{
$supportedACPProviders = Get-csAudioConferencingProvider
$providerNameMatch = $supportedACPProviders | ?{$_.Identity -eq $ACPProviderName}
if ($providerNameMatch -eq $null)
{
Write-Host "The provider name is not from a supported provider, please use any of the following values: "
$supportedACPProviders      | %{$_.Identity}
return
}
$allUsersInTenant = Get-csOnlineUser
$users =  $allUsersInTenant | ?{$_.AcpInfo -ne $null -and $_.ACPInfo.Name -eq $ACPProviderName}
}
Write-Host "Number of users to have their audio conferencing provider set to Microsoft: " $users.count
foreach ($user in $users)
{
if ($CsvFile -or $UserList)
{
try
{
$adUser = Get-csOnlineUser -Identity $user
}
catch
{
Write-Error "There was an exception while retrieving user: $user. "   $error[0].Exception.Message
Continue
}
}
else
{
$adUser = $user
}
if ($adUser -ne $null -and ($adUser.OnlineDialInConferencingPOlicy -ne $null))
{
if ($adUser.AcpInfo -eq $null -Or $adUser.AcpInfo.Name -ne "Microsoft")
{
try
{
$enableUser = Enable-CsOnlineDialInConferencingUser -Identity $adUser.ObjectId -Tenant $adUser.TenantId -ReplaceProvider
Write-Host "The provider of $user has changed to Microsoft."
$enableUser
}
catch
{
Write-Error "There was an exception while enabling user: $user. "  $error[0].Exception.Message
continue;
}
}
 else
{
Write-Warning "The provider of $user is already set to Microsoft."
}
}
else
            {
Write-Error "$user does not have valid Audio Conferencing license assigned."
}
}

Verify Settings as Microsoft

PS C:\> Get-CsUserAcp -Identity "user@labrats.us"


RunspaceId         : 90419993-79b4-4c75-b7c7-f6e06e4676fc
AcpInfo            : {<acpInformation default="true">
                       <tollNumber>17203709609</tollNumber>
                       <participantPassCode>0</participantPassCode>
                       <domain>resources.lync.com</domain>
                       <name>Microsoft</name>
                       <url>https://dialin.lync.com/f862865b-d49e-42be-8c67-1952c9ca8644</url>
                     </acpInformation>}
Name               : ab2cf895-db4a-4a27-9e6a-74154fbed58b
DistinguishedName  : CN=ab2cf895-db4a-4a27-9e6a-74154fbed58b,OU=ce701975-2de8-4dbf-a876-0ab0e031fa9c,OU=OCS
                     Tenants,DC=lync0a001,DC=local
Identity           : CN=ab2cf895-db4a-4a27-9e6a-74154fbed58b,OU=ce701975-2de8-4dbf-a876-0ab0e031fa9c,OU=OCS
                     Tenants,DC=lync0a001,DC=local
Guid               : 8d53d4fe-e7e2-4a73-ad0f-1cc20ae06593
ObjectCategory     : CN=Person,CN=Schema,CN=Configuration,DC=lync0a001,DC=local
ObjectClass        : {top, person, organizationalPerson, user}
WhenChanged        : 3/16/2021 6:54:45 PM
WhenCreated        : 1/28/2016 8:16:30 AM
OriginatingServer  : WU20A00ADS01.lync0a001.local
IsByPassValidation : False
IsValid            : True
ObjectState        : Unchanged

Set User to use PGI as Conference Provider

First, you may need to remove the configuration for the user.

PS C:\> Remove-CsUserAcp -Identity "user@labrats.us"

Verify that the configuration was removed.

PS C:\> Get-CsUserAcp -Identity "user@labrats.us"


RunspaceId         : 90419993-79b4-4c75-b7c7-f6e06e4676fc
AcpInfo            : {}
Name               : ab2cf895-db4a-4a27-9e6a-74154fbed58b
DistinguishedName  : CN=ab2cf895-db4a-4a27-9e6a-74154fbed58b,OU=ce701975-2de8-4dbf-a876-0ab0e031fa9c,OU=OCS
                     Tenants,DC=lync0a001,DC=local
Identity           : CN=ab2cf895-db4a-4a27-9e6a-74154fbed58b,OU=ce701975-2de8-4dbf-a876-0ab0e031fa9c,OU=OCS
                     Tenants,DC=lync0a001,DC=local
Guid               : 8d53d4fe-e7e2-4a73-ad0f-1cc20ae06593
ObjectCategory     : CN=Person,CN=Schema,CN=Configuration,DC=lync0a001,DC=local
ObjectClass        : {top, person, organizationalPerson, user}
WhenChanged        : 3/16/2021 7:07:43 PM
WhenCreated        : 1/28/2016 8:16:30 AM
OriginatingServer  : WU20A00ADS01.lync0a001.local
IsByPassValidation : False
IsValid            : True
ObjectState        : Unchanged

Next, you can set the user to PGI.

PS C:\> Set-CsUserAcp -Identity "user@labrats.us" -TollNumber "16054755602" `
   -TollFreeNumber '17127704201' -ParticipantPassCode 981705 -Domain "lync.pgi.com" `
   -Name "PGi" -Url "http://www.pgi.com/lynconline/localnums.php"

Verifying the user was set to PGI.

PS C:\> Get-CsUserAcp -Identity "user@labrats.us"


RunspaceId         : 90419993-79b4-4c75-b7c7-f6e06e4676fc
AcpInfo            : {<acpInformation>
                       <tollNumber>1 (712) 770-4201</tollNumber>
                       <participantPassCode>981705</participantPassCode>
                       <domain>lync.pgi.com</domain>
                       <name>PGi</name>
                       <url>http://www.pgi.com/lynconline/localnums.php</url>
                     </acpInformation>}
Name               : ab2cf895-db4a-4a27-9e6a-74154fbed58b
DistinguishedName  : CN=ab2cf895-db4a-4a27-9e6a-74154fbed58b,OU=ce701975-2de8-4dbf-a876-0ab0e031fa9c,OU=OCS
                     Tenants,DC=lync0a001,DC=local
Identity           : CN=ab2cf895-db4a-4a27-9e6a-74154fbed58b,OU=ce701975-2de8-4dbf-a876-0ab0e031fa9c,OU=OCS
                     Tenants,DC=lync0a001,DC=local
Guid               : 8d53d4fe-e7e2-4a73-ad0f-1cc20ae06593
ObjectCategory     : CN=Person,CN=Schema,CN=Configuration,DC=lync0a001,DC=local
ObjectClass        : {top, person, organizationalPerson, user}
WhenChanged        : 3/16/2021 7:07:58 PM
WhenCreated        : 1/28/2016 8:16:30 AM
OriginatingServer  : WU20A00ADS01.lync0a001.local
IsByPassValidation : False
IsValid            : True
ObjectState        : Unchanged