Last active
September 14, 2018 17:42
-
-
Save techthoughts2/38ccacf3c7d2bf761c3783e131e589df to your computer and use it in GitHub Desktop.
Checks the location of all 6 PowerShell Profile to determine if there is a Profile file loaded there. If there is, the contents will be scanned so you can see what profile customizations are being loaded up.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Synopsis | |
Evaluates all 6 PowerShell Profile locations and will indicate if they are present - and if so what they contain | |
.DESCRIPTION | |
Checks the location of all 6 PowerShell Profile to determine if there is a Profile file loaded there. If there is, the contents will be scanned so you can see what profile customizations are being loaded up. | |
.EXAMPLE | |
Test-PSProfiles | |
Checks all 6 PowerShell Profile locations and returns results | |
.EXAMPLE | |
Test-PSProfiles -Verbose | |
Checks all 6 PowerShell Profile locations and returns results with verbose output | |
.OUTPUTS | |
Custom PSObject | |
Name Present Contents | |
---- ------- -------- | |
allUsersAllHosts False | |
allUsersCurrentHostConsole False | |
allUsersCurrentHostISE False | |
currentUserAllHosts False | |
currentUserCurrentHostConsole True Write-Host "Hello Jake. Welcome Back" -ForegroundCo... | |
currentUserCurrentHostISE False | |
.NOTES | |
Author: Jake Morrison | |
http://techthoughts.info | |
Based on information from scripting guy: https://blogs.technet.microsoft.com/heyscriptingguy/2012/05/21/understanding-the-six-powershell-profiles/ | |
$PSHOME = C:\Windows\System32\WindowsPowerShell\v1.0 | |
$HOME = C:\Users\currentuser | |
#> | |
function Test-PSProfiles { | |
[CmdletBinding()] | |
param() | |
begin { | |
Write-Verbose -Message "Begin." | |
Write-Verbose -Message "Loading 6 PS Profile locations..." | |
$allUsersAllHosts = "$PSHOME\Profile.ps1" | |
$allUsersCurrentHostConsole = "$PSHOME\Microsoft.PowerShell_profile.ps1" | |
$allUsersCurrentHostISE = "$PSHOME\Microsoft.PowerShellISE_profile.ps1" | |
$currentUserAllHosts = "$HOME\Documents\WindowsPowerShell\Profile.ps1" | |
$currentUserCurrentHostConsole = "$HOME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1.ps1" | |
$currentUserCurrentHostISE = "$Home\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1" | |
Write-Verbose -Message "Creating Hash of all profile locations..." | |
$profileHash = @{ | |
"allUsersAllHosts" = $allUsersAllHosts; | |
"allUsersCurrentHostConsole" = $allUsersCurrentHostConsole; | |
"allUsersCurrentHostISE" = $allUsersCurrentHostISE; | |
"currentUserAllHosts" = $currentUserAllHosts; | |
"currentUserCurrentHostConsole" = $currentUserCurrentHostConsole; | |
"currentUserCurrentHostISE" = $currentUserCurrentHostISE; | |
}#profileHash | |
}#begin | |
process { | |
Write-Verbose -Message "Process." | |
$resultsArray = @() | |
Write-Verbose -Message "Evaluating each PS Profile location..." | |
$profileHash.GetEnumerator() | ForEach-Object { | |
$nameProperty = ($_.Name) | |
Write-Verbose -Message "Checking $nameProperty" | |
$evalProperty = $false | |
$contentsProperty = "" | |
if (Test-Path ($_.value)) { | |
Write-Verbose -Message "Found." | |
$evalProperty = $true | |
$contentsProperty = Get-Content ($_.value) | |
}#if-testLocation | |
$resultsArray += @{ | |
"Name" = $nameProperty; | |
"Present" = $evalProperty; | |
"Contents" = $contentsProperty | |
} | |
}#ForEach-Object | |
}#proces | |
end { | |
Write-Verbose -Message "Generating results..." | |
$a = $resultsArray | ForEach-Object { new-object PSObject -Property $_} | |
$output = $a | Select-Object Name, Present, Contents | Sort-Object Name | |
Write-Verbose -Message "Complete." | |
return $output | |
}#end | |
}#function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment