Checking Profile Scripts (Part 1)

by Sep 29, 2020

PowerShell uses up to four profile scripts. When they exist, PowerShell silently executes any content when it launches.

It’s important to know which profile script exist (if any) because their content can slow down PowerShell launch time, and they can be used by rouge code to sneak in.

Testing for profile paths manually can be cumbersome. Here is a fun one-liner that does the job for you:

 
$profile.PSObject.Properties.Name | Where-Object { $_ -ne 'Length' } | ForEach-Object { [PSCustomObject]@{Profile=$_=Test-Path $profile.$_=$profile.$_}}   
 

The result looks similar to this:

 
Profile                Present Path                                                                                   
-------                ------- ----                                                                                   
AllUsersAllHosts         False C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1                                 
AllUsersCurrentHost      False C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShellISE_profile.ps1         
CurrentUserAllHosts      False C:\Users\tobia\OneDrive\Dokumente\WindowsPowerShell\profile.ps1                        
CurrentUserCurrentHost    True C:\Users\tobia\OneDrive\Dokumente\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1  
 


Twitter This Tip! ReTweet this Tip!