pkjaer / tridion-powershell-modules

Windows PowerShell module allowing management of SDL Tridion (Content Management System) from the command line
13 stars 14 forks source link

New-TridionUser error when adding user to groups #50

Closed masterpipo closed 5 years ago

masterpipo commented 5 years ago

I am scripting adding new users to Tridion, but I keep encountering this weird issue when adding a new user to multiple groups

New-TridionUser : Could not find a group named Group1,Group2.
At Z:\Powershell\TridionUser.ps1:155 char:20
+ ...  $newUser = New-TridionUser -Name "$username" -Description "$fullname ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,New-TridionUser

This part works when adding to a single group.

I am using the following example below from get-help

PS C:\>New-TridionUser -Name "GLOBAL\user01" -MemberOf SuperUsers,WebMasters

Is there anything I am not using correctly?

pkjaer commented 5 years ago

Hmm that should have worked. I guess you can try to explicitly make it an array of strings and see if that works?

New-TridionUser -Name 'GLOBAL\user01' -MemberOf @('SuperUsers','WebMasters')

masterpipo commented 5 years ago

Thanks @pkjaer looks like that did the trick

Any plans to change the execution of this in the future? Just in case if I need to change my script as well :)

https://github.com/pkjaer/tridion-powershell-modules/blob/19ad0520ba8702328e25c97134d5c6f6afd95d79/CoreService/Trustees.psm1#L557

pkjaer commented 5 years ago

Possibly, though I'm not sure to what exactly. It seems like your issue was that it didn't automatically convert the two strings into an array -- but that's fairly understandable as there were no quotes and the parameter is a string array. So you could have meant it as a single string that just happens to have a comma in it.

In general, it's a good idea to be explicit (array, quoted strings), so I think perhaps it's more appropriate to just update the example. But I'm certainly open to ideas :)

masterpipo commented 5 years ago

Ah I think it was just a miss on the get-help notes. Shouldn't be a big deal. Happy to close this as is :)