16

I just started yesterday learning about powershell. Very new into powershell. I have created quite a few variables for testing purposes. Below is my questions on variables

  1. How can i list back all the variables that I have created before?
  2. How do I then clear all the contents of the variables?
  3. How do I remove/delete a variables?

1 Answer 1

23
  1. How can I list back all the variables that I have created before?

    • This gets all the variables, not just the ones you created, you need to filter to variable you are concerned about: Get-Variable -name <name without $>
  2. How do I then clear all the contents of the variables?

    • Clear-Variable -name <name without $>
  3. How do I remove/delete a variable?
    • Remove-Variable -name <name without $>
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Travis. Really helpful info. However, when I use the Get-Variable $myvariable, it displays error " Get-Variable : Cannot find a variable with the name 'variable name' ". The same error msg when I use the Clear-Variable
Type the variable name without the $
Added clarification to the answer for this issue
how to clean a global variable from inside a function?

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.