Greetings,
I’m having an issue getting a function to work properly. The goal is to compare the output of some JSON data to existing unified groups in Office 365, and if the group already exists, skip it, otherwise, create a new group. The tricky part is that as part of function that creates the group, it prepends “gr-” to the group name. Because the compare function is comparing the original JSON data without the prepended data to Office 365, the compare function has to have the logic to prepend “gr-” on the fly.
Here is the latest version of the function. There have been other variations, but none so far have worked. There are no errors, but the code does not identify lists that definitely do exist. I am using simple echo statements for the purpose of testing, the actual code will include the function to create a new group.
# Test variable that cycles through each .json file. $jsonFiles = Get-ChildItem -path "c:\tmp\json" -filter *.json | get-content -raw $allobjects = $jsonFiles | convertfrom-json $alreadyCreatedGroup = Get-UnifiedGroup | select alias # Determine if list already exists in Office 365 function checkForExistingGroup { [CmdletBinding()] Param( [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] $InputObject ) Process { if("gr-$($InputObject.alias)" -in $alreadyCreatedGroup){ echo "$($inputobject.alias) exists" } else{ echo "$($InputObject.alias) does not exist" } } } $allobjects | checkForExistingGroup
The above code always produces the “does not exist” option for each alias from the JSON data.
The individual variables appear to be outputting correctly:
PS> $alreadyCreatedGroup Alias ----- gr-jsonoffice365grouptest1 gr-jsonoffice365grouptest2 gr-jsonoffice365grouptest3 PS> $allobjects.alias jsonoffice365grouptest3 jsonoffice365grouptest4
If I run the following on its own:
"gr-$($allobjects.alias)"
I get the following output:
gr-jsonoffice365grouptest3 jsonoffice365grouptest4
So on its own it appends the output from the JSON files, but I had hoped by using $InputObject in the function, this would resolve that issue.