Really? Powershell is not that almighty after all J

 

That can't be true in general.

I do that already, but without any additional separators and especially no
blanks.

 

This would work:

 

$CM_Roles =
@("CM_Global_Administration","FullAdministrator","ALL","CM_Global_Packagers"
,"ApplicationAdministrator","ALL")

 

Every entry is an array entry then:

 

CM_Global_Administration

FullAdministrator

ALL

CM_Global_Packagers

ApplicationAdministrator

ALL

 

But as soon as there is a blank in there I get this again.

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

 

CM_Global_Administration

Full

Administrator

ALL

CM_Global_Packagers

Application

Administrator

ALL

 

I'd like to use this:

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

 

Why aren't the commas and the blanks put into single array entry just as a
string?

 

"CM_Global_Administration,Full Administrator,ALL"

"CM_Global_Packagers,Application Administrator,ALL"

 

-R

 

 

 

From: [email protected] [mailto:[email protected]]
On Behalf Of Trevor Sullivan
Sent: Donnerstag, 31. Oktober 2013 14:14
To: [email protected]
Subject: RE: [mssms] OT: Powershell pass array help

 

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