#PSTip Find all PowerShell Profiles from $PROFILE

Note: This tip requires PowerShell 2.0 and above

I have always wanted to see what all PowerShell profiles are defined and in-use on a system. Sometimes, this is very crucial to understand what exactly is causing errors in scripts.

The $PROFILE automatic variable shows the current PowerShell Profile in use within the host. Now, a less known fact is that the $PROFILE also has extended properties that show different PowerShell path properties.

Let us see how we can use this to find all PowerShell profiles in use.

function Get-PSProfile{
 $PROFILE.PSExtended.PSObject.Properties |
 Select-Object Name,Value,@{Name='IsExist';Expression={Test-Path -Path $_.Value -PathType Leaf}}

This gives us an output similar to:

About the author: Shay Levy

Shay Levy is a Co-founder and editor of the PowerShell Magazine. He is a multiple-year recipient of the Microsoft MVP award, and a Microsoft Certified Trainer (MCT). Shay often covers PowerShell related topics on his blog and you can also follow him on Twitter at @ShayLevy

Related Posts