A PowerShell profile is a script that runs when a hosting application starts a session. Use it to make recurring administrative setup automatic instead of retyping commands. section 26.1.1
A profile can prepare a session by:
- Loading frequently used modules, such as ActiveDirectory or DBATools. section 26.1.1
- Changing to a preferred starting directory, such as the root of the C: drive. section 26.1.1
- Defining reusable functions, including a custom prompt function. section 26.1.1 section 26.1.2
- Applying settings that may depend on the host; console-specific changes can fail in VS Code or Windows Terminal. section 26.1.1
A practical startup profile
A profile can import commonly used modules and place the session where work begins. Importing ActiveDirectory also makes its AD: PowerShell drive available immediately. Add only settings that work in the hosting applications you use. section 26.1.1
A more informative prompt
Define a prompt function in the profile to display the current time and computer name, producing a prompt such as 6:07 PM [CLIENT01]:>.
Import-Module ActiveDirectory Import-Module DBATools cd c:\
Inspect a compact example of module loading and starting-directory setup. section 26.1.1
