PowerTip: Find Name and Location of PowerShell Profiles

Summary: Learn how to find the name and location of various Windows PowerShell profiles.

Hey, Scripting Guy! Question How can I find the name and location of various Windows PowerShell profiles?

Hey, Scripting Guy! Answer Use the $profile automatic variable to see what profiles are available for your particular Windows PowerShell
           host (for example, the console host or the ISE). To find only the name and the location of the profiles,
           you need to return only the properties from the object and then look for names that  begin with A or C,
           for example:

(($PROFILE).psobject.Properties).where({$_.name -match 'a|c'}) | select name, value

Comments (5)

  1. Mike Shepard says:

    I get these with this line:
    $profile | select *user* | fl *

  2. James A. Brown says:

    The command is incorrect. It’s calling ‘where’ as a method, when the objects should be piped into ‘Where-Object’ or its alias ‘where’:

    (($PROFILE).psobject.Properties) | where({$_.name -match ‘a|c’}) | select name, value

    And of course, Mike Shepard’s one-liner is much simpler.

  3. Ed Wilson says:

    @Mike Shepard that is a nice way to get the information, and is easier. But my command returns an object that now I can use to get a listing of all the names, or all of the values:
    PS C:> $a = (($PROFILE).psobject.Properties).where({$_.name -match ‘a|c’}) | select name, value
    PS C:> $a.name
    PS C:> $a.value

  4. Ed Wilson says:

    @James Brown Beginning with powerShell 4.0, there is no need to pipeline to Where-Object. Where as a method was introduced, and my code works fine on PowerShell 4 and above. Also see my reply to Mike about the advantage of my code in returning objects.

  5. James A. Brown says:

    Thanks, Ed. I wasn’t aware of that change in version 4.

Skip to main content