How do i called PS script in Lynch shell and calling MicrosoftTeams commands in same script

cosy M 6 Reputation points
2021-06-12T08:49:31.877+00:00

Hi All,

I have a requirement to set up for new sfb online user and then convert to a team Only user.

So I have created the form with multiple inputs and select boxes with OK to execute the task. ( OK-Script part in below)

Q1: Can I call both sfb and Teams commands on the same shell?

Q2: How do I verify sfb online user is sync before running the Teams command?

Q3: How do I remove my admin password from that script?

Q4: is it better to create 2 forms and instruct to run one after 15 -20 min?

-----------------------------------------------------------------------Part of the script----------------------------------
# add sfb online user and convert to Teams only Mode
$Okbutton.Add_Click({
# your compare function comparing the file in $textbox1 against the file in $textbox2
# IF both fields contain a valid file path and name of course ;)
# for demo just output in console
Write-Host "$($objTextBox.Text),$($objTextBox2.Text),$($objTextBox3.Text),$Dialplan,$voiceroutingpolicy"
#Activate voice calling and assign a number to the user
Enable-CsUser -Identity $($objTextBox.Text) -SipAddressType Emailaddress -HostingProviderProxyFqdn 'sipfed.online.lync.com' -DomainController 'xxxx.domain.com'
#Enterprise Voice users only
Set-CsUser -Identity sip:$UserName -LineUri "tel:$($objTextBox2.Text);ext=$($objTextBox3.Text)" -DomainController 'xxxx.domain.com'

\# ADSync to synch the user

Invoke-command -ComputerName yyxx.domain.com -ScriptBlock { Start-AdSyncSyncCycle }

\# *Wait \~15 minutes*

Start-Sleep -s 900

#*Connect to Microsoft Teams with pre-configured user and password*
$User = "xxxx@domain.com"

$PassWord = ConvertTo-SecureString -String "abcd123456" -AsPlainText -Force
$UserCredential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $User, $PassWord
import-module microsoftteams
Connect-MicrosoftTeams -Credential $UserCredential -AccountId $User
Import-Module MicrosoftTeams -RequiredVersion 2.3.1
Connect-MicrosoftTeams -Credential $UserCredential -AccountId $User

\# Set user account for Microsoft Teams *only* (PowerShell with MicrosoftTeams module >2.3.1 installed)
Grant-CsTeamsUpgradePolicy -Identity $UserName -PolicyName 'UpgradeToTeams'
\# *******************************
\# * Enterprise Voice users only *
\# *******************************
Set-CsUser -Identity $UserName -EnterpriseVoiceEnabled $true -HostedVoicemail $true -Verbose
Grant-CsTenantDialPlan -Identity $UserName -PolicyName $($objListBox1.Text) -Verbose
Grant-CsOnlineVoiceRoutingPolicy -Identity $UserName -PolicyName $($objListBox.Text) -Verbose


}) 

$Form.Controls.Add($Okbutton) 
Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,125 questions
Skype for Business
Skype for Business
A Microsoft communications service that provides communications capabilities across presence, instant messaging, audio/video calling, and an online meeting experience that includes audio, video, and web conferencing.
603 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
2,873 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,382 questions
{count} votes

3 answers

Sort by: Most helpful
  1. cosy M 6 Reputation points
    2021-06-12T08:54:52.077+00:00

    Found the answer to Q3

    (get-credential).password | ConvertFrom-SecureString | set-content "C:\Passwords\password.txt"
    $password = Get-Content "C:\Passwords\password.txt" | ConvertTo-SecureString
    $credential = New-Object System.Management.Automation.PsCredential("Luke",$password)

    1 person found this answer helpful.
    0 comments No comments

  2. Sharon Zhao-MSFT 25,056 Reputation points Microsoft Vendor
    2021-06-14T02:50:06.927+00:00

    @cosy M ,

    You don’t need to do that because Skype for Business Online Connector connections will be rejected starting May 17, 2021. Your organization must replace the Skype for Business Online PowerShell connector module with the Teams PowerShell module by this date.

    If your organization doesn’t do the migration, please read this article to finish the operation.

    As we are mainly responsible for general question of Microsoft Teams and Skype for Business, if you want the scripts support, I will add office-teams-app-dev tag for further help. Thanks for you understanding.


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  3. cosy M 6 Reputation points
    2021-06-15T06:07:25.297+00:00

    Hi,

    How do I run Enable-CsUser? It is not recognized in Teams Module.