Powershell Profile

Oct 3, 2008 at 2:10 PM
Does PolyMon load a Powershell Profile and how would one change it?

Or is there another way to set global variables and load particular functions?

Oct 3, 2008 at 11:41 PM

Not that I am aware of. I can look into how to do something like that, but can you educate me a little about what a PowerShell Profile is and how you usually load it into PowerShell.

Is it not possible to load it using commands within the PowerShell script itself? If so, then you could include the code right into the script itself...

Maybe someone else out there has some ideas on this?

Oct 4, 2008 at 2:41 PM
Edited Oct 4, 2008 at 8:09 PM
PowerShell profile is a script (or set of scripts) that run when a PowerShell host starts.  There are multiple locations and names for a PowerShell profile. There are machine specific (all user) profiles are stored in the %WinDir%\System32\WindowsPowerShell folder, and the user specific profiles are stored in %userprofile%\Documents(or My Documents)\WindowsPowerShell. 

The file names used for profile scripts are profile.ps1(which is a global -all hosts- profile script) and Microsoft.PowerShell_profile.ps1 (which is the profile script for the default cmd.exe style host).  Other PowerShell hosts could have a different profile script associated.  The $profile automatic variable points to the shell specific profile.

What is happening in the PowerShell monitor and in the after monitor action script is that a PowerShell runspace is being created and no profile scripts are being added to the runspace.  

If you would like your profile scripts to be available, you could run the profile script at the start of your monitor script or after monitor action script.  You would have to specifically run each profile script you wanted to use.   I don't think the $profile value is accessible in the runspace, but I'm not 100% positive, so I think you would have to declare the full path of the profile script you want to run.  The script should be run "dot sourced" to make any functions and variables defined available in the runspace.

Example: . c:\users\sjm199\documents\windowspowershell\profile.ps1 (would run the global, all shells, profile script)

Hope this helps.