Author Posts

May 12, 2017 at 9:38 am

Hello,

I'm trying to pass either an array or hash into Powershell from CruiseControl.net; I'm constrained on the way it is called based on how it's hardcoded into the PowershellTask. I need to basically make this work when executed from cmd or ccnet.

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nologo -NoProfile -NonInteractive -file "C:\Test\Input.ps1" -Environment test -Overrides @{'asd'='net';'arguments'='broken'}

In the script I've got:

[CmdletBinding()]
Param(
    [Parameter(Mandatory=$true)]
    [String]$Environment,
    [Parameter(Mandatory=$false)]
    [Hashtable]$Overrides = @{}
)

When I try that command (through CMD or cc.net) I get:

 : Cannot process argument transformation on parameter 'Overrides'. Cannot convert the "@{'asd'='net';'arguments'='broken'}" value of type "System.String" to type "System.Collections.Hashtable".

If I switch from -File to -Command it works. Unfortunately the -File is hardcoded in CCNet so I can't change it.

I don't understand why it doesn't work, and why the behaviour is different between -File and -Command.

Is what I want even possible?

Thanks,
Rob

May 12, 2017 at 3:13 pm

Thanks for your post. Please try the following:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -NonInteractive -Command "& C:\Test\Input.ps1 -Environment test -Overrides @{'asd'='net';'arguments'='broken'}"

I hope that helps.

– Daniel

May 12, 2017 at 4:20 pm

Hi Daniel,

Thank you for your reply. However as I said in my question:

Unfortunately the -File is hardcoded in CCNet so I can't change it.

So, I need it to work with -File not -Command

Thanks,
Rob

May 21, 2017 at 7:57 pm

Hello,

I've been trying more and more things to do this.

I have a feeling it's impossible to pass anything but simple strings into a

powershell -File

execution, can someone confirm? Unfortunately I can't change the execution from -File to -Command as it's hard-coded in cc.net 🙁

Thanks,
Rob

May 22, 2017 at 7:56 am

Afaik this is true
but you can write a "proxy"

param(
    [Parameter(Mandatory=$true)]
    [String]$Environment,
    [Parameter(Mandatory=$false)]
    #[Hashtable]$Overrides = @{}
	[string]$Overrides = ''
)

"Environment: $Environment"
"Overrides:"
$Overrides
$Overrides1 = & ([ScriptBlock]::Create($Overrides))
$Overrides1
#here you can call your needed file with transformed parameters