0

I have a variables $env that I'd like to use when traversing a powershell object: myObject.$env.connectionstring

This is not working, what I want is for Powershell to evaluate it like: myObject.Production.connectionstring ... instead I'm getting an empty string / null object.

Can I accomplish what I'm trying to do?

2 Answers 2

2

You just need to specify $myObject rather than myObject. This code snippet produces the results I think you are looking for...

$obj = Get-Item C:\Windows
$prop = "Name"

# prints Windows
Write-Host $obj.$prop

# prints 7
Write-Host $obj.$prop.Length
Sign up to request clarification or add additional context in comments.

1 Comment

Good call on the missing $ on myObject. I looked right past that.
0

This should just work. It does for me on PowerShell V3 e.g.:

PS> $d = Get-Date
PS> $time = 'TimeOfDay'
PS> $d.$time.ticks
809485347258

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.