-
Notifications
You must be signed in to change notification settings - Fork 389
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
UseDeclaredVarsMoreThanAssignments should ignore $Env: #631
Comments
+1 to this - I've experienced this due to setting $env:psmodulepath for the duration of a script. This obviously doesn't get read, so triggers this rule. |
This is already fixed in the current version |
A remark, not to prove the opposite but to take into account the multiple assignment: #PSScriptAnalyzer 1.16.1
#PS 5.1.14409.1012
Invoke-ScriptAnalyzer -ScriptDefinition '$env:Path =$Copypath= [Environment]::GetEnvironmentVariable(''Path'',''Machine'')'
#Warning for copypath
Invoke-ScriptAnalyzer -ScriptDefinition '$env:Path =$Copypath= [Environment]::GetEnvironmentVariable(''Path'',''Machine'');$copypath +="c:\temp\"'
#Warning for Path |
The first one looks correct to me because |
This is still broken for me, here's a repro (does not complain outside a function):
|
@bergmeister - Please reopen - I still see this warning in $x = { $env:foo = 1 }
& $x |
Let me summarise:
|
@bergmeister - Assignments to drive qualified variables should never get a warning regardless of the context. env:, function:, hklm:, etc. If #938 is related to my example, it shouldn't be. |
@lzybkr Sorry, you're right. When I first copy pasted your example then I also saw a warning on |
Hi,
I'm using the following code in from time to time to refresh Environment/Path variables without restarting the OS/Shell:
I think this has proper use cases in software installs and so on.
The text was updated successfully, but these errors were encountered: