Roland,

 

You can't pass a .NET [Object] from one PowerShell session to another (not
without some advanced hacking, anyway). To make this work, you'll probably
have to -join or [String]::Join() the array values together into a single,
contiguous string, pass the entire string as a single parameter to the
secondary script, and then -Split or [String].Split() the String into an
array again.

 

Cheers,

Trevor Sullivan

 

From: [email protected] [mailto:[email protected]]
On Behalf Of Roland Janus
Sent: Thursday, October 31, 2013 5:52 AM
To: [email protected]
Subject: [mssms] OT: Powershell pass array help

 

Not completely off-topic, trying to use CM12 cmdlets.

 

I have an array:

 

$CM_Roles = @("'CM_Global_Administration','Full
Administrator','ALL'";"'CM_Global_Packagers','Application
Administrator','ALL'")

Two entries, separated with ";" and each one separated with ","

 

This works fine: foreach ($x in $CM_Roles) {$x}

'CM_Global_Administration','Full Administrator','ALL'

'CM_Global_Packagers','Application Administrator','ALL'

 

I have the single quotes and can use split to get another array:

 

foreach ($x in $CM_Roles) {$x -split ","}

 

'CM_Global_Administration'

'Full Administrator'

'ALL'

'CM_Global_Packagers'

'Application Administrator'

'ALL'

 

All good. Still with quotes.

 

But I need to pass the array to another ps-script, namely an x86 like that:

 

&"$env:SystemRoot\syswow64\WindowsPowerShell\v1.0\powershell.exe"
".\CM_Assign_Security.ps1" @cm_roles

 

But the script with this in it:

 

Foreach ($x in $args) {$x}

 

only returns the values without the single quotes or ',':

 

CM_Global_Administration Full Administrator ALL

CM_Global_Packagers Application Administrator ALL

 

I've also tried like a million variations, like with param() in the script.
Then I only get one array entry back.

 

For sure someone knows how to do that? And it is probably trivial, but
google wasn't helping.

Those examples never had to use quotes.

 

-R

 

 



Reply via email to