Variable with dot (.) in name is not accessible in PowerShell

Hi,
We are not able to access a variable in the PowerShell script if the variable name contains dot (.) in it. For example in the variable section we have defined these variables:

Source.Directory = “c:\test\source”
DestinationDirectory = “c:\test\dest”

and following are commands inside Powershell script editor:
Write-Host SourceDirectory: ${Source.Directory} Destination: $DestinationDirectory
Copy-Item -Path ${Source.Directory} -Destination $DestinationDirectory

Write-Host is printing blank value for ${Source.Directory} in the logs, and thus copy is not working as expected.

But if we change variable name to SourceDirectory (instead of Source.Directory) and also rename it in the PowerShell script then its working fine.

Thanks,

Hi @shashmi,

Thanks for getting in touch! There are a couple of ways this can work, it looks like you are close.

As per the following documentation page, you should be able to reference your Source.Directory variable in the following ways.

For a project variable named Source.Directory

${SourceDirectory} #If your project variable has a stop in it you should remove it when calling this way.
$OctopusParameters["Source.Directory"] #You do not need to remove the stop if calling it like this.
#{Source.Directory} #Using the # syntax will let you call the variable with the stop.

Let me know if this helps clear things up for you. :slight_smile:

Best regards,
Daniel

Hi @Daniel_Fischer,

Thanks for your response.
$OctopusParameters[“Source.Directory”] - this solution is working for me.
I also tried #{Source.Directory} but when such variable is used in combination with other values its not working like for e.g.
#{Source.Directory} + " \ *" #e.g. c:\test\source \ *

but following is working:
$OctopusParameters[“Source.Directory”] + " \ *"

shared this analysis for that it can be helpful for someone else. I am good as one of the two provided solution is working for me.

Thanks,

Hi @shashmi,

Thanks for the update on this one. :slight_smile:

If you have any further questions or run into any issues, please don’t hesitate to let me know.

Best regards,
Daniel

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.