Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Set-Variable vs. $foo = "bar" best practice #144

Open
tscholze opened this issue May 24, 2020 · 2 comments
Open

Add Set-Variable vs. $foo = "bar" best practice #144

tscholze opened this issue May 24, 2020 · 2 comments

Comments

@tscholze
Copy link

Hi,

I'm a beginner and a little bit confused in which cases I should use the following syntax:

Set-Variable -Name "desc" -Value "A description"

and ich which cases it is ok do to the simpler

$desc = "A description"

I could not find any helpful information in the internet, maybe someone has a link for me? :)__

@rkeithhill
Copy link

In general, use variable assignment (your second case above). Set-Variable is handy if the name of a variable is itself contained in a variable e.g. Set-Variable -Name $varname -Value 42. Set-Variable is also handy if you need to specify Option, Visibility or Scope which is somewhat uncommon compared to variable assignment.

@tscholze
Copy link
Author

@rkeithhill thanks for you answer. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants