VMware Cloud Community
WJPConway
Contributor
Contributor
Jump to solution

vRO Powershell Host, Invoke and External Script that uses Get-Folder - Positional parameter cauing Pain!!!!!

I have a workflow that is doing several steps,

Basically its a loop that deploys multiple vCD vAPPs from a template

All of this was working, but I now need to add a step that runs a 'Invoke and External Script' (this is to be used with the Get-Folder command and will run a command on all vms in that folder)

The PowerShell host is added fine and tested and working

I have mapped the attributes (basically the host is static and set at a PowerShell Host, external Script is also Static and set at the location of the Script on the PowerShell host - the External script arguments are the only thing can change.

I have debugged that the script is getting called and run - and it looks to me like the argument is correct

To narrow things down - I have cut everything bare the essential form the script

The PowerShell script is pretty simple see below

$InputFolder=$args[0]+'*' |Out-File c:\scriptserver\utils\args.csv -Append

#$InputFolder='SomeValue'

$Folder = Get-Folder $InputFolder |Out-File c:\scriptserver\utils\args.csv -Append

My  c:\scriptserver\utils\args.csv - gets the first entry fine as I would expect - its basically a Folder with * appended to the end.

The Second line then is blank - but should be a single folder name - the Get-Folder would always have only 1 output

I know that if I run the Get-Folder with the output it does find a folder so the folder does exist

Pretty sure its something to do with scope or how I am mapping the $InputFolder to $args[0]

The basic error is Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again

I am not sure where parameter Name is coming from and I don't see any null values in the attributes but know this is got to do with the handover from vRO to Powershell  or how I am mapping the input in the vRO workflow to the parameter on the PowerShell script

The full error is below

[2020-02-19 05:14:59.080] [E] (com.vmware.library.powershell/invokeScript) Error in (Dynamic Script Module name : invokeScript#14) PowerShellInvocationError: Errors found while executing script
System.Management.Automation.ParameterBindingValidationException: Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. ---> System.Management.Automation.ValidationMetadataException: The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
   at System.Management.Automation.ValidateNotNullOrEmptyAttribute.Validate(Object arguments, EngineIntrinsics engineIntrinsics)
   at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
   --- End of inner exception stack trace ---
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
   at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseToInvoke clauseToInvoke, Boolean createLocalScope, Dictionary`2 functionsToDefine, List`1 variablesToDefine, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Object[] args)
   at System.Management.Automation.ScriptBlock.<>c__DisplayClass57_0.<InvokeWithPipe>b__0()
   at System.Management.Automation.Runspaces.RunspaceBase.RunActionIfNoRunningPipelinesWithThreadCheck(Action action)
   at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Boolean propagateAllExceptionsToTop, List`1 variablesToDefine, Dictionary`2 functionsToDefine, Object[] args)
   at System.Management.Automation.ScriptBlock.InvokeUsingCmdlet(Cmdlet contextCmdlet, Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Object[] args)
   at Microsoft.PowerShell.Commands.InvokeExpressionCommand.ProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()

[2020-02-19 05:14:59.103] [E] Workflow execution stack:
***
item: 'Invoke an external script/item0', state: 'failed', business state: 'null', exception: 'PowerShellInvocationError: Errors found while executing script
System.Management.Automation.ParameterBindingValidationException: Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. ---> System.Management.Automation.ValidationMetadataException: The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
   at System.Management.Automation.ValidateNotNullOrEmptyAttribute.Validate(Object arguments, EngineIntrinsics engineIntrinsics)
   at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
   --- End of inner exception stack trace ---
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
   at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseToInvoke clauseToInvoke, Boolean createLocalScope, Dictionary`2 functionsToDefine, List`1 variablesToDefine, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Object[] args)
   at System.Management.Automation.ScriptBlock.<>c__DisplayClass57_0.<InvokeWithPipe>b__0()
   at System.Management.Automation.Runspaces.RunspaceBase.RunActionIfNoRunningPipelinesWithThreadCheck(Action action)
   at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Boolean propagateAllExceptionsToTop, List`1 variablesToDefine, Dictionary`2 functionsToDefine, Object[] args)
   at System.Management.Automation.ScriptBlock.InvokeUsingCmdlet(Cmdlet contextCmdlet, Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Object[] args)
   at Microsoft.PowerShell.Commands.InvokeExpressionCommand.ProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()
(Dynamic Script Module name : invokeScript#14)'
workflow: 'Deploy Multiple vPODs (Include DRS and MacLearn)' (b66e3d66-a34c-4c78-a844-4e5e1f24328d)
|  'attribute': name=vdc type=vCloud:Vdc value=dunes://service.dunes.ch/CustomSDKObject?id='26ea2c9536a679b87134257214a4fe22a89f74d29a2b8cb4b315f75e83ffcac::::aHR0cHM6Ly9jbG91ZC12aXAuaW5mcmEubGFiLmxvY2FsL2FwaS92ZGMvOTY4M2E0OTctMTk3ZS00YzY1LTg4MzctNTg5OGY4M2Y1MjA0'&dunesName='vCloud:Vdc'
|  'attribute': name=deploy type=boolean value=true
|  'attribute': name=powerOn type=boolean value=true
|  'attribute': name=eulaAccepted type=boolean value=true
|  'attribute': name=runtimeLeaseHours type=number value=500.0
|  'attribute': name=storageLeaseHours type=number value=500.0
|  'attribute': name=linkedClone type=boolean value=true
|  'attribute': name=deleteSource type=boolean value=false
|  'attribute': name=vpodnumberout type=number value=0.0
|  'attribute': name=name type=string value=Temp-1
|  'attribute': name=description type=string value=Deployed from vCD Service Catalog, Date: Wed Feb 19 2020 10:11:23 GMT-0000 (UTC)From Template: TMPL-1.0.0-InfraCore
|  'attribute': name=vapp type=vCloud:VApp value=dunes://service.dunes.ch/CustomSDKObject?id='26ea2c9536a679b87134257214a4fe22a89f74d29a2b8cb4b315f75e83ffcac::::aHR0cHM6Ly9jbG91ZC12aXAuaW5mcmEubGFiLmxvY2FsL2FwaS92QXBwL3ZhcHAtNjgyODViNDgtYzVlNy00ZWQ2LTg1ZjUtZmViNmJkMWJiYzVl'&dunesName='vCloud:VApp'
|  'attribute': name=host type=PowerShell:PowerShellHost value=dunes://service.dunes.ch/CustomSDKObject?id='0bb2b363-7f48-4264-b50b-092b78e6d815'&dunesName='PowerShell:PowerShellHost'
|  'attribute': name=externalScript type=string value=C:\scriptserver\scripts\vcenter\drsrulesfromvro.ps1
|  'attribute': name=vcenterfolderstring type=string value=Will-10_230_76_50-R7zX
|  'input': name=vappTemplate type=vCloud:VAppTemplate value=dunes://service.dunes.ch/CustomSDKObject?id='26ea2c9536a679b87134257214a4fe22a89f74d29a2b8cb4b315f75e83ffcac::::aHR0cHM6Ly9jbG91ZC12aXAuaW5mcmEubGFiLmxvY2FsL2FwaS92QXBwVGVtcGxhdGUvdmFwcFRlbXBsYXRlLTRlYTIzNzJkLWY0MTEtNDBiNy1iOGU1LTc4ZmZmZWQ5ZDBhNA'&dunesName='vCloud:VAppTemplate'
|  'input': name=prefix type=string value=Will
|  'input': name=vpodnumber type=number value=1.0
|  'output': name=vappOut type=vCloud:VApp value=null
|  'output': name=output type=PowerShell:PowerShellRemotePSObject value=null
--workflow: 'Invoke an external script' (A3818080808080808080808080808080B180808001304933636362ce882292c2a)
  |  'input': name=host type=PowerShell:PowerShellHost value=dunes://service.dunes.ch/CustomSDKObject?id='0bb2b363-7f48-4264-b50b-092b78e6d815'&dunesName='PowerShell:PowerShellHost'
  |  'input': name=externalScript type=string value=C:\scriptserver\scripts\vcenter\drsrulesfromvro.ps1
  |  'input': name=arguments type=string value=Will-10_230_76_50-R7zX
  |  'output': name=output type=PowerShell:PowerShellRemotePSObject value=null
  |  'no attributes'
*** End of execution stack.

0 Kudos
1 Solution

Accepted Solutions
eoinbyrne
Expert
Expert
Jump to solution

I think in your updated version your issue is that you are using Out-File to write the output (or more specifically, the return value) of the cmdlet to your CSV file. AFAIK Write-Host just writes the value to the console and the returns nothing.

pastedImage_2.png

The " | Out-File" writes whatever the result was of the operation. In the $InputFolder assignment case there is a result which can be piped to Out-File - as you have proved Smiley Happy

Here's a mimic of what you're doing

pastedImage_4.png

You can see the outfile.csv in the top left after the script was executed. There is a CRLF after the initial assignment and the write-host does not append to the file

View solution in original post

4 Replies
WJPConway
Contributor
Contributor
Jump to solution

Based on further testing the keys seems to be

$InputFolder=$args[0]+'*' |Out-File c:\scriptserver\utils\args.csv -Append

Write-Host $InputFolder  |Out-File c:\scriptserver\utils\args.csv -Append

Post running the script the args.csv file will have the first line filled with the $args plus the *  - but nothing for the second line - see sample below

vAPP-100*   [Where vAPP-100 is the argument and * is being added in the first line of code]

So the line $InputFolder=$args[0]+'*' ends up with $InputFolder having a blank string

Anyone got any clue as to whatas happening 0

0 Kudos
WJPConway
Contributor
Contributor
Jump to solution

Ok resolved this,

Rather than trying to

$InputFolder=$args[0]+'*'

Get-Folder $InputFolder

I just plugged the arg directly in and it seemed to work fine now

Get-Folder $($args[0]+'*')

0 Kudos
eoinbyrne
Expert
Expert
Jump to solution

I think in your updated version your issue is that you are using Out-File to write the output (or more specifically, the return value) of the cmdlet to your CSV file. AFAIK Write-Host just writes the value to the console and the returns nothing.

pastedImage_2.png

The " | Out-File" writes whatever the result was of the operation. In the $InputFolder assignment case there is a result which can be piped to Out-File - as you have proved Smiley Happy

Here's a mimic of what you're doing

pastedImage_4.png

You can see the outfile.csv in the top left after the script was executed. There is a CRLF after the initial assignment and the write-host does not append to the file

WJPConway
Contributor
Contributor
Jump to solution

Thanks Eoin, So basically I was tripping myself up trying to know what every value was during the running of the script and using the Write-Host incorrectly (while it did what I wanted when I was running the script locally it wasn't when the script was being run remotely from the vRO Server).

Lesson Learned for next time I guess..

0 Kudos