Azure Runbook if statement does not work

%3CLINGO-SUB%20id%3D%22lingo-sub-805013%22%20slang%3D%22en-US%22%3EAzure%20Runbook%20if%20statement%20does%20not%20work%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-805013%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20the%20last%20part%20of%20the%20below%20code%20block%20the%20if%20statement%20is%20not%20evaluated.%20The%20user%20is%20always%20added%20to%20the%20team%20no%20matter%20what%20the%20company%20name%20is.%20Any%20suggestions%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EParam(%0A%0A%20%20%20%20%5Bstring%5D%24teamname%2C%20%23The%20name%20of%20the%20Team%0A%20%20%20%20%5Bstring%5D%24teamowner%2C%20%23The%20email%20address%20of%20the%20owner%20of%20the%20Team%0A%20%20%20%20%5Bstring%5D%24teamalias%2C%20%23The%20bit%20of%20the%20teamname%20you%20want%20to%20be%20the%20URL%0A%20%20%20%20%5Bstring%5D%24external%2C%20%23external%20sharing%20enabled%3F%0A%20%20%20%20%5Bstring%5D%24company%20%23to%20determine%20site%20owner%20from%20IT%0A%0A)%0A%23Connect%20to%20Teams%20PowerShell%0A%24cred%20%3D%20Get-AutomationPSCredential%20-Name%20%22TestAdmin%22%0A%24teams%20%3D%20Connect-MicrosoftTeams%20-Credential%20%24cred%0A%0A%23Create%20the%20Team%20and%20add%20owners%2C%20ensure%20added%20to%20address%20list%20and%20can%20be%20found%20in%20exchange%20groups%0A%24newteam%20%3D%20New-Team%20-MailNickname%20%24teamalias%20-DisplayName%20%24teamname%20-Owner%20%24teamowner%20-Visibility%20Private%20%0AStart-Sleep%20-Seconds%20180%0AAdd-TeamUser%20-GroupId%20%24newteam.GroupId%20-User%20user1%40domain.com%20-Role%20Owner%0Aif(%24company%20%3D%20%22CompanyName1%22)%0A%7B%0A%20%20%20%20Add-TeamUser%20-GroupId%20%24newteam.GroupId%20-User%20user2%40domain.com%20-Role%20Owner%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-805013%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAutomation%20%26amp%3B%20Control%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20Runbooks%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-805191%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20Runbook%20if%20statement%20does%20not%20work%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-805191%22%20slang%3D%22en-US%22%3E%3CP%3EI%20figured%20it%20out.%20I%20had%20to%20use%20-eq%20instead%20of%20%3D%20since%20I%20was%20evaluating%20the%20variable%20instead%20of%20assigning%20to%20it.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Super Contributor

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
}

 

1 Reply

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