Forum Discussion

Robert Woods's avatar
Robert Woods
Steel Contributor
Aug 14, 2019

Azure Runbook if statement does not work

In the last part of the below code block the if statement is not evaluated. The user is always added to the team no matter what the company name is. Any suggestions?

 

Param(

    [string]$teamname, #The name of the Team
    [string]$teamowner, #The email address of the owner of the Team
    [string]$teamalias, #The bit of the teamname you want to be the URL
    [string]$external, #external sharing enabled?
    [string]$company #to determine site owner from IT

)
#Connect to Teams PowerShell
$cred = Get-AutomationPSCredential -Name "TestAdmin"
$teams = Connect-MicrosoftTeams -Credential $cred

#Create the Team and add owners, ensure added to address list and can be found in exchange groups
$newteam = New-Team -MailNickname $teamalias -DisplayName $teamname -Owner $teamowner -Visibility Private 
Start-Sleep -Seconds 180
Add-TeamUser -GroupId $newteam.GroupId -User user1@domain.com -Role Owner
if($company = "CompanyName1")
{
    Add-TeamUser -GroupId $newteam.GroupId -User user2@domain.com -Role Owner
}

 

  • Robert Woods's avatar
    Robert Woods
    Steel Contributor

    I figured it out. I had to use -eq instead of = since I was evaluating the variable instead of assigning to it. 

Resources