PowerShell Scripts, Tips, Expert Advices, Forums, and Resources

Geek Sync Live

Welcome to PowerShell.com, the educational and community site for Windows PowerShell People. Get a quick overview.

Latest Scripts

09-01-2015 - Gui multi-vcenter login
08-31-2015 - Generic
08-31-2015 - restapi

As a Powershell.com member you will have access to:

  • Daily PowerShell tips written by Microsoft MVPs and other leading Windows PowerShell experts
  • Free Windows PowerShell advice and training provided by Microsoft MVPs and other leading Windows PowerShell experts
  • Access to leading Windows PowerShell blogs
  • A free ebook, Mastering PowerShell, written by Microsoft MVP Dr. Tobias Weltner
PowerTip of the Day

Listing (and Checking) PowerShell Profiles

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!

Copyright 2012 PowerShell.com. All rights reserved.