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

  • Your usage of the global variable seems to be fine. I have used it in the same way in the past and it worked.

    Are you sure that $header is not null or empty?
  • 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
  • I have used the global variable in my custom command. Did you declare the parameter Auth in your custom commandlet?
  • Yes, I did unfortunately I haven't saved the xml of incorrect configuration.

    I've tried to reproduce the error now, and it works, the value is passed correctly.
    It must have been an error with the call (var name maybe). No idea why I was experiencing issues yesterday.

    I was able to use the SetParameter correctly.