Accessing Profile Scripts

Profile scripts are executed automatically when PowerShell starts. The paths to these scripts can be found in $profile:

$profile | gm *Host* | % { $_.Name } | % {
$rv = @{}; $rv.Name = $_
$rv.Path = $profile.$_
$rv.Exists= (Test-Path $profile.$_)
New-Object PSObject -Property $rv
} | Format-Table -AutoSize
Name Path Exists
---- ---- ------
AllUsersAllHosts C:\Windows\...ps1 True
AllUsersCurrentHosts C:\Windows\...ps1 False
CurrentUserAllHosts C:\Users\...ps1 True
CurrentUserCurrentHost C:\Users\...ps1 True

Twitter This Tip! ReTweet this Tip!


Posted Mar 05 2010, 08:00 AM by ps1

Comments

Aleksandar wrote re: Accessing Profile Scripts
on 03-05-2010 3:52 PM

Here is a quick way to find just  the paths to profile scripts:

$profile.psextended | fl *

The following command will give you a similar output as the command from a power tip, but using a different approach:

$profile.psextended | gm | select name,@{n="Path";e={$profile.($_.name)}},@{n="Exists";e={test-path $profile.($_.name)}}

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.