Forum Discussion
Sebastian cerazy
Nov 18, 2020Brass Contributor
Get-Team -DisplayName via variable with spaces
See below, I cannot find what makes it behave this way:
Get-Team -DisplayName "`"$teamName`""
return nothing!
PS C:\PSScripts> $teamName= "xx Year Group"
PS C:\PSScripts> Write-Host "`"$teamName`""
"xx Year Group"
PS C:\PSScripts> Get-Team -DisplayName "`"$teamName`""
PS C:\PSScripts> Get-Team -DisplayName "xx Year Group"
GroupId DisplayName Visibility Archived MailNickName Description
------- ----------- ---------- -------- ------------ -----------
f1e733af-8179-43bf-a5fe-c9f714f0b10e xx Year Group Private False nic--f5283 Whole xx Year ...
It seems that using variable is not possible, or do I have something very wrong in my logic?
Seb
First of all, you shouldnt be using identifiers such as DisplayName, as you can easily have multiple objects returned in a large tenant (duplicate values). Best use unique identifier such as the ExternalObjectId.
In any case, you can do it like this:
$name = "Project Tango" Get-Team -DisplayName $name GroupId DisplayName ------- ----------- 7503c511-dd24-45bf-8b43-6a280b815121 Project Tango
no need to escape the variable or anything
- SebCerazyIron Contributor
Just realized that get-team is CaSe SeNsItIvE !