Listing (and Checking) PowerShell Profiles

by Sep 2, 2015

Profile scripts are PowerShell scripts that launch automatically once PowerShell starts. The path to the primary profile file can be found in $profile.

To get a list of potential profile script paths, try this:

#requires -Version 1
($profile | Get-Member -MemberType NoteProperty).Name | ForEach-Object { $profile.$_ }

To check which profiles are in use on your machine, check out this example:

#requires -Version 3
($profile | Get-Member -MemberType NoteProperty).Name | 
  ForEach-Object { 
      $path = $profile.$_
      New-Object PSObject -Property ([Ordered]@{Path=$Path Exists=(Test-Path $Path) }) 
  
  }

The output would look similar to this:

 
Path                                                                            Exists
----                                                                            ------
C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1                           False
C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShellISE_profile.ps1   False
C:\Users\user09\Documents\WindowsPowerShell\profile.ps1                           True
C:\Users\user09\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1   True

 

The interesting part in this example is how to programmatically access object properties. You can use Get-Member to find out the property names of an object. We’ll look at the hidden gems of this technology in one of the upcoming tips.

Twitter This Tip! ReTweet this Tip!