Saturday 17 April 2010

Get-ProfileFile.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script gets the details of the PowerShell profile files
  4.     related to a given host. 
  5. .DESCRIPTION 
  6.     This script gets the 4 script file names from the $profile
  7.    variable and creates a custom object containing the name and
  8.     path or each profile, and whether that profile actually exists. 
  9. .NOTES 
  10.     File Name  : Get-ProfileFile.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 2.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://pshscripts.blogspot.com/2010/04/get-profilefileps1.html 
  16. .EXAMPLE 
  17.     [PS] C:\foo:> .\Get-ProfileFile.ps1' 
  18.     Name   : AllUsersAllHosts 
  19.     Path   : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1 
  20.     Exists : True 
  21.     Name   : AllUsersCurrentHosts 
  22.     Path   : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1 
  23.     Exists : False 
  24.     Name   : CurrentUserAllHosts 
  25.     Path   : C:\Users\tfl\Documents\WindowsPowerShell\profile.ps1 
  26.     Exists : True 
  27.     Name   : CurrentUserCurrentHost 
  28.     Path   : C:\Users\tfl\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 
  29.     Exists : True 
  30. #> 
  31.  
  32. ##  
  33. # Start of Script 
  34. ## 
  35.  
  36. $profile | gm *Host* | % { $_.Name } | % { 
  37. $rv = @{}; $rv.Name = $_ ;$rv.Path = $profile.$_
  38. $rv.Exists= (Test-Path $profile.$_); 
  39. New-Object PSObject -Property $rv  
  40. } | Format-List  
  41.  
  42. # End of script