Profile Execution

PowerShell ASP will not attempt to load any profiles by default. There are two options for loading profiles with PowerShell ASP.

Dot Sourcing

Dot sourcing can be used to load any profile. For example: ./profiles/YourProfile.ps1

PSASPRunProfiles Setting

When this setting is specified in the appSettings section of the web.config, PowerShell ASP will attempt to load and run profiles automatically. PowerShell ASP will use the host-agnostic profile scripts (e.g. profile.ps1) and Server-specific named profiles that are only run for PowerShell ASP connections named "nsoftware.PowerShellASP_profile.ps1".

Profiles will first be loaded from the "%SystemRoot%\System32\WindowsPowerShell\v1.0" location and then the "%UserProfile%\Documents\WindowsPowerShell" location.

To enable this option in the web.config file add the key "PSASPRunProfiles" to the appSettings sections with a value of "true". For instance:

<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <system.web>
  ...
  </system.web>
  <system.webServer>
  ...
  </system.webServer>
  <appSettings>
    <add key="PSASPRunProfiles" value="true"/>    
  </appSettings>
</configuration>

PSASPProfile

When this setting is specified in the appSetting section of the web.config, PowerShell ASP will attempt to load the profile from the location specified as the value of the key. Note that the PSASPRunProfiles setting also needs to be set to true in order for the profile to be loaded. Both paths relative the web directory and absolute paths are allowed. For example:

<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <system.web>
  ...
  </system.web>
  <system.webServer>
  ...
  </system.webServer>
  <appSettings>
    <add key="PSASPRunProfiles" value="true"/>    
    <add key="PSASPProfile" value="../profile.ps1"/> 
  </appSettings>
</configuration>

This would cause PowerShell ASP to load the script named "profile.ps1" one directory up from the web directory to be loaded.

Copyright (c) 2022 /n software inc. - All rights reserved.
PowerShell Server 2020 - Version 20.0 [Build 8318]