This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

PS1 Sync project - global variables

Hello, 

 

how to setup correctly global variables in PowerShell Sync Project?

 

I've created a custom command used in Connect, that takes some configuration parameters as input and sets global variables:

<CustomCommand Name="Init">
<![CDATA[
param(
[parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[String]$User,
[parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[String]$Pass
)

(... do some logic ...)

$global:AuthHeader = $header

]]>
</CustomCommand>

 

I tried to use this variable in other commands, with:

<SetParameter Param="Auth" Source="GlobalVariable" Value="AuthHeader" />

 

Unfortunately I always get: The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

 

What might be the problem?

 

Thank you,
Piotr Markiewicz

Parents
  • Hi Markus,

    yes I'm sure. For the test I was dumping contents of global: variables to file.

    My findings:
    * <SetParameter Param="Auth" Source="GlobalVariable" Value="AuthHeader" /> does not work, the parameter is not assigned to the call (NULL)
    * I can use global variables in other methods without passing them as parameters (as mentioned above), won't work for standard cmdlets though (value must be passed as param)

    For me, it's enough for now as I need those global variables in my custom method. Maybe this way of passing parameters works only for standard cmdlets?

    Piotr
Reply
  • Hi Markus,

    yes I'm sure. For the test I was dumping contents of global: variables to file.

    My findings:
    * <SetParameter Param="Auth" Source="GlobalVariable" Value="AuthHeader" /> does not work, the parameter is not assigned to the call (NULL)
    * I can use global variables in other methods without passing them as parameters (as mentioned above), won't work for standard cmdlets though (value must be passed as param)

    For me, it's enough for now as I need those global variables in my custom method. Maybe this way of passing parameters works only for standard cmdlets?

    Piotr
Children
No Data