diff --git a/docs/DOCSMIGRATION.md b/docs/DOCSMIGRATION.md index e3aef3ad111..43c1b23dfe4 100644 --- a/docs/DOCSMIGRATION.md +++ b/docs/DOCSMIGRATION.md @@ -2,7 +2,7 @@ The docs folder in this repo contains a lot of documentation about the PowerShell source code and build environment. It also has contained documentation about installing and using PowerShell. -That documentation really belongs in the [PowerShell/PowerShell-Docs](https://github.com/PowerShell/PowerShell-Docs) repo. +That documentation belongs in the [PowerShell/PowerShell-Docs](https://github.com/PowerShell/PowerShell-Docs) repo. We are in the process of migrating the user-focused articles to the docs repo. This file records which files have been migrated. diff --git a/docs/building/internals.md b/docs/building/internals.md index 1ed23dc85b5..e6d800167b5 100644 --- a/docs/building/internals.md +++ b/docs/building/internals.md @@ -143,7 +143,7 @@ Be sure to build and test for all supported architectures: `x86`, `x64`, `x64_ar The `x64_arm` and `x64_arm64` architectures mean that the host system needs to be x64 to cross-compile to ARM. When building for multiple architectures, be sure to use the `-clean` switch as cmake will cache the previous run and the wrong compiler will be used to generate the subsequent architectures. -After that, the binary `pwrshplugin.dll`, its PDB file, and `powershell.core.instrumentation.dll` will be placed under 'src\powershell-win-core'. +After that, the binary `pwrshplugin.dll`, its PDB file, and `powershell.core.instrumentation.dll` will be placed under `src\powershell-win-core`. To create a new NuGet package for `pwrshplugin.dll`, first you need to get the `psrp.windows.nuspec` from an existing `psrp.windows` package. You can find it at `~/.nuget/packages/psrp.windows` on your windows machine if you have recently built PowerShell on it. diff --git a/docs/cmdlet-example/visual-studio-simple-example.md b/docs/cmdlet-example/visual-studio-simple-example.md index 6f91d064a3e..d027bcdf0f8 100644 --- a/docs/cmdlet-example/visual-studio-simple-example.md +++ b/docs/cmdlet-example/visual-studio-simple-example.md @@ -30,7 +30,7 @@ Add another package source with name `powershell-core` and source `https://power ![Step4](./Images/Step4.png) 1. Add the code of cmdlet: - ```CSharp + ```csharp using System.Management.Automation; // PowerShell namespace. namespace SendGreeting @@ -90,7 +90,7 @@ It should find `PowerShellStandard.Library` package, select it and it will show ![StdImage3](./Images/Std3.png) 1. Add the code of cmdlet: - ```CSharp + ```csharp using System.Management.Automation; // PowerShell namespace. namespace SendGreeting @@ -128,4 +128,4 @@ It should find `PowerShellStandard.Library` package, select it and it will show On PowerShell Core on Linux: ![StdImage62](./Images/Std62.png) On Windows PowerShell on Windows (this requires [.NET Framework 4.7.1](https://github.com/Microsoft/dotnet-framework-early-access/blob/master/instructions.md)): -![StdImage63](./Images/Std63.png) \ No newline at end of file +![StdImage63](./Images/Std63.png) diff --git a/docs/community/governance.md b/docs/community/governance.md index ec72ec2e2c3..c847cda4f58 100644 --- a/docs/community/governance.md +++ b/docs/community/governance.md @@ -5,6 +5,7 @@ * [**PowerShell Committee**](#powershell-committee): A committee of project owners who are responsible for design decisions, approving [RFCs][RFC-repo], and approving new maintainers/committee members * [**Repository maintainer**](#repository-maintainers): An individual responsible for merging pull requests (PRs) into `master` when all requirements are met (code review, tests, docs, and RFC approval as applicable). + Repository Maintainers are the only people with write permissions for the `master` branch. * [**Area experts**](#area-experts): People who are experts for specific components (e.g. PSReadline, the parser) or technologies (e.g. security, performance). Area experts are responsible for code reviews, issue triage, and providing their expertise to others. diff --git a/docs/debugging/README.md b/docs/debugging/README.md index 5e7de2b87e7..36107f1ba06 100644 --- a/docs/debugging/README.md +++ b/docs/debugging/README.md @@ -1,5 +1,4 @@ -Visual Studio Code -================== +# Visual Studio Code [Experimental .NET Core Debugging in VS Code][core-debug] enables cross-platform debugging with the [Visual Studio Code][vscode] editor. @@ -48,8 +47,7 @@ careful not to commit such a change.) [OmniSharp]: https://github.com/OmniSharp/omnisharp-vscode [vscclrdebugger]: https://aka.ms/vscclrdebugger -PowerShell -========== +## PowerShell The `Trace-Command` cmdlet can be used to enable tracing of certain PowerShell subsystems. Use `Get-TraceSource` for a list of tracers: @@ -91,8 +89,7 @@ The `-PSHost` specifies the sink, in this case the console host, so we can see the tracing messages. The `-Name` chooses the list of tracers to enable. -LLDB with SOS plug-in -===================== +## LLDB with SOS plug-in The `./tools/debug.sh` script can be used to launch PowerShell inside of LLDB with the SOS plug-in provided by .NET Core. This provides an additional way to @@ -104,14 +101,12 @@ The script is self-documented and contains a link to the [clr-debug]: https://github.com/dotnet/coreclr/blob/master/Documentation/building/debugging-instructions.md#debugging-coreclr-on-linux -corehost -======== +## `corehost` The native executable produced by .NET CLI will produce trace output if launched with `COREHOST_TRACE=1 ./powershell`. -CoreCLR PAL -=========== +## CoreCLR PAL The native code in the CLR has debug channels to selectively output information to the console. These are controlled by the @@ -123,8 +118,7 @@ you will need to narrow your scope. [header]: https://github.com/dotnet/coreclr/blob/release/1.0.0/src/pal/src/include/pal/dbgmsg.h -Debugging .NET Core -=================== +## Debugging .NET Core The .NET Core libraries downloaded from NuGet and shipped with PowerShell are release versions. This means that `PAL_DBG_CHANNELS` will not work with them, @@ -134,16 +128,14 @@ but should prove useful. They are currently written for Linux and are meant only as a shortcut means to debug. -Build and deploy CoreCLR ------------------------- +## Build and deploy CoreCLR * Clone CoreCLR: `git clone -b release/1.0.0 https://github.com/dotnet/coreclr.git` * Follow [building instructions](https://github.com/dotnet/coreclr/blob/release/1.0.0/Documentation/building/linux-instructions.md) * Wait for `./build.sh` to finish * Overwrite PowerShell libraries: `cp bin/Product/Linux.x64.Debug/*{so,dll} /path/to/powershell/` -Build and deploy CoreFX ------------------------ +## Build and deploy CoreFX * Clone CoreFX: `git clone -b release/1.0.0 https://github.com/dotnet/corefx.git` * Follow [building instructions](https://github.com/dotnet/corefx/blob/release/1.0.0/Documentation/building/unix-instructions.md) diff --git a/docs/dev-process/breaking-change-contract.md b/docs/dev-process/breaking-change-contract.md index b9124a58fb4..f33f806f7e8 100644 --- a/docs/dev-process/breaking-change-contract.md +++ b/docs/dev-process/breaking-change-contract.md @@ -4,29 +4,33 @@ We have a serious commitment to backwards compatibility with all earlier version Below is a summary of our approach to handing breaking changes including what kinds of things constitute breaking changes, how we categorize them, and how we decide what we're willing to take. -Note that these rules only apply to existing stable features that have shipped in a supported release. New features marked as “in preview” that are still under development may be modified from one preview release to the next. These are not considered breaking changes. +Note that these rules only apply to existing stable features that have shipped in a supported release. New features marked as “in preview” that are still under development may be modified from one preview release to the next. +These are **not** considered breaking changes. To help triage breaking changes, we classify them in to four buckets: 1. Public Contract -2. Reasonable Grey Area -3. Unlikely Grey Area -4. Clearly Non-Public +1. Reasonable Grey Area +1. Unlikely Grey Area +1. Clearly Non-Public ## Bucket 1: Public Contract Any change that is a clear violation of the public contract. -### Unacceptable changes: +### Unacceptable changes + A code change that results in a change to the existing behavior observed for a given input with an API, protocol or the PowerShell language. -+ Renaming or removing a public type, type member, or type parameter; renaming or removing a cmdlet or cmdlet parameter (note: it is possible to rename a cmdlet parameter if a parameter alias is added. This is an acceptable solution for PowerShell scripts but may break .NET code that depends on the name of the original member on the cmdlet object type.) ++ Renaming or removing a public type, type member, or type parameter; renaming or removing a cmdlet or cmdlet parameter (note: it is possible to rename a cmdlet parameter if a parameter alias is added. + +This is an acceptable solution for PowerShell scripts but may break .NET code that depends on the name of the original member on the cmdlet object type.) + + Decreasing the range of accepted values within a given parameter. + Changing the value of a public constant or enum member; changing the type of a cmdlet parameter to a more restrictive type. + Example: A cmdlet with a parameter -p1 that was previously type as [object] cannot be changed to be or a more restrictive type such as [int]. + Making an incompatible change to any protocol without increasing the protocol version number. -### Acceptable changes: +### Acceptable changes + Any existing behavior that results in an error message generally may be changed to provide new functionality. + A new instance field is added to a type (this impacts .NET serialization but not PowerShell serialization and so is considered acceptable.) @@ -44,7 +48,8 @@ Examples: + Change in parsing of input and throwing new errors (even if parsing behavior is not specified in the docs) + Example: a script may be using a JSON parser that is forgiving to minor syntactic errors in the JSON text. Changing that parser to be more rigorous in its processing would result in errors being thrown when no error was generated in the past thus breaking scripts. -Judiciously making changes in these type of features require judgement: how predictable, obvious, consistent was the behavior? In general, a significant external preview of the change would need to be done also possibly requiring an RFC to be created to allow for community input on the proposal. +Judiciously making changes in these type of features require judgement: how predictable, obvious, consistent was the behavior? +In general, a significant external preview of the change would need to be done also possibly requiring an RFC to be created to allow for community input on the proposal. ## Bucket 3: Unlikely Grey Area @@ -68,9 +73,10 @@ Examples: + Changes to internal APIs that break private reflection -It is impossible to evolve a code base without making such changes, so we don't require up-front approval for these, but we will sometimes have to go back and revisit such change if there's too much pain inflicted on the ecosystem through a popular app or library. +It is impossible to evolve a code base without making such changes, so we don't require up-front approval for these, but we will sometimes have to go back and +revisit such change if there's too much pain inflicted on the ecosystem through a popular app or library. -# What This Means for Contributors +## What This Means for Contributors + All bucket 1, 2, and 3 breaking changes require contacting team at @powershell/powershell. + If you're not sure into which bucket a given change falls, contact us as well. @@ -78,4 +84,3 @@ It is impossible to evolve a code base without making such changes, so we don't + If a change is deemed too breaking, we can help identify alternatives such as introducing a new API or cmdlet and obsoleting the old one. Request for clarifications or suggested alterations to this document should be done by opening issues against this document. - diff --git a/docs/dev-process/coding-guidelines.md b/docs/dev-process/coding-guidelines.md index 48b1a778609..3472296251b 100644 --- a/docs/dev-process/coding-guidelines.md +++ b/docs/dev-process/coding-guidelines.md @@ -155,7 +155,7 @@ such as `password`, `crypto`, `encryption`, `decryption`, `certificate`, `authen When facing a PR with such changes, the reviewers should request a designated security Subject Matter Expert (SME) to review the PR. -Currently, @PaulHigin and @TravisEz13 are our security SMEs. +Currently, [@PaulHigin](https://github.com/PaulHigin) and [@TravisEz13](https://github.com/TravisEz13) are our security SMEs. See [CODEOWNERS](../../.github/CODEOWNERS) for more information about the area experts. ## Best Practices @@ -165,7 +165,7 @@ See [CODEOWNERS](../../.github/CODEOWNERS) for more information about the area e * Avoid a method that is too long and complex. In such case, separate it to multiple methods or even a nested class as you see fit. -* Use `using` statement instead of `try/finally` if the only code in the `finally` block is to call the `Dispose` method. +* Use the `using` statement instead of `try/finally` if the only code in the `finally` block is to call the `Dispose` method. * Use of object initializers (e.g. `new Example { Name = "Name", ID = 1 }`) is encouraged for better readability, but not required. diff --git a/docs/dev-process/resx-files.md b/docs/dev-process/resx-files.md index 61bcfa4277d..ec9eace54fe 100644 --- a/docs/dev-process/resx-files.md +++ b/docs/dev-process/resx-files.md @@ -9,33 +9,32 @@ We are using our own `Start-ResGen` to generate them. Usually it's called as part of the regular build with -``` -PS C:\> Start-PSBuild -ResGen +```powershell +Start-PSBuild -ResGen ``` If you see compilation errors related to resources, try to call `Start-ResGen` explicitly. -``` -PS C:\> Start-ResGen +```powershell +Start-ResGen ``` ## Editing `.resx` files -**Don't edit** `.resx` files from Visual Studio. +**Don't edit** `.resx` files from Visual Studio. It will try to create `.cs` files for you and you will get whole bunch of hard-to-understand errors. -To edit a resource file, use any **plain text editor**. +To edit a resource file, use any **plain text editor**. A resource file is a simple XML file, and it's easy to edit. - ## Convert `.txt` resource files into `.resx` files `dotnet cli` doesn't support embedding old-fashioned `.txt` resource. You can do a one-time conversion of `.txt` resources into `.resx` files with a helper function: -``` +```powershell # example, converting all .txt resources under src\Microsoft.WSMan.Management\resources -PS C:\> Convert-TxtResourceToXml -Path src\Microsoft.WSMan.Management\resources +Convert-TxtResourceToXml -Path src\Microsoft.WSMan.Management\resources ``` `.resx` files would be placed next to `.txt` files. diff --git a/docs/git/README.md b/docs/git/README.md index 0f2a7f0ad94..817e4930f6c 100644 --- a/docs/git/README.md +++ b/docs/git/README.md @@ -1,14 +1,12 @@ -Working with PowerShell repository -================================== +# Working with PowerShell repository -#### Get the code for the first time +## Get the code for the first time ```sh -git clone https://github.com/PowerShell/PowerShell.git +git clone https://github.com/PowerShell/PowerShell.git --branch=master ``` -Branches ---------- +## Branches * Don't commit your changes directly to master. It will make the collaborative workflow messy. @@ -19,13 +17,13 @@ Branches You must never EVER destroy other peoples history. You must not rebase commits other people did. Basically, if it doesn't have your sign-off on it, it's off limits: you can't rebase it, because it's not yours." -#### Understand branches +### Understand branches * **master** is the branch with the latest and greatest changes. It could be unstable. * Send your pull requests to **master**. -#### Sync your local repo +### Sync your local repo Use **git rebase** instead of **git merge** and **git pull**, when you're updating your feature-branch. @@ -39,7 +37,7 @@ git fetch --all -p git rebase origin/master ``` -#### More complex scenarios +### More complex scenarios Covering all possible git scenarios is behind the scope of the current document. Git has excellent documentation and lots of materials available online. @@ -50,14 +48,12 @@ We are leaving few links here: [Linus]:https://wincent.com/wiki/git_rebase%3A_you're_doing_it_wrong - -Tags ------- +## Tags If you are looking for the source code for a particular release, you will find it via **tags**. -* `git tag` will show you list of all tags. +* `git tag` will show you list of all tags. * Find the tag that corresponds to the release. * Use `git checkout ` to get this version. @@ -73,31 +69,33 @@ checkout a new branch from this DETACHED HEAD state. git checkout -b vors/hotfix ``` - -Recommended Git configurations -============================== +## Recommended Git configurations We highly recommend these configurations to help deal with whitespace, rebasing, and general use of Git. > Auto-corrects your command when it's sure (`stats` to `status`) + ```sh git config --global help.autoCorrect -1 ``` > Refuses to merge when pulling, and only pushes to branch with same name. + ```sh git config --global pull.ff only git config --global push.default current ``` > Shows shorter commit hashes and always shows reference names in the log. + ```sh git config --global log.abbrevCommit true git config --global log.decorate short ``` > Ignores whitespace changes and uses more information when merging. + ```sh git config --global apply.ignoreWhitespace change git config --global rerere.enabled true diff --git a/docs/git/basics.md b/docs/git/basics.md index 79a92f742c2..a8a9bacf046 100644 --- a/docs/git/basics.md +++ b/docs/git/basics.md @@ -1,14 +1,12 @@ -Getting started with Git -======================== +# Getting started with Git We are using Git version 2.9.0, but any recent version should be good. It's recommended to learn the `git` command-line tool for full cross-platform experience and a deeper understanding of Git itself. -Install ---------- +## Install -#### Windows +### Windows Install [Git for Windows][]. @@ -22,13 +20,12 @@ During the installation process, choose these recommended settings: [Git for Windows]: https://git-scm.com/download/win -#### Linux +### Linux Install by using the package manager on your system. A list of all the package managers and commands can be found [here][linux-git-dl]. -Interactive tutorials ----------------------- +### Interactive tutorials There are (too) many Git tutorials on the internet. Here we post references to our favorites. @@ -55,11 +52,10 @@ learn Git in couple hours. After finishing 50+ real-world scenarios you will have a pretty good idea about what and when you can do with Git. +## Authentication -Authentication --------------- +### Windows -#### Windows On Windows, the best way to use Git securely is [Git Credential Manager for Windows][manager]. It's included in the official Git installer for Windows. @@ -76,11 +72,10 @@ git config --global credential.helper store Alternatively, you can use [SSH key][]. In this case, you may want to use git-ssh even for HTTPS Git URLs. -``` +```none git config --global url.git@github.com:.insteadOf https://github.com/ ``` - [SSH key]: https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#generating-a-new-ssh-key [token]: https://help.github.com/articles/creating-an-access-token-for-command-line-use/ [manager]: https://github.com/Microsoft/Git-Credential-Manager-for-Windows diff --git a/docs/learning-powershell/README.md b/docs/learning-powershell/README.md index 4573139e337..0be3ab2e804 100644 --- a/docs/learning-powershell/README.md +++ b/docs/learning-powershell/README.md @@ -1,5 +1,4 @@ -Learning PowerShell -==== +# Learning PowerShell Whether you're a Developer, a DevOps or an IT Professional, this doc will help you getting started with PowerShell. In this document we'll cover the following: @@ -10,18 +9,16 @@ You won't be a PowerShell guru at the end of reading this material but you will If you have 30 minutes now, let’s try it. - -Installing PowerShell ----- +## Installing PowerShell First you need to set up your computer working environment if you have not done so. Choose the platform below and follow the instructions. At the end of this exercise, you should be able to launch the PowerShell session. - Get PowerShell by installing package - * [PowerShell on Linux][inst-linux] - * [PowerShell on macOS][inst-macos] - * [PowerShell on Windows][inst-win] + * [PowerShell on Linux][inst-linux] + * [PowerShell on macOS][inst-macos] + * [PowerShell on Windows][inst-win] For this tutorial, you do not need to install PowerShell if you are running on Windows. You can launch PowerShell console by pressing Windows key, typing PowerShell, and clicking on Windows PowerShell. @@ -33,8 +30,8 @@ At the end of this exercise, you should be able to launch the PowerShell session [inst-win]: https://docs.microsoft.com/powershell/scripting/setup/installing-powershell-core-on-windows?view=powershell-6 [inst-macos]: https://docs.microsoft.com/powershell/scripting/setup/installing-powershell-core-on-macos?view=powershell-6 -Getting Started with PowerShell ----- +## Getting Started with PowerShell + PowerShell commands follow a Verb-Noun semantic with a set of parameters. It's easy to learn and use PowerShell. For example, `Get-Process` will display all the running processes on your system. @@ -43,8 +40,7 @@ Let's walk through with a few examples from the [PowerShell Beginner's Guide](po Now you have learned the basics of PowerShell. Please continue reading if you want to do some development work in PowerShell. -PowerShell Editor ----- +### PowerShell Editor In this section, you will create a PowerShell script using a text editor. You can use your favorite editor to write scripts. @@ -53,8 +49,7 @@ Click on the following link to create your first PowerShell script. - [Using Visual Studio Code (VS Code)](https://docs.microsoft.com/powershell/scripting/components/vscode/using-vscode?view=powershell-6) -PowerShell Debugger ----- +### PowerShell Debugger Debugging can help you find bugs and fix problems in your PowerShell scripts. Click on the link below to learn more about debugging: @@ -67,21 +62,16 @@ Click on the link below to learn more about debugging: [get-powershell]:../../README.md#get-powershell [build-powershell]:../../README.md#building-the-repository - -PowerShell Testing ----- +### PowerShell Testing We recommend using Pester testing tool which is initiated by the PowerShell Community for writing test cases. -To use the tool please read [ Pester Guides](https://github.com/pester/Pester) and [Writing Pester Tests Guidelines](https://github.com/PowerShell/PowerShell/blob/master/docs/testing-guidelines/WritingPesterTests.md). +To use the tool please read [Pester Guides](https://github.com/pester/Pester) and [Writing Pester Tests Guidelines](https://github.com/PowerShell/PowerShell/blob/master/docs/testing-guidelines/WritingPesterTests.md). - -Map Book for Experienced Bash users ----- +### Map Book for Experienced Bash users The table below lists the usage of some basic commands to help you get started on PowerShell faster. Note that all bash commands should continue working on PowerShell session. - | Bash | PowerShell | Description |:--------------------------------|:----------------------------------------|:--------------------- | ls | dir, Get-ChildItem | List files and folders @@ -101,8 +91,8 @@ Note that all bash commands should continue working on PowerShell session. | grep -Rin "sometext" --include="*.cs" |Get-ChildItem -Recurse -Filter *.cs
\| Select-String -Pattern "sometext" | Recursively case-insensitive search for text in files | curl https://github.com | Invoke-RestMethod https://github.com | Transfer data to or from the web -Recommended Training and Reading ----- +### Recommended Training and Reading + - Microsoft Virtual Academy: [Getting Started with PowerShell][getstarted-with-powershell] - [Why Learn PowerShell][why-learn-powershell] by Ed Wilson - PowerShell Web Docs: [Basic cookbooks][basic-cookbooks] @@ -113,10 +103,9 @@ Recommended Training and Reading - [PowerShell 5 How-To Videos][script-guy-how-to] by Ed Wilson - [PowerShell Documentation](https://docs.microsoft.com/powershell) +### Commercial Resources -Commercial Resources ----- -- [Windows PowerShell in Action][in-action] by Bruce Payette +- [Windows PowerShell in Action][in-action] by [Bruce Payette](https://github.com/brucepay) - [Introduction to PowerShell][powershell-intro] from Pluralsight - [PowerShell Training and Tutorials][lynda-training] from Lynda.com - [Learn Windows PowerShell in a Month of Lunches][learn-powershell] by Don Jones and Jeffrey Hicks diff --git a/docs/learning-powershell/create-powershell-scripts.md b/docs/learning-powershell/create-powershell-scripts.md index 0403dd70209..dced379cb9d 100644 --- a/docs/learning-powershell/create-powershell-scripts.md +++ b/docs/learning-powershell/create-powershell-scripts.md @@ -1,14 +1,14 @@ -How to Create and Run PowerShell Scripts -==== +# How to Create and Run PowerShell Scripts You can combine a series of commands in a text file and save it with the file extension '.ps1', and the file will become a PowerShell script. This would begin by opening your favorite text editor and pasting in the following example. -``` PowerShell +```powershell # Script to return current IPv4 addresses on a Linux or MacOS host $ipInfo = ifconfig | Select-String 'inet' $ipInfo = [regex]::matches($ipInfo,"addr:\b(?:\d{1,3}\.){3}\d{1,3}\b") | ForEach-Object value -foreach ($ip in $ipInfo) { +foreach ($ip in $ipInfo) +{ $ip.Replace('addr:','') } ``` @@ -16,46 +16,50 @@ foreach ($ip in $ipInfo) { Then save the file to something memorable, such as .\NetIP.ps1. In the future when you need to get the IP addresses for the node, you can simplify this task by executing the script. -``` PowerShell -PS> .\NetIP.ps1 +```powershell +.\NetIP.ps1 10.0.0.1 127.0.0.1 ``` + You can accomplish this same task on Windows. -```PowerShell +```powershell # One line script to return current IPv4 addresses on a Windows host Get-NetIPAddress | Where-Object {$_.AddressFamily -eq 'IPv4'} | ForEach-Object IPAddress ``` + As before, save the file as .\NetIP.ps1 and execute within a PowerShell environment. Note: If you are using Windows, make sure you set the PowerShell's execution policy to "RemoteSigned" in this case. See [Running PowerShell Scripts Is as Easy as 1-2-3][run-ps] for more details. -```PowerShell -PS C:\> NetIP.ps1 +```powershell +NetIP.ps1 127.0.0.1 10.0.0.1 ``` -Creating a script that can accomplish the same task on multiple operating systems ----- +## Creating a script that can accomplish the same task on multiple operating systems If you would like to author one script that will return the IP address across Linux, MacOS, or Windows, you could accomplish this using an IF statement. -```PowerShell +```powershell # Script to return current IPv4 addresses for Linux, MacOS, or Windows -$IP = if ($IsLinux -or $IsMacOS) { +$IP = if ($IsLinux -or $IsMacOS) +{ $ipInfo = ifconfig | Select-String 'inet' $ipInfo = [regex]::matches($ipInfo,"addr:\b(?:\d{1,3}\.){3}\d{1,3}\b") | ForEach-Object value foreach ($ip in $ipInfo) { $ip.Replace('addr:','') } } -else { +else +{ Get-NetIPAddress | Where-Object {$_.AddressFamily -eq 'IPv4'} | ForEach-Object IPAddress } # Remove loopback address from output regardless of platform $IP | Where-Object {$_ -ne '127.0.0.1'} ``` + [run-ps]:https://windowsitpro.com/powershell/running-powershell-scripts-easy-1-2-3 diff --git a/docs/learning-powershell/debugging-from-commandline.md b/docs/learning-powershell/debugging-from-commandline.md index 53dca76540d..f6a247ab967 100644 --- a/docs/learning-powershell/debugging-from-commandline.md +++ b/docs/learning-powershell/debugging-from-commandline.md @@ -1,11 +1,12 @@ -Debugging in PowerShell Command-line -===== +# Debugging in PowerShell Command-line -As we know, we can debug PowerShell code via GUI tools like [Visual Studio Code](https://docs.microsoft.com/en-us/powershell/scripting/components/vscode/using-vscode?view=powershell-6#debugging-with-visual-studio-code). In addition, we can directly perform debugging within the PowerShell command-line session by using the PowerShell debugger cmdlets. This document demonstrates how to use the cmdlets for the PowerShell command-line debugging. We will cover the following topics: setting a debug breakpoint on a line of code and on a variable. +As we know, we can debug PowerShell code via GUI tools like [Visual Studio Code](https://docs.microsoft.com/en-us/powershell/scripting/components/vscode/using-vscode?view=powershell-6#debugging-with-visual-studio-code). In addition, we can +directly perform debugging within the PowerShell command-line session by using the PowerShell debugger cmdlets. This document demonstrates how to use the cmdlets for the PowerShell command-line debugging. We will cover the following topics: +setting a debug breakpoint on a line of code and on a variable. Let's use the following code snippet as our sample script. -```PowerShell +```powershell # Convert Fahrenheit to Celsius function ConvertFahrenheitToCelsius([double] $fahrenheit) { @@ -17,32 +18,32 @@ $celsius $fahrenheit = Read-Host 'Input a temperature in Fahrenheit' $result =[int](ConvertFahrenheitToCelsius($fahrenheit)) Write-Host "$result Celsius" - ``` - - **1. Setting a Breakpoint on a Line** + 1. **Setting a Breakpoint on a Line** - Open a [PowerShell editor](README.md#powershell-editor) - Save the above code snippet to a file. For example, "test.ps1" - Go to your command-line PowerShell - Clear existing breakpoints if any -```PowerShell +```powershell PS /home/jen/debug>Get-PSBreakpoint | Remove-PSBreakpoint - ``` +``` + - Use **Set-PSBreakpoint** cmdlet to set a debug breakpoint. In this case, we will set it to line 5 -```PowerShell +```powershell PS /home/jen/debug>Set-PSBreakpoint -Line 5 -Script ./test.ps1 ID Script Line Command Variable Action -- ------ ---- ------- -------- ------ 0 test.ps1 5 ``` + - Run the script "test.ps1". As we have set a breakpoint, it is expected the program will break into the debugger at the line 5. -```PowerShell +```powershell PS /home/jen/debug> ./test.ps1 Input a temperature in Fahrenheit: 80 @@ -102,16 +103,16 @@ PS /home/jen/debug> ``` - -**2. Setting a Breakpoint on a Variable** +1. **Setting a Breakpoint on a Variable** - Clear existing breakpoints if there are any -```PowerShell +```powershell PS /home/jen/debug>Get-PSBreakpoint | Remove-PSBreakpoint ``` + - Use **Set-PSBreakpoint** cmdlet to set a debug breakpoint. In this case, we set it to line 5 -```PowerShell +```powershell PS /home/jen/debug>Set-PSBreakpoint -Variable "celsius" -Mode write -Script ./test.ps1 @@ -122,9 +123,8 @@ PS /home/jen/debug> Once hit the debug breakpoint, we can type **l** to list the source code that debugger is currently executing. As we can see line 3 has an asterisk at the front, meaning that's the line the program is currently executing and broke into the debugger as illustrated below. - Type **q** to exit from the debugging mode. The following is an example of debugging output. -```PowerShell - -PS /home/jen/debug> ./test.ps1 +```powershell +./test.ps1 Input a temperature in Fahrenheit: 80 Hit Variable breakpoint on '/home/jen/debug/test.ps1:$celsius' (Write access) @@ -167,8 +167,7 @@ PS /home/jen/debug> Now you know the basics of the PowerShell debugging from PowerShell command-line. For further learning, read the following articles. +## More Reading -More Reading -===== - [about_Debuggers](https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_debuggers?view=powershell-6) - [PowerShell Debugging](https://blogs.technet.microsoft.com/heyscriptingguy/tag/debugging/) diff --git a/docs/learning-powershell/powershell-beginners-guide.md b/docs/learning-powershell/powershell-beginners-guide.md index 971f692b87a..8564dc0822a 100644 --- a/docs/learning-powershell/powershell-beginners-guide.md +++ b/docs/learning-powershell/powershell-beginners-guide.md @@ -66,20 +66,21 @@ Handles NPM(K) PM(K) WS(K) CPU(s) Id ProcessName ``` -2. `Clear-Host`: Clears the display in the host program. +1. `Clear-Host`: Clears the display in the host program. ```powershell PS /> Get-Process PS /> Clear-Host ``` + Type too much just for clearing the screen? Here is how the alias can help. -3. `Get-Alias`: Gets the aliases for the current session. +1. `Get-Alias`: Gets the aliases for the current session. ```powershell -PS /> Get-Alias +Get-Alias CommandType Name ----------- ---- @@ -100,19 +101,20 @@ Alias type -> Get-Content As you can see `cls` or `clear` is an alias of `Clear-Host`. Now try it: + ```powershell PS /> Get-Process PS /> cls ``` -4. `cd -> Set-Location`: Sets the current working location to a specified location. +1. `cd -> Set-Location`: Sets the current working location to a specified location. ```powershell PS /> Set-Location /home PS /home> ``` -5. `dir -> Get-ChildItem`: Gets the items and child items in one or more specified locations. +1. `dir -> Get-ChildItem`: Gets the items and child items in one or more specified locations. ```powershell # Get all files under the current directory: @@ -181,7 +183,7 @@ Or simply use `>` as below: The pound sign `#` above is used for comments in PowerShell. -7. `type -> Get-Content`: Gets the content of the item at the specified location. +1. `type -> Get-Content`: Gets the content of the item at the specified location. ```powershell PS /home/jen> Get-Content -Path ./test.txt @@ -190,7 +192,7 @@ PS /home/jen> type -Path ./test.txt Hello world again! ``` -8. `del -> Remove-Item`: Deletes the specified items. +1. `del -> Remove-Item`: Deletes the specified items. This cmdlet will delete the file `/home/jen/test.txt`: @@ -198,7 +200,7 @@ This cmdlet will delete the file `/home/jen/test.txt`: PS /home/jen> Remove-Item ./test.txt ``` -9. `$PSVersionTable`: Displays the version of PowerShell you are currently using. +1. `$PSVersionTable`: Displays the version of PowerShell you are currently using. Type `$PSVersionTable` in your PowerShell session, you will see something like below. "PSVersion" indicates the PowerShell version that you are using. @@ -218,10 +220,10 @@ SerializationVersion 1.1.0.1 ``` -10. `Exit`: To exit the PowerShell session, type `exit`. +1. `Exit`: To exit the PowerShell session, type `exit`. ```powershell -PS /home/jen> exit +exit ``` ## Need Help? @@ -329,7 +331,7 @@ For more details, see [Create and Run PowerShell Script Guide][create-run-script [tutorial]: https://www.computerperformance.co.uk/powershell/index.htm [to-learn]:https://blogs.technet.microsoft.com/heyscriptingguy/2015/01/04/weekend-scripter-the-best-ways-to-learn-powershell/ [ps-module]:https://msdn.microsoft.com/library/dd878324%28v=vs.85%29.aspx -[create-ps-module]:http://www.tomsitpro.com/articles/powershell-modules,2-846.html +[create-ps-module]:https://www.business.com/articles/powershell-modules/ [remoting]:https://channel9.msdn.com/Series/GetStartedPowerShell3/06 [in-depth]: https://channel9.msdn.com/events/MMS/2012/SV-B406 [remote-mgmt]:https://windowsitpro.com/powershell/powershell-basics-remote-management diff --git a/docs/learning-powershell/working-with-powershell-objects.md b/docs/learning-powershell/working-with-powershell-objects.md index adbdc3eeef6..ab127483cfe 100644 --- a/docs/learning-powershell/working-with-powershell-objects.md +++ b/docs/learning-powershell/working-with-powershell-objects.md @@ -1,5 +1,5 @@ -Working with PowerShell Objects -==== +# Working with PowerShell Objects + When cmdlets are executed in PowerShell, the output is an Object, as opposed to only returning text. This provides the ability to store information as properties. As a result, handling large amounts of data and getting only specific properties is a trivial task. @@ -7,8 +7,9 @@ As a result, handling large amounts of data and getting only specific properties As a simple example, the following function retrieves information about storage Devices on a Linux or MacOS operating system platform. This is accomplished by parsing the output of an existing command, *parted -l* in administrative context, and creating an object from the raw text by using the *New-Object* cmdlet. -```PowerShell -Function Get-DiskInfo { +```powershell +function Get-DiskInfo +{ $disks = sudo parted -l | Select-String "Disk /dev/sd*" -Context 1,0 $diskinfo = @() foreach ($disk in $disks) { @@ -27,7 +28,7 @@ The results are formatted as a table with the default view. *Note: in this example, the disks are virtual disks in a Microsoft Azure virtual machine.* -```PowerShell +```powershell PS /home/psuser> $d = Get-DiskInfo [sudo] password for psuser: PS /home/psuser> $d @@ -44,7 +45,7 @@ This is because the value of *$d* is not just text output. The value is actually an array of .Net objects with methods and properties. The properties include Device, Friendly Name, and Total Size. -```PowerShell +```powershell PS /home/psuser> $d | Get-Member @@ -63,7 +64,7 @@ Total Size NoteProperty string Total Size= 31.5GB To confirm, we can call the GetType() method interactively from the console. -```PowerShell +```powershell PS /home/psuser> $d.GetType() IsPublic IsSerial Name BaseType @@ -73,7 +74,7 @@ True True Object[] System.Array To index in to the array and return only specific objects, use the square brackets. -```PowerShell +```powershell PS /home/psuser> $d[0] Friendly Name Total Size Device @@ -89,7 +90,7 @@ True False PSCustomObject System.Object To return a specific property, the property name can be called interactively from the console. -```PowerShell +```powershell PS /home/psuser> $d.Device /dev/sda /dev/sdb @@ -97,7 +98,7 @@ PS /home/psuser> $d.Device To output a view of the information other than default, such as a view with only specific properties selected, pass the value to the *Select-Object* cmdlet. -```PowerShell +```powershell PS /home/psuser> $d | Select-Object Device, 'Total Size' Device Total Size @@ -107,10 +108,10 @@ Device Total Size ``` Finally, the example below demonstrates use of the *ForEach-Object* cmdlet to iterate through the array and manipulate the value of a specific property of each object. -In this case the Total Size property, which was given in Gigabytes, is changed to Megabytes. +In this case the Total Size property, which was given in Gigabytes, is changed to Megabytes. Alternatively, index in to a position in the array as shown below in the third example. -```PowerShell +```powershell PS /home/psuser> $d | ForEach-Object 'Total Size' 31.5GB 145GB @@ -121,4 +122,4 @@ PS /home/psuser> $d | ForEach-Object {$_.'Total Size' / 1MB} PS /home/psuser> $d[1].'Total Size' / 1MB 148480 -``` \ No newline at end of file +``` diff --git a/docs/maintainers/README.md b/docs/maintainers/README.md index d9795795fbe..b5d3bc2f255 100644 --- a/docs/maintainers/README.md +++ b/docs/maintainers/README.md @@ -6,8 +6,8 @@ One of their primary responsibilities is merging pull requests after all require They have [write access](https://help.github.com/articles/repository-permission-levels-for-an-organization/) to the PowerShell repositories which gives them the power to: 1. `git push` to the official PowerShell repository -1. Merge pull requests -1. Assign labels, milestones, and people to [issues](https://guides.github.com/features/issues/) +1. Merge [pull requests](https://www.thinkful.com/learn/github-pull-request-tutorial/) +1. Assign labels, milestones, and people to [issues](https://guides.github.com/features/issues/) and [pull requests](https://www.thinkful.com/learn/github-pull-request-tutorial/) ## Table of Contents @@ -20,18 +20,22 @@ They have [write access](https://help.github.com/articles/repository-permission- ## Current Repository Maintainers -- Dongbo Wang ([daxian-dbw](https://github.com/daxian-dbw)) -- Travis Plunk ([TravisEz13](https://github.com/TravisEz13)) + + - Aditya Patwardhan ([adityapatwardhan](https://github.com/adityapatwardhan)) -- Ilya Sazonov ([iSazonov](https://github.com/iSazonov)) - Andrew Menagarishvili ([anmenaga](https://github.com/anmenaga)) +- Dongbo Wang ([daxian-dbw](https://github.com/daxian-dbw)) +- Ilya Sazonov ([iSazonov](https://github.com/iSazonov)) +- Travis Plunk ([TravisEz13](https://github.com/TravisEz13)) ## Former Repository Maintainers + + +- Andy Schwartzmeyer ([andschwa](https://github.com/andschwa)) - Jason Shirk ([lzybkr](https://github.com/lzybkr)) -- Sergei Vorobev ([vors](https://github.com/vors)) - Mike Richmond ([mirichmo](https://github.com/mirichmo)) -- Andy Schwartzmeyer ([andschwa](https://github.com/andschwa)) +- Sergei Vorobev ([vors](https://github.com/vors)) ## Repository Maintainer Responsibilities @@ -39,7 +43,7 @@ Repository Maintainers enable rapid contributions while maintaining a high level If you are a Repository Maintainer, you: -1. **MUST** ensure that each contributor has signed a valid Contributor License Agreement (CLA) +1. **MUST** ensure that each contributor has signed a valid Microsoft Contributor License Agreement (CLA) 1. **MUST** verify compliance with any third party code license terms (e.g., requiring attribution, etc.) if the contribution contains third party code. 1. **MUST** make sure that [any change requiring approval from the PowerShell Committee](../community/governance.md#changes-that-require-an-rfc) has gone through the proper [RFC][RFC-repo] or approval process 1. **MUST** validate that code reviews have been conducted before merging a pull request when no code is written diff --git a/docs/maintainers/best-practice.md b/docs/maintainers/best-practice.md index 08be16fa42a..47cc304cf61 100644 --- a/docs/maintainers/best-practice.md +++ b/docs/maintainers/best-practice.md @@ -8,7 +8,7 @@ ## Review PRs - Ask the author to reword the PR title based on guidelines in [Contributing](../../.github/CONTRIBUTING.md). -- Ask the author to apply `[Feature]` tag to trigger full test builds if it's necessary. +- Ask the author to apply `[feature]` tag to trigger full test builds if it's necessary. - Label the PR with `Breaking-Change`, `Documentation Needed` and `Area-XXX` as appropriate. - When labelling a PR with `Review-Committee`, leave a detailed comment to summarize the issue you want the committee to look into. It's recommended to include examples to explain/demonstrate behaviors. @@ -21,7 +21,7 @@ - Use `Create a merge commit` for feature-work PRs **only if** the commit history of the PR is reasonably clean. After using this option, GitHub will make it your default option for merging a PR. - Do remember to change the default back to `Squash and merge`. + Do remember to change the default back to `Squash and merge` as it will be useful next time. ![Merge Commit Example](./Images/merge-commit.png)    ![Merge Confirm Example](./Images/merge-commit-confirm.png) diff --git a/docs/maintainers/issue-management.md b/docs/maintainers/issue-management.md index 7b416d6359f..1779a3a95b5 100644 --- a/docs/maintainers/issue-management.md +++ b/docs/maintainers/issue-management.md @@ -4,7 +4,7 @@ If you believe that there is a security vulnerability in PowerShell Core, it **must** be reported to [secure@microsoft.com](https://technet.microsoft.com/security/ff852094.aspx) to allow for [Coordinated Vulnerability Disclosure](https://technet.microsoft.com/security/dn467923). -**Only** file an issue, if secure@microsoft.com has confirmed filing an issue is appropriate. +**Only** file an issue, if [secure@microsoft.com](https://www.microsoft.com/en-us/msrc/faqs-report-an-issue?rtc=1) has confirmed filing an issue is appropriate. ## Long-living issue labels @@ -53,15 +53,15 @@ These labels describe what feature area of PowerShell that an issue affects: * `Area-HelpSystem`: anything related to the help infrastructure and formatting of help * `Area-Intellisense`: tab completion * `Area-Language`: parser, language semantics -* `Area-OMI`: omi +* `Area-OMI`: OMI * `Area-PackageManagement`: PackageManagement related issues * `Area-Performance`: a performance issue * `Area-Portability`: anything affecting script portability * `Area-PowerShellGet`: PowerShellGet related issues -* `Area-Providers`: PowerShell providers like FileSystem, Certificates, Registry, etc... +* `Area-Providers`: PowerShell providers such as FileSystem, Certificates, Registry, etc... * `Area-PSReadline`: PSReadline related issues * `Area-Remoting`: PSRP issues with any transport layer -* `Area-Security`: security related areas like [JEA](https://github.com/powershell/JEA) +* `Area-Security`: security related areas such as [JEA](https://github.com/powershell/JEA) * `Area-SideBySide`: side by side support * `Area-Test`: issues in a test or in test infrastructure @@ -80,7 +80,7 @@ The following labels are used on PRs: * `Review - Needed` : The PR is being reviewed. Please see [Pull Request - Code Review](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#pull-request---code-review) * `Review - Waiting on Author` : The PR was reviewed by the team and requires changes or comments from the author before being accepted. -* `Review - Abandoned` : The PR was not updated for significant number of days (the exact number could vary over time). +* `Review - Abandoned` : The PR was not updated for a significant number of days (the exact number could vary over time). Maintainers should look into such PRs and re-evaluate them. * `Review - Committee` : The PR/Issue needs a review from [powershell-committee](../community/governance.md#powershell-committee) diff --git a/docs/testing-guidelines/CodeCoverageAnalysis.md b/docs/testing-guidelines/CodeCoverageAnalysis.md index 1461905b716..bee669ea747 100644 --- a/docs/testing-guidelines/CodeCoverageAnalysis.md +++ b/docs/testing-guidelines/CodeCoverageAnalysis.md @@ -1,7 +1,7 @@ # Code coverage analysis for commit [de5f69c](https://codecov.io/gh/PowerShell/PowerShell/tree/de5f69cf942a85839c907f11a29cf9c09f9de8b4/src) Code coverage runs are enabled on daily Windows builds for PowerShell Core 6. -The results of the latest build are available at: [CodeCov.io](https://codecov.io/gh/PowerShell/PowerShell) +The results of the latest build are available at [codecov.io](https://codecov.io/gh/PowerShell/PowerShell) The goal of this analysis is to find the hot spots of missing coverage. The metrics used for selection of these hot spots were: # missing lines and likelihood of code path usage.