Getting Started
Relevant source files
The following files were used as context for generating this wiki page:
- README.md
- src/System.Management.Automation/engine/InitialSessionState.cs
- src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs
- src/System.Management.Automation/help/HelpCommands.cs
- src/System.Management.Automation/help/UpdatableHelpSystem.cs
- test/powershell/engine/Help/HelpSystem.Tests.ps1
- tools/AttackSurfaceAnalyzer/README.md
PowerShell is a cross-platform (Windows, Linux, and macOS) automation and configuration tool and framework. It is optimized for dealing with structured data such as JSON, CSV, and XML, as well as REST APIs and object models. It encompasses a command-line shell, a scripting language, and a framework for processing cmdlets.
Sources: README.md:6-10
The project provides capabilities for managing system automation through various modules and a robust help system. Users can interact with the environment by configuring initial session states, importing modules, and utilizing the extensive built-in command set.
Sources: src/System.Management.Automation/engine/InitialSessionState.cs:450-465, src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs:50-60
Installation and Environment Setup
PowerShell supports multiple installation methods across supported platforms. For developers and users, the environment is typically initialized through a runspace that defines the available commands, variables, and providers.
Sources: README.md:23-26, src/System.Management.Automation/engine/InitialSessionState.cs:440-445
Core Components for Initialization
The environment setup relies on the InitialSessionState class to define the elements present when a session is created. This includes:
- Cmdlets and Functions: Predefined commands for system management.
- Aliases: Shortcuts for commonly used commands (e.g.,
dirforGet-ChildItem). - Variables: Built-in preference variables like
$ErrorActionPreference. - Providers: Interface components for accessing data stores like the FileSystem or Registry.
Sources: src/System.Management.Automation/engine/InitialSessionState.cs:810-850, src/System.Management.Automation/engine/InitialSessionState.cs:1280-1350
The diagram above illustrates the high-level flow of initializing a PowerShell session via the Initial Session State mechanism.
Sources: src/System.Management.Automation/engine/InitialSessionState.cs:915-950
Working with Modules
Modules are the primary vehicle for extending PowerShell functionality. They can contain scripts (.psm1), manifests (.psd1), and binary assemblies (.dll).
Sources: src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs:518-530
Module Types
| Module Type | Description | Primary File Extension |
|---|---|---|
| Script | PowerShell script files that define functions and variables. | .psm1 |
| Binary | Compiled .NET assemblies containing cmdlets and providers. | .dll |
| Manifest | Data files that describe module dependencies and metadata. | .psd1 |
| CIM | Cmdletization XML files defining commands over CIM/WMI objects. | .cdxml |
| Sources: src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs:550-600 |
Import Process
When a module is imported, the system resolves its path, checks compatibility, and binds exported members to the current session.
Sources: src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs:1150-1175
This sequence diagram shows the interaction between the user, engine, and loader during a module import operation.
Sources: src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs:1200-1250
Accessing Help and Documentation
PowerShell includes a comprehensive help system that allows users to discover command usage and syntax.
Sources: src/System.Management.Automation/help/HelpCommands.cs:25-30
Help Views
Users can request different levels of detail using specific parameters with Get-Help:
- Detailed: Provides parameter descriptions and examples.
- Full: Includes all available information, including technical notes.
- Examples: Displays only the example section of the help content.
- Online: Opens the documentation in a web browser.
Sources: src/System.Management.Automation/help/HelpCommands.cs:80-110
Updatable Help
The system supports downloading and updating help content from remote sources to ensure documentation is current.
Sources: src/System.Management.Automation/help/UpdatableHelpSystem.cs:250-270
This flowchart shows the logic used by the help system to locate and display command documentation.
Sources: src/System.Management.Automation/help/UpdatableHelpSystem.cs:400-430, test/powershell/engine/Help/HelpSystem.Tests.ps1:15-30
Testing and Security
Security and stability are managed through various tools, including the Attack Surface Analyzer for Windows installations.
Sources: tools/AttackSurfaceAnalyzer/README.md:5-15
Installation Security Analysis
The project includes tools to analyze changes made to a system's attack surface during PowerShell installation:
- Run-AttackSurfaceAnalyzer.ps1: Executes ASA tests within a Windows container.
- MSI Verification: Ensures official releases are digitally signed by Microsoft Corporation before testing.
Sources: tools/AttackSurfaceAnalyzer/README.md:65-80
| Parameter | Purpose | Source |
|---|---|---|
-MsiPath | Path to the official signed PowerShell MSI file. | tools/AttackSurfaceAnalyzer/README.md:148 |
-OutputPath | Directory where ASA results will be stored. | tools/AttackSurfaceAnalyzer/README.md:149 |
-KeepWorkDirectory | Retains temporary files for debugging purposes. | tools/AttackSurfaceAnalyzer/README.md:151 |
Summary
PowerShell provides a robust automation framework starting with a highly configurable InitialSessionState. Extensions are handled through a strictly defined module system, and usability is supported by an integrated, updatable help system. Security is maintained through digital signature requirements and automated attack surface analysis tools.
Sources: README.md:6-12, src/System.Management.Automation/engine/InitialSessionState.cs:100-110