Set of tools for Powershell environment
Перейти к файлу
Aleksandr Kostikov 288c7a45e7 Open-GitExtensions fix for the latest gitextensions 2024-10-01 15:35:05 -07:00
.vscode Enforcing code style throughout the project 2020-05-05 16:58:52 -07:00
media Screenshot added 2020-05-04 14:09:51 -07:00
.gitignore Initial commit 2020-04-29 21:54:06 +00:00
CODE_OF_CONDUCT.md Initial CODE_OF_CONDUCT.md commit 2020-04-29 14:54:09 -07:00
CONTRIBUTING.md Extracted used indentation style 2020-05-05 16:36:19 -07:00
Colors.ps1 notes 2023-01-04 16:38:10 -08:00
ConstrainedMode.ps1 notes 2023-01-04 16:38:10 -08:00
Data.ps1 constrained mode 2023-01-04 16:21:43 -08:00
DocFx.ps1 Code fixes 2020-07-28 16:54:44 -07:00
Files.ps1 Enforcing code style throughout the project 2020-05-05 16:58:52 -07:00
Functional.ps1 constrained mode 2023-01-04 16:21:43 -08:00
Git.ps1 Open-GitExtensions fix for the latest gitextensions 2024-10-01 15:35:05 -07:00
LICENSE Organizing metadata needed for repo publishing 2020-04-29 15:12:18 -07:00
PSScriptAnalyzerSettings.psd1 Cleaning up trailing spaces 2020-05-04 12:15:52 -07:00
PSToolset.psd1 Open-GitExtensions fix for the latest gitextensions 2024-10-01 15:35:05 -07:00
PSToolset.psm1 Ported over code to run docfx from jupyter notebook 2020-07-28 16:45:02 -07:00
Python.ps1 Ported over code to run docfx from jupyter notebook 2020-07-28 16:45:02 -07:00
README.md Screenshot added 2020-05-04 14:09:51 -07:00
SECURITY.md Cleaning up trailing spaces 2020-05-04 12:15:52 -07:00
Security.ps1 Added ability to lock just with minutes 2020-05-21 16:51:05 -07:00
TabExpansion.ps1 Enforcing code style throughout the project 2020-05-05 16:58:52 -07:00
Text.ps1 Addressed all PSanalyser issues 2020-05-04 12:35:41 -07:00
Utils.ps1 Bumped the module version 2022-06-21 14:16:53 -07:00
Xml.ps1 Enforcing code style throughout the project 2020-05-05 16:58:52 -07:00

README.md

The purpose and state of the repository

This module represents a set of tools for Powershell that I find useful to have available in every Powershell console. It was started as a helper project for some daily work activities and polished over the years as an internal project. Some recent commands rely on Powershell 7 syntax, so the module is marked for Powershell 7, although most of the commands actually should work in older Powershell versions.

You are welcome to use and contribute.

Installation

To make the module auto-discoverable by Powershell, clone it into your Powershell Modules folder without changing it's name:

$modulesFolder = $env:PSModulePath -split ";" | select -f 1
mkdir $modulesFolder -ea Ignore
cd $modulesFolder
git clone https://github.com/microsoft/PSToolset

Powershell should be able to discover module commands after that. If it doesn't you can import the module explicitly

Import-Module PSToolset

Documentation

List all exported commands from the module:

Get-Command -Module PSToolset

Get detailed help for a particular function:

man Set-CmdEnvironment -Detailed

Get examples for a particular function:

man Show-Highlight -Examples

See implementation details in color:

source construct

Source output

Commands

Colors

Name Alias Description
Get-Colors Print all console host colors to the console in color
Get-Source source Print source code of a command or script in color
Show-Highlight hl Highlight portion of some text to make it visually easier to find something in the text
Write-Colorized Output object to stdout with specific color

Data

Name Alias Description
ConvertFrom-Ini Converts ini strings into Powershell hashtable object
ConvertTo-Hash Convert an object into a hash table
ConvertTo-PsObject construct Convert a set of variables into a PsObject
Get-Ini Parse INI file as a hashtable object
Get-Parameter Get names of all available parameters from input objects
Import-Ini Imports ini file into Powershell hashtable object
Show-Ini Print contents of INI parsed file, received from Get-Ini command
Use-Filter f Regex based parameter filter for input objects
Use-Project p Project several parameters from input objects

Files

Name Alias Description
Get-FileEncoding Gets file encoding
Resolve-ScriptPath Resolve path that is local to the script

Functional

Name Alias Description
Get-First first Returns first element in the piped in input that confirms to the condition
Get-Last last Returns last element in the piped in input that confirms to the condition
Get-Median Calculate median of numeric array piped in
Get-Randomized Randomize a sequence that is piped in
Get-Reverse Reverse a sequence that is piped in
Get-Separation separate Separate collection into two based on some condition
Get-UniqueUnsorted Get unique values from an unsorted array
Test-All all Test if all elements in the piped in input confirm to the condition
Test-Any any Test if any element in the piped in input confirms to the condition

Git

Name Alias Description
Get-CommitAuthorDate Get author commit date from a git commit
Get-CommitAuthorEmail Get author email from a git commit
Get-CommitAuthorName Get author name from a git commit
Get-CommitMessage Get commit message from a git commit
Initialize-GitConfig Configure git before the first use; assigns name and email for the current user and sets up some useful defaults
Open-GitExtensions gite Open GitExtensions GUI frontend, by default browse window in the current folder would be opened

Python

Name Alias Description
Start-JupyterNotebook jn Start Jupyter Notebook in current folder or $env:DefaultJupyterNotebookPath. Reuse existing notebook already running if possible
Stop-JupyterNotebook Stop all Jupyter Notebooks running

Security

Name Alias Description
Invoke-Elevated Invoke script in elevated Powershell session
Set-DelayLock lock Lock machine after the specified timeout
Test-Elevated Test if current Powershell session is elevated
Test-Interactive Determine if the current Powershell session is interactive

Text

Name Alias Description
Format-Template Render text template
Get-UnresolvedTemplateItem Find template items that were not resolved yet
Use-Default default Define default value if input is null, false or missing
Use-Parse parse Parse incoming text to find relevant pieces in it

Utils

Name Alias Description
Set-CmdEnvironment call Call .bat or .cmd file and preserve all environment variables set by it
Use-Retries Retry execution of a script that throws an exception

Xml

Name Alias Description
New-XAttribute xattr Create XAttribute object with specified name and value
New-XComment xcomm Create XComment object with specified value
New-XElement xelem Create XElement object and attach specified via script blocks other XObjects in a hierarchal form
New-Xmlns xmlns Create Xmlns object with specified namespace and value
New-XName xname Create XName object with specified name

How to regenerate table of exported commands


Import-Module PSToolset
$functions = get-module pstoolset | % ExportedFunctions | % Keys
$aliases = get-module pstoolset | % ExportedAliases | % Keys
$map = @{}

foreach( $function in $functions )
{
    $map.$function = @{}
    $map.$function.Name = $function
    $map.$function.File = gi (ls function: | where Name -eq $function| % ScriptBlock | % File) | % BaseName

    $map.$function.Description = man $function | select -skip 5 -First 10 | % Trim
    $map.$function.Description = foreach( $line in $map.$function.Description )
    {
        if( -not $line ){ break }
        $line
    }
    $map.$function.Description = $map.$function.Description -join " "
}

foreach( $alias in $aliases )
{
    $function = get-alias $alias | % ResolvedCommand | % Name
    $map.$function.Alias = $alias
}

$parsed = $map.Keys | %{ [PsCustomObject] $map.$psitem }
$groups = $parsed | group File

$table = foreach( $group in $groups )
{
    "## $($group.Name)"
    "Name | Alias | Description"
    "-----|-------|-------------"
    foreach( $element in $group.Group | sort Name )
    {
        "$($element.Name) | $($element.Alias) | $($element.Description)"
    }
    ""
}
$table | clip

"Table is saved to Windows clipboard"