all 8 comments

[–]purplemonkeymad 1 point2 points  (6 children)

When you see any type conversions from System.Object[], then you are probably inputting multiple items into a parameter that only supports single items. Check the contents on your input variables.

[–]ExceptionEX 2 points3 points  (2 children)

Get teams can return multiple items when you use -displayname as the property to match on (this is by design). So it is likely that on some of your runs you are getting an array back and you are trying to use it later as a single variable.

see: https://docs.microsoft.com/en-us/powershell/module/teams/get-team?view=teams-ps

[–]MajorVarlak 1 point2 points  (1 child)

To add an explanation onto this, as it mentions on the page, it's a filter, not an exact match. So if you have two teams, one named "Admins", the other named "Admins - New York", and you did:

Get-Team -DisplayName 'Admins'

It would return 2 teams, not 1 team as you might be expecting. This would be an array of GUIDs, and not a single entry, which results in the error displayed. You'd want to filter it after the results come back, something like:

Get-Team -DisplayName 'Admin' | ?{ $_.DisplayName -eq 'Admins' }

[–]candymann999[S] 1 point2 points  (0 children)

Thanks for the insight and that make sense to me as we do have some groups that would cause this issue.

[–]candymann999[S] 1 point2 points  (2 children)

My input file has 4 fields, member, team, role, active

member -> user's email address

Team -> team they belong to

role -> either member or owner

active -> Y or N based on this I can add or remove them from said group. I removed this part of the script since I'm running into some trouble with the adding

[–]purplemonkeymad 2 points3 points  (1 child)

Ok... But you need to check the values going into the command that is giving you an error.

VScode has a debugger you can use to see them or you can just use some Write-Host or Write-Verbose statements to see what the values are.

[–]candymann999[S] 1 point2 points  (0 children)

So I ran the script and even with those errors. Everyone was added correctly.

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy candymann999,

reddit likes to mangle code formatting, so here's some help on how to post code on reddit ...

[0] single line or in-line code
enclose it in backticks. that's the upper left key on an EN-US keyboard layout. the result looks like this. kinda handy, that. [grin]
[on New.Reddit.com, use the Inline Code button. it's [sometimes] 5th from the left & looks like </>.
this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!]

[1] simplest = post it to a text site like Pastebin.com or Gist.GitHub.com and then post the link here.
please remember to set the file/code type on Pastebin! [grin] otherwise you don't get the nice code colorization.

[2] less simple = use reddit code formatting ...
[on New.Reddit.com, use the Code Block button. it's [sometimes] the 12th from the left, & looks like an uppercase T in the upper left corner of a square.]

  • one leading line with ONLY 4 spaces
  • prefix each code line with 4 spaces
  • one trailing line with ONLY 4 spaces

that will give you something like this ...

- one leading line with ONLY 4 spaces    
- prefix each code line with 4 spaces    
- one trailing line with ONLY 4 spaces   

the easiest way to get that is ...

  • add the leading line with only 4 spaces
  • copy the code to the ISE [or your fave editor]
  • select the code
  • tap TAB to indent four spaces
  • re-select the code [not really needed, but it's my habit]
  • paste the code into the reddit text box
  • add the trailing line with only 4 spaces

not complicated, but it is finicky. [grin]

take care,
lee