Hi all,
I have an issue with using a csv as input for a script to add multiple workergroups to a xenapp published app. I have created a csv with a custom delimiter ";" because the paramater value needed to add multiple workergroups need to be seperated by a comma.
In my csv the exported data looks like this after running this command.
Get-XAApplicationReport * |where {($_.ApplicationType -ne"Content") -and($_.ApplicationType -ne"ServerDesktop") -and($_.Enabled -eq"True")} |selectBrowserName,@{n="WorkerGroups";e={[string]::join(",",$_.WorkerGroupNames)}},Folderpath | export-csv c:\workergroup.csv-Delimiter";"-NoTypeInformation
CSV content:
"Test_APP_NAME";"CTX-WG-NewBuild-10.6,CTX-WG-NewBuild-10.6-Silo";"Applications/TEST"
When running the following script
$vars=Import-Csvc:\workergroups.csv-Delimiter";"-Header "BrowserName","WorkerGroups","FolderPath" Foreach ($line in $Vars) { Set-XAApplication-BrowserName$line.BrowserName -WorkerGroupNames $line.WorkerGroups -Enabled$True }
It wil interpret the "CTX-WG-NewBuild-10.6,CTX-WG-NewBuild-10.6-Silo" (without quotes) as a single name instead of 2 names seperated by the comma. Resulting in an error because that combined name ofcourse does not exsist. Running the command manually wil work fine.
If i run trace-command "Trace-Commandparameterbinding-Expression"
Trace-Command parameterbinding -Expression {Set-XAApplication -BrowserName $line.BrowserName -WorkerGroupNames $line.WorkerGroups -Enabled $True} -PSHost
with the script i see the following :
DEBUG: ParameterBinding Information: 0 : Parameter and arg types the same, no coercion is needed.
DEBUG: ParameterBinding Information: 0 : Adding scalar element of type String to array position 0
DEBUG: ParameterBinding Information: 0 : Executing VALIDATION metadata: [System.Management.Automation.ValidateNotNullOrEmptyAttribute]
DEBUG: ParameterBinding Information: 0 : BIND arg [System.String[]] to param [BrowserName] SUCCESSFUL
DEBUG: ParameterBinding Information: 0 : BIND arg [CTX-WG-NewBuild-10.6,CTX-WG-NewBuild-10.6-Silo] to parameter [WorkerGroupNames]
DEBUG: ParameterBinding Information: 0 : COERCE arg to [System.String[]]
DEBUG: ParameterBinding Information: 0 : Trying to convert argument value from System.String to System.String[]
DEBUG: ParameterBinding Information: 0 : ENCODING arg into collection
DEBUG: ParameterBinding Information: 0 : Binding collection parameter WorkerGroupNames: argument type [String], parameter type [System.String[]],
Which results in:
Set-XAApplication : Cannot find worker group with name CTX-WG-NewBuild-10.6,CTX-WG-NewBuild-10.6-Silo (0x80000001 Failure.)
At line:1 char:45
+ Trace-Command parameterbinding -Expression {Set-XAApplication -BrowserName $line ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (CTX-WG-NewBuild...Build-10.6-Silo:String) [Set-XAApplication], CitrixException
+ FullyQualifiedErrorId : FindWorkerGroupByName,Citrix.XenApp.Commands.SetAppCmdlet
When running the same trace-command but with the parameters filled in manually all works fine and i see this:
Trace-Command parameterbinding -Expression {Set-XAApplication -BrowserName "Test_APP_NAME" -WorkerGroupNames CTX-WG-NewBuild-10.6,CTX-WG-NewBuild-10.6-Silo} -PSHost
DEBUG: ParameterBinding Information: 0 : BIND NAMED cmd line args [Set-XAApplication]
DEBUG: ParameterBinding Information: 0 : BIND arg [Test_APP_Name] to parameter [BrowserName]
DEBUG: ParameterBinding Information: 0 : COERCE arg to [System.String[]]
DEBUG: ParameterBinding Information: 0 : Trying to convert argument value from System.String to System.String[]
DEBUG: ParameterBinding Information: 0 : ENCODING arg into collection
DEBUG: ParameterBinding Information: 0 : Binding collection parameter BrowserName: argument type [String], parameter type [System.String[]], coll
ection type Array, element type [System.String], coerceElementType
DEBUG: ParameterBinding Information: 0 : Creating array with element type [System.String] and 1 elements
DEBUG: ParameterBinding Information: 0 : Argument type String is not IList, treating this as scalar
DEBUG: ParameterBinding Information: 0 : COERCE arg to [System.String]
DEBUG: ParameterBinding Information: 0 : Parameter and arg types the same, no coercion is needed.
DEBUG: ParameterBinding Information: 0 : Adding scalar element of type String to array position 0
DEBUG: ParameterBinding Information: 0 : Executing VALIDATION metadata: [System.Management.Automation.ValidateNotNullOrEmptyAttribute]
DEBUG: ParameterBinding Information: 0 : BIND arg [System.String[]] to param [BrowserName] SUCCESSFUL
DEBUG: ParameterBinding Information: 0 : BIND arg [System.Object[]] to parameter [WorkerGroupNames]
DEBUG: ParameterBinding Information: 0 : COERCE arg to [System.String[]]
DEBUG: ParameterBinding Information: 0 : Trying to convert argument value from System.Object[] to System.String[]
DEBUG: ParameterBinding Information: 0 : ENCODING arg into collection
DEBUG: ParameterBinding Information: 0 : Binding collection parameter WorkerGroupNames: argument type [Object[]], parameter type [System.String[]
], collection type Array, element type [System.String], coerceElementType
DEBUG: ParameterBinding Information: 0 : Arg is IList with 2 elements
DEBUG: ParameterBinding Information: 0 : Creating array with element type [System.String] and 2 elements
DEBUG: ParameterBinding Information: 0 : Argument type System.Object[] is IList
DEBUG: ParameterBinding Information: 0 : COERCE collection element from type String to type System.String
DEBUG: ParameterBinding Information: 0 : COERCE arg to [System.String]
DEBUG: ParameterBinding Information: 0 : Parameter and arg types the same, no coercion is needed.
DEBUG: ParameterBinding Information: 0 : Adding element of type String to array position 0
The difference i see is that the later one is converted from a System.Object[] to System.String[] and the line that is used from the CSV is converted from a System.String to System.String[].
Can anyone give me a hint to whats going wrong and what i might be able to do to fix it?