Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: Extending Output Objects
---
# Extending Output Objects

You can extend the .NET Framework objects that are returned by cmdlets, functions, and scripts by using types files (.ps1xml). Types files are XML-based files that let you add properties and methods to existing objects. For example, Windows PowerShell provides the Types.ps1xml file, which adds elements to several existing .NET Framework objects. The Types.ps1xml file is located in the Windows PowerShell installation directory (`$pshome`). You can create your own types file to further extend those objects or to extend other objects. When you extend an object by using a types file, any instance of the object is extended with the new elements.
You can extend the .NET Framework objects that are returned by cmdlets, functions, and scripts by using types files (.ps1xml). Types files are XML-based files that let you add properties and methods to existing objects. For example, Windows PowerShell provides the Types.ps1xml file, which adds elements to several existing .NET Framework objects. The Types.ps1xml file is located in the Windows PowerShell installation directory (`$PSHOME`). You can create your own types file to further extend those objects or to extend other objects. When you extend an object by using a types file, any instance of the object is extended with the new elements.

## Extending the System.Array Object

Expand Down Expand Up @@ -66,7 +66,7 @@ PS> (1, 2, 3, 4).Length

## Custom Types Files

To create a custom types file, start by copying an existing types file. The new file can have any name, but it must have a .ps1xml file name extension. When you copy the file, you can place the new file in any directory that is accessible to Windows PowerShell, but it is useful to place the files in the Windows PowerShell installation directory (`$pshome`) or in a subdirectory of the installation directory.
To create a custom types file, start by copying an existing types file. The new file can have any name, but it must have a .ps1xml file name extension. When you copy the file, you can place the new file in any directory that is accessible to Windows PowerShell, but it is useful to place the files in the Windows PowerShell installation directory (`$PSHOME`) or in a subdirectory of the installation directory.

To add your own extended types to the file, add a types element for each object that you want to extend. The following topics provide examples.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ title: Windows PowerShell Formatting Files
# Windows PowerShell Formatting Files

Windows PowerShell provides several formatting files (.format.ps1xml) that are located in the
installation directory (`$pshome`). Each of these files defines the default display for a specific
installation directory (`$PSHOME`). Each of these files defines the default display for a specific
set of .NET objects. These files should never be changed. However, you can use them as a reference
for creating your own custom formatting files.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This sample requires Windows PowerShell 2.0.
- Building a console application that uses these host classes to build an interactive Windows
PowerShell shell.

- Creating a `$profile` variable and loading the following profiles.
- Creating a `$PROFILE` variable and loading the following profiles.

- current user, current host
- current user, all hosts
Expand Down Expand Up @@ -145,7 +145,7 @@ namespace Microsoft.Samples.PowerShell.Host
this.myRunSpace.Open();

// Create a PowerShell object that will be used to execute the commands
// to create $profile and load the profiles.
// to create $PROFILE and load the profiles.
lock (this.instanceLock)
{
this.currentPowerShell = PowerShell.Create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ host application also supports calls to remote computers by using the

- Building a console application that uses these host classes to build an interactive Windows PowerShell shell.

- Creating a `$profile` variable and loading the following profiles.
- Creating a `$PROFILE` variable and loading the following profiles.

- current user, current host
- current user, all hosts
Expand Down Expand Up @@ -159,7 +159,7 @@ namespace Microsoft.Samples.PowerShell.Host
this.myRunSpace.Open();

// Create a PowerShell object to run the commands used to create
// $profile and load the profiles.
// $PROFILE and load the profiles.
lock (this.instanceLock)
{
this.currentPowerShell = PowerShell.Create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ the user.
- Building a console application that uses these host classes to build an interactive Windows
PowerShell shell.

- Creating a `$profile` variable and loading the following profiles.
- Creating a `$PROFILE` variable and loading the following profiles.

- current user, current host
- current user, all hosts
Expand Down Expand Up @@ -165,7 +165,7 @@ namespace Microsoft.Samples.PowerShell.Host
this.myRunSpace.Open();

// Create a PowerShell object to run the commands used to create
// $profile and load the profiles.
// $PROFILE and load the profiles.
lock (this.instanceLock)
{
this.currentPowerShell = PowerShell.Create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ The following table describes the elements you can include in a module manifest.
| **Copyright**<br /> Type: `String` | `'(c) <Author>. All rights reserved.'` | Copyright statement for this module. If a value isn't specified, `New-ModuleManifest` uses the default with the current user as the `<Author>`. To specify an author, use the **Author** parameter. <br /> Example: `Copyright = '2019 AuthorName. All rights reserved.'` |
| **Description**<br /> Type: `String` | `<empty string>` | Description of the functionality provided by this module.<br /> Example: `Description = 'This is the module's description.'` |
| **PowerShellVersion**<br /> Type: `Version` | `<empty string>` | Minimum version of the PowerShell engine required by this module. Valid values are 1.0, 2.0, 3.0, 4.0, 5.0, 5.1, 6.0, 6.1, 6.2, 7.0 and 7.1.<br /> Example: `PowerShellVersion = '5.0'` |
| **PowerShellHostName**<br /> Type: `String` | `<empty string>` | Name of the PowerShell host required by this module. This name is provided by PowerShell. To find the name of a host program, in the program, type: `$host.name`.<br /> Example: `PowerShellHostName = 'ConsoleHost'` |
| **PowerShellHostName**<br /> Type: `String` | `<empty string>` | Name of the PowerShell host required by this module. This name is provided by PowerShell. To find the name of a host program, in the program, type: `$Host.name`.<br /> Example: `PowerShellHostName = 'ConsoleHost'` |
| **PowerShellHostVersion**<br /> Type: `Version` | `<empty string>` | Minimum version of the PowerShell host required by this module.<br /> Example: `PowerShellHostVersion = '2.0'` |
| **DotNetFrameworkVersion**<br /> Type: `Version` | `<empty string>` | Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only, such as Windows PowerShell 5.1, and only applies to .NET Framework versions lower than 4.5. <br /> Example: `DotNetFrameworkVersion = '3.5'` |
| **CLRVersion**<br /> Type: `Version` | `<empty string>` | Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only, such as Windows PowerShell 5.1, and only applies to .NET Framework versions lower than 4.5. <br /> Example: `CLRVersion = '3.5'` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ PowerShell modules. Cmdlets rely on the value of this environment variable to fi
By default, the **PSModulePath** environment variable value contains the following system and user
module directories, but you can add to and edit the value.

- `$PSHome\Modules` (`%Windir%\System32\WindowsPowerShell\v1.0\Modules`)
- `$PSHOME\Modules` (`%Windir%\System32\WindowsPowerShell\v1.0\Modules`)

> [!WARNING]
> This location is reserved for modules that ship with Windows. Do not install modules to this
Expand Down
2 changes: 1 addition & 1 deletion reference/docs-conceptual/how-to-use-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ If there are version-specific differences, the documentation makes note of those

![Animation showing how to use the version selector.][04]

You can verify the version of PowerShell you are using by inspecting the `$PSversionTable.PSVersion`
You can verify the version of PowerShell you are using by inspecting the `$PSVersionTable.PSVersion`
value. The following example shows the output for Windows PowerShell 5.1.

```powershell
Expand Down
2 changes: 1 addition & 1 deletion reference/docs-conceptual/lang-spec/chapter-04.md
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ In PowerShell, this type is `System.Management.Automation.PSCustomObject`. The c

### 4.5.14 Command description type

The automatic variable `$PsCmdlet` is an object that represents the cmdlet or function being
The automatic variable `$PSCmdlet` is an object that represents the cmdlet or function being
executed. The type of this object is implementation defined; it has the following accessible
members:

Expand Down
16 changes: 8 additions & 8 deletions reference/docs-conceptual/lang-spec/chapter-07.md
Original file line number Diff line number Diff line change
Expand Up @@ -1698,10 +1698,10 @@ dash:
Description:

If the left operand does not designate a collection, the result has type `bool` and if that result
is `$true`, the elements of the Hashtable `$matches` are set to the strings that match (or
is `$true`, the elements of the Hashtable `$Matches` are set to the strings that match (or
do-not-match) the value designated by the right operand. Otherwise, the result is a possibly empty
unconstrained 1-dimensional array containing the elements of the collection that test True when
compared to the value designated by the right operand, and `$matches` is not set. The right operand
compared to the value designated by the right operand, and `$Matches` is not set. The right operand
may designate a string that contains regular expressions ([§3.16][§3.16]), in which case, it is
referred to as a _pattern_. These operators have two variants ([§7.8][§7.8]).

Expand All @@ -1710,11 +1710,11 @@ These operators support submatches ([§7.8.4.6][§7.8.4.6]).
Examples:

```powershell
"Hello" -match ".l" # True, $matches key/value is 0/"el"
"Hello" -match '\^h.*o$' # True, $matches key/value is
"Hello" -match ".l" # True, $Matches key/value is 0/"el"
"Hello" -match '\^h.*o$' # True, $Matches key/value is
0/"Hello"
"Hello" -cmatch '\^h.*o$' # False, $matches not set
"abc\^ef" -match ".\\\^e" # True, $matches key/value is 0/"c\^e"
"Hello" -cmatch '\^h.*o$' # False, $Matches not set
"abc\^ef" -match ".\\\^e" # True, $Matches key/value is 0/"c\^e"

"abc" -notmatch "[A-Za-z]" # False
"abc" -match "[\^A-Za-z]" # False
Expand Down Expand Up @@ -1885,7 +1885,7 @@ _submatches_) delimited by parentheses. Consider the following example:

`"red" -match "red"`

The result is `$true` and key 0 of `$matches` contains "red", that part of the string designated by
The result is `$true` and key 0 of `$Matches` contains "red", that part of the string designated by
the left operand that exactly matched the pattern designated by the right operand.

In the following example, the whole pattern is a submatch:
Expand Down Expand Up @@ -1914,7 +1914,7 @@ In the case of `-replace`, the replacement text can access the submatches via na

The resulting string is "the morning of Monday".

Instead of having keys in `$matches` be zero-based indexes, submatches can be named using the form
Instead of having keys in `$Matches` be zero-based indexes, submatches can be named using the form
`?<*name*>`. For example, `"((r)e)(d)"` can be written with three named submatches, `m1`, `m2`, and
`m3`, as follows: `"(?<m1>(?<m2>r)e)(?<m3>d)"`.

Expand Down
6 changes: 3 additions & 3 deletions reference/docs-conceptual/lang-spec/chapter-08.md
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ is case-insensitive.

A pattern may contain a regular expression ([§3.16][§3.16]), in which case, regular expression string
comparisons are performed, but only if the *switch-parameter* `-Regex` is present. By default, the
comparison is case-insensitive. If `-Regex` is present and a pattern is matched, `$matches` is
comparison is case-insensitive. If `-Regex` is present and a pattern is matched, `$Matches` is
defined in the *switch-clause* *statement-block* for that pattern.

A *switch-parameter* may be abbreviated; any distinct leading part of a parameter may be used. For
Expand Down Expand Up @@ -1169,7 +1169,7 @@ only:

- All operators except `-match`
- The `if` statement
- The following automatic variables: `$PsCulture`, `$PsUICulture`, `$true`, `$false`, and `$null`.
- The following automatic variables: `$PSCulture`, `$PSUICulture`, `$true`, `$false`, and `$null`.
- Comments
- Pipelines
- Statements separated by semicolons (`;`)
Expand Down Expand Up @@ -1660,7 +1660,7 @@ function Test {
[Parameter(Position = 0, ParameterSetname = "SetB")]
[int]$in
)
$PsCmdlet.ParameterSetName
$PSCmdlet.ParameterSetName
}

Test 42d # outputs "SetA"
Expand Down
6 changes: 3 additions & 3 deletions reference/docs-conceptual/lang-spec/chapter-12.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ conversion from `$null` to int.

This attribute is used in the *attribute-list* of *param-block* of a function to indicate that
function acts similar to a cmdlet. Specifically, it allows functions to access a number of methods
and properties through the $PsCmdlet variable by using begin, process, and end named blocks
and properties through the $PSCmdlet variable by using begin, process, and end named blocks
([§8.10.7][§8.10.7]).

When this attribute is present, positional arguments that have no matching positional parameters
Expand Down Expand Up @@ -322,11 +322,11 @@ ParameterSetName = "User")]<br />
ParameterSetName = "Computer")]<br />
[Parameter(ParameterSetName = "User")]<br />
[int] $SharedParam = 5 )</p>
<p>if ($PsCmdlet.ParameterSetName -eq "Computer")<br />
<p>if ($PSCmdlet.ParameterSetName -eq "Computer")<br />
{<br />
# handle "Computer" parameter set<br />
}</p>
<p>elseif ($PsCmdlet.ParameterSetName -eq "User")<br />
<p>elseif ($PSCmdlet.ParameterSetName -eq "User")<br />
{<br />
# handle "User" parameter set<br />
}<br />
Expand Down
Loading
Loading