PowerShell
PowerShell, developed by Microsoft, is a task automation and configuration management framework, consisting of a command-line shell and an associated scripting language. Initially a Windows component only, it is now open-source and cross-platform.
The language draws developer’s eye sight due to
- Object-Oriented Pipeline: Unlike most shells that pipe text, PowerShell pipes .NET objects between cmdlets, allowing for more robust and powerful data manipulation without text parsing.
- Cmdlets: Administrative tasks are performed by cmdlets, which are specialized .NET classes. Their
Verb-Nounnaming convention (e.g.,Get-Process) makes them easy to understand and use. - Cross-Platform: PowerShell runs on Windows, macOS, and Linux, enabling administrators to use a single toolset across different environments.
- .NET Integration: Built on the .NET Framework (and now .NET Core), PowerShell provides full access to the extensive capabilities of the .NET ecosystem.
- Remoting: PowerShell has powerful remoting capabilities, allowing scripts and cmdlets to be invoked on remote machines.
- Desired State Configuration (DSC): DSC is a management platform in PowerShell that enables you to manage your IT and development infrastructure with configuration as code.
- Providers: PowerShell uses providers to access data stores, such as the registry and certificate store, as if they were file systems.
- Scripting Language: PowerShell includes a rich scripting language that supports functions, classes, error handling, and other features found in modern programming languages.
PowerShell is a powerful tool for administrators and developers to automate tasks and manage systems at scale.
Web Site
Tools
- Visual Studio Code with PowerShell Extension
- Windows Terminal
- PowerShell ISE (Windows-only)
- Azure PowerShell
Basic
Open TCP port for debug
On server side, open a Tcp Socket on 8080 port (change the target port you are testing)
|
|
On the client side, use tnc command for connection
|
|
Script basic initializer
$PSScriptRoot refers to the directory containing the script. try/finally
restores the original working directory and prints the end time even if the
script body fails.
|
|
Preventing sensitive command being logged by history
To work with shell, we normally have some secrete data to store in the environment, add a backtick(`) as prefix could help prevent the message being logged.
|
|