Problems with collection via Invoke-Command

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
DeKade
Posts: 18
Last visit: Fri Mar 04, 2022 2:16 am

Problems with collection via Invoke-Command

Post by DeKade »

I'm having trouble setting a customAttribute via PS Remoting.

Locally on the server this works perfectly:

Set-ADUser testuser-Replace @{DepartmentNumber = @("test1", "test2","test3")}

If I try to remote this very same command with Invoke-Command I get this:

Invalid type 'System.Collections.ArrayList'.
Parameter name: DepartmentNumber
+ CategoryInfo : InvalidArgument: (anker:ADUser) [Set-ADUser], ArgumentException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Commands.SetADUser

If I try a single value it works locally and remotely, but as soon a I pass an array, arraylist or hashtable, I get an error remotely
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Problems with collection via Invoke-Command

Post by jvierra »

Why do you need to use "Invoke-Command".

"DepartmentNumber" is not an array: https://msdn.microsoft.com/en-us/librar ... s.85).aspx
User avatar
DeKade
Posts: 18
Last visit: Fri Mar 04, 2022 2:16 am

Re: Problems with collection via Invoke-Command

Post by DeKade »

jvierra wrote:Why do you need to use "Invoke-Command".

"DepartmentNumber" is not an array: https://msdn.microsoft.com/en-us/librar ... s.85).aspx
Because I'm remoting. (using JEA)

also, DepartmentNumber is a Multi value AD field.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Problems with collection via Invoke-Command

Post by jvierra »

Remoting has no requirement to do that. Are you thinking you want to use "Invoke-Command" but it needs to have a target session to connect to.

help invoke-command -full

JEA is not remoting. It is a way of referring to a special type of restricted endpoint.
User avatar
DeKade
Posts: 18
Last visit: Fri Mar 04, 2022 2:16 am

Re: Problems with collection via Invoke-Command

Post by DeKade »

jvierra wrote:Remoting has no requirement to do that. Are you thinking you want to use "Invoke-Command" but it needs to have a target session to connect to.

help invoke-command -full

JEA is not remoting. It is a way of referring to a special type of restricted endpoint.
?

I don't understand.
I'm combining remoting and JEA.
I have helpdeskusers that need to perform certain tasks.
I have created a GUI application for this.
Under the hood JEA is used in combination with a group managed service account.
The helpdesk users are not on the machine where the commands need to run so I use Invoke-Command passing it a ConfigurationName
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Problems with collection via Invoke-Command

Post by jvierra »

So you will need to use Invoke-Command to the constrained endpoint. If the endpoint is allowed to execute the commands and has access to the resources it will work.

I still cannot understand what question you are asking. As I noted above you cannot use an array for "DepartmentNumber". That is the cause of your error message.
User avatar
DeKade
Posts: 18
Last visit: Fri Mar 04, 2022 2:16 am

Re: Problems with collection via Invoke-Command

Post by DeKade »

jvierra wrote:So you will need to use Invoke-Command to the constrained endpoint. If the endpoint is allowed to execute the commands and has access to the resources it will work.

I still cannot understand what question you are asking. As I noted above you cannot use an array for "DepartmentNumber". That is the cause of your error message.
Try it :)
You can pass this Attribute a collection just fine on the computer itself
It also is a Multi value field in AD
Image
If I pass this an array on the computer itself it works perfectly, so it must do something with it so it works. The Invoke-Command probably doesn't do this.
Same issue with "ProxyAddresses"
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Problems with collection via Invoke-Command

Post by jvierra »

Please read the definition of the field. It is not multivalued which is why you are getting the error.

https://msdn.microsoft.com/en-us/librar ... s.85).aspx

You cannot set a department number on a local computer. Somewhere you are missing or mis-reporting this information.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Problems with collection via Invoke-Command

Post by jvierra »

Actually it turns out that on WS2008R2 and later that it has been changed to an array and you can set multiple values.

I also tested using Invoke-Command and it also fails on multiple values. I suggest reporting this as a bug in the RSAT components.
User avatar
DeKade
Posts: 18
Last visit: Fri Mar 04, 2022 2:16 am

Re: Problems with collection via Invoke-Command

Post by DeKade »

jvierra wrote:Actually it turns out that on WS2008R2 and later that it has been changed to an array and you can set multiple values.

I also tested using Invoke-Command and it also fails on multiple values. I suggest reporting this as a bug in the RSAT components.
;)

Thanks. What would be the best channel to report this bug?
This topic is 6 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked