PowerTip: Easily Find the Value of a PowerShell Variable


Summary: Learn how to return only the value of a Windows PowerShell variable.

Hey, Scripting Guy! Question How can I use a Windows PowerShell cmdlet to return only the value of a particular variable?

Hey, Scripting Guy! Answer Use the Get-Variable cmdlet, and specify the name of the variable and the –valueonly switch. This technique is shown here using the home variable:

PS C:\> Get-Variable -Name home -ValueOnly

C:\Users\ed.IAMMRED

Comments (2)

  1. Dave says:

    Why wouldn't I just type:

    PS C:> $home

    C:Usersed.IAMMRED

  2. Ed Wilson says:

    @Dave you absolutely can do that! I was just pointing out a cool switch to the Get-Variable cmdlet — The Get-Variable cmdlet is extremely powerful and permits you to use wildcard patterns to find variables, as well as easily specify the scope. In addition, you can use include and exclude patterns.

Skip to main content