Refactor code to make it easier to maintain and a little faster. Changes are as follows:
1. Support finding a matching signature with variance. But make PowerShell prefer exact match over a match with variance.
2. The metadata signatures in `PSMethod<..>` are generated based on the array of method overloads in `MethodCacheEntry.MethodInformationStructures`, in the exact same order. So in `LanguagePrimitive.ConvertViaParseMethod`, when we try to figure out if there is a match using the metadata signatures in `PSMethod<..>`, we can get the index of the matching signature, and the same index should locate the matching method in `MethodCacheEntry.MethodInformationStructures`. Therefore, we don't need to compare signatures again in the actual conversion method, and instead, we can just leverage the index we found when figuring out the conversion in `ConvertViaParseMethod`.
- This gets rid of the reflection call `GetMethod("Invoke")` and the subsequent signature comparisons in the final conversion method.
- Also, when comparing signatures using `PSMethod<..>` in `ConvertViaParseMethod`, we can just use the generic argument types of each `Func<..>` metadata type, instead of calling `GetMethod("Invoke")` and then `GetParameters()`. This makes the code for comparing signatures simpler (the type `SignatureComparator`).
- Move `MatchesPSMethodProjectedType` from `PSMemberInfo.cs` to the type `SignatureComparator` in `LanguagePrimitives.cs`, as it's closely related to the signature comparison. Also, renamed it to `ProjectedTypeMatchesTargetType`.
- These changes make PSMethod-to-Delegate conversion a little faster, but no big improvement, as the true bottleneck probably is in delegate creation(?). Actually, the performance of this conversion is not critical at all at this moment because this feature should rarely be used in any hot script path. So this exercise is mainly for fun.
3. Remove `PSEnum<T>`. We can directly use enum types when constructing the metadata type `Func<..>`.
4. Remove the code that generates metadata signatures for generic method definitions (call `MakeGenericMethod` with fake types like `GenericType0`, `GenericType1`). This is because:
- We don't support convert generic method to delegate today, so may be better not spending time on preparing the metadata signature types for those methods.
- When the day comes that we need to support it, it's better to use generic argument types directly to construct the `Func<..>` metadata types. I left comments in `GetMethodGroupType` method in `PSMemberInfo.cs` to explain why that approach is better.
PowerShell
Welcome to the PowerShell GitHub Community! PowerShell Core is a cross-platform (Windows, Linux, and macOS) automation and configuration tool/framework that works well with your existing tools and is optimized for dealing with structured data (e.g. JSON, CSV, XML, etc.), REST APIs, and object models. It includes a command-line shell, an associated scripting language and a framework for processing cmdlets.
Windows PowerShell vs PowerShell Core
Although this repo started as a fork of the Windows PowerShell code base, changes made in this repo do not make their way back to Windows PowerShell 5.1 automatically. This also means that issues tracked here are only for PowerShell Core 6.0. Windows PowerShell specific issues should be opened on UserVoice.
New to PowerShell?
If you are new to PowerShell and would like to learn more, we recommend reviewing the getting started documentation.
Get PowerShell
You can download and install a PowerShell package for any of the following platforms.
| Supported Platform | Downloads (stable) | Downloads (preview) | How to Install |
|---|---|---|---|
| Windows (x64) | .msi | .msi | Instructions |
| Windows (x86) | .msi | .msi | Instructions |
| Ubuntu 17.04 | .deb | .deb | Instructions |
| Ubuntu 16.04 | .deb | .deb | Instructions |
| Ubuntu 14.04 | .deb | .deb | Instructions |
| Debian 8.7+ | .deb | .deb | Instructions |
| Debian 9 | .deb | .deb | Instructions |
| CentOS 7 | .rpm | .rpm | Instructions |
| Red Hat Enterprise Linux 7 | .rpm | .rpm | Instructions |
| OpenSUSE 42.2 | .rpm | .rpm | Instructions |
| Fedora 25 | .rpm | .rpm | Instructions |
| Fedora 26 | .rpm | .rpm | Instructions |
| macOS 10.12+ | .pkg | .pkg | Instructions |
| Docker | Instructions |
You can download and install a PowerShell package for any of the following platforms, which are supported by the community.
| Platform | Downloads (stable) | Downloads (preview) | How to Install |
|---|---|---|---|
| Arch Linux | Instructions | ||
| Kali Linux | .deb | .deb | Instructions |
| Many Linux distributions | .AppImage | Instructions |
You can also download the PowerShell binary archives for Windows, macOS and Linux.
| Platform | Downloads (stable) | Downloads (preview) | How to Install |
|---|---|---|---|
| Windows | 32-bit/64-bit | 32-bit/64-bit | Instructions |
| macOS | 64-bit | 64-bit | Instructions |
| Linux | 64-bit | 64-bit | Instructions |
| Windows (arm) Experimental | 32-bit/64-bit | 32-bit/64-bit | Instructions |
| Raspbian (Stretch) Experimental | .tgz | .tgz | Instructions |
To install a specific version, visit releases.
Community Dashboard
Dashboard with visualizations for community contributions and project status using PowerShell, Azure, and PowerBI.
For more information on how and why we built this dashboard, check out this blog post.
Chat Room
Want to chat with other members of the PowerShell community?
We have a Gitter Room which you can join below.
There is also the community driven PowerShell Slack Team which you can sign up for at Slack Sign up.
Add-ons and libraries
Awesome PowerShell is a great curated list of add-ons and resources.
Building the Repository
| Linux | Windows | macOS |
|---|---|---|
| Instructions | Instructions | Instructions |
If you have any problems building, please consult the developer FAQ.
Build status of master branches
| AppVeyor (Windows) | Travis CI (Linux / macOS) |
|---|---|
Build status of nightly builds
| AppVeyor (Windows) | Travis CI (Linux) | Travis CI (macOS) | Code Coverage Status |
|---|---|---|---|
Downloading the Source Code
The PowerShell repository has a number of other repositories embedded as submodules.
To make things easy, you can just clone recursively:
git clone --recursive https://github.com/PowerShell/PowerShell.git
If you already cloned but forgot to use --recursive, you can update submodules manually:
git submodule update --init
See working with the PowerShell repository for more information.
Developing and Contributing
Please see the Contribution Guide for how to develop and contribute.
If you have any problems, please consult the known issues, developer FAQ, and GitHub issues. If you do not see your problem captured, please file a new issue and follow the provided template. If you are developing .NET Core C# applications targeting PowerShell Core, please check out our FAQ to learn more about the PowerShell SDK NuGet package.
Also make sure to check out our PowerShell-RFC repository for request-for-comments (RFC) documents to submit and give comments on proposed and future designs.
Legal and Licensing
PowerShell is licensed under the MIT license.
Windows Docker Files and Images
License: By requesting and using the Container OS Image for Windows containers, you acknowledge, understand, and consent to the Supplemental License Terms available on Docker hub:
Telemetry
By default, PowerShell collects the OS description and the version of PowerShell (equivalent to $PSVersionTable.OS and $PSVersionTable.GitCommitId) using Application Insights.
To opt-out of sending telemetry, create an environment variable called POWERSHELL_TELEMETRY_OPTOUT set to a value of 1 before starting PowerShell from the installed location.
The telemetry we collect fall under the Microsoft Privacy Statement.
Governance
Governance policy for PowerShell project is described here.
Code of Conduct
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.