Variable squeezing

When you’re developing code interactively how often do you set a variable and then display it to test the result? You can do that in one go using variable squeezing.

Normally you’d do:

PS> $test = 1
PS> $test

Set the variable and display the contents as two separate actions.

By enclosing the first statement in parentheses you accomplish both tasks

PS> ($test2 = 2)

Great for interactive work but you don’t want in in scripts as you’d be getting output every time you set a variable value!

This entry was posted in Powershell. Bookmark the permalink.

One Response to Variable squeezing

  1. Pingback: Figuring out a PowerShell version of Dynamic SQL – No Column Name

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s