Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #11550 - Add note about PassThru #11551

Merged
merged 1 commit into from
Nov 25, 2024
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
35 changes: 19 additions & 16 deletions reference/5.1/Microsoft.PowerShell.Utility/Add-Type.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
Locale: en-US
Module Name: Microsoft.PowerShell.Utility
ms.date: 12/12/2022
ms.date: 11/25/2024
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/add-type?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: Add-Type
Expand Down Expand Up @@ -64,7 +64,7 @@ the class is available in all PowerShell sessions.

You can specify the type by specifying an existing assembly or source code files, or you can specify
the source code inline or saved in a variable. You can even specify only a method and `Add-Type`
will define and generate the class. On Windows, you can use this feature to make Platform Invoke
defines and generates the class. On Windows, you can use this feature to make Platform Invoke
(P/Invoke) calls to unmanaged functions in PowerShell. If you specify source code, `Add-Type`
compiles the specified source code and generates an in-memory assembly that contains the new .NET
Framework types.
Expand All @@ -77,7 +77,7 @@ the resulting assembly.

### Example 1: Add a .NET type to a session

This example adds the **BasicTest** class to the session by specifying source code that is stored in
This example adds the **BasicTest** class to the session by specifying source code that's stored in
a variable. The **BasicTest** class is used to add integers, create an object, and multiply
integers.

Expand Down Expand Up @@ -240,7 +240,7 @@ PowerShell console. The method takes two parameters: the window handle, and an i
specifies how the window is displayed.

To minimize the PowerShell console, `ShowWindowAsync` uses the `Get-Process` cmdlet with the `$PID`
automatic variable to get the process that is hosting the current PowerShell session. Then it uses
automatic variable to get the process that's hosting the current PowerShell session. Then it uses
the **MainWindowHandle** property of the current process and a value of `2`, which represents the
`SW_MINIMIZE` value.

Expand Down Expand Up @@ -484,7 +484,7 @@ Accept wildcard characters: False

### -MemberDefinition

Specifies new properties or methods for the class. `Add-Type` generates the template code that is
Specifies new properties or methods for the class. `Add-Type` generates the template code that's
required to support the properties or methods.

On Windows, you can use this feature to make Platform Invoke (P/Invoke) calls to unmanaged functions
Expand Down Expand Up @@ -525,12 +525,10 @@ Accept wildcard characters: False

### -Namespace

Specifies a namespace for the type.

If this parameter isn't included in the command, the type is created in the
**Microsoft.PowerShell.Commands.AddType.AutoGeneratedTypes** namespace. If the parameter is included
in the command with an empty string value or a value of `$Null`, the type is generated in the global
namespace.
By default, this command creates the type in the
**Microsoft.PowerShell.Commands.AddType.AutoGeneratedTypes** namespace. When you use this parameter,
the type is created in the specified namespace. If the value an empty string, the type is created in
the global namespace.

```yaml
Type: System.String
Expand All @@ -548,7 +546,8 @@ Accept wildcard characters: False

Generates a DLL file for the assembly with the specified name in the location. Enter an optional
path and filename. Wildcard characters are permitted. By default, `Add-Type` generates the assembly
only in memory.
only in memory. If you output the assembly to a file you should include the **PassThru** parameter
to return the type from the newly created assembly.

```yaml
Type: System.String
Expand All @@ -566,7 +565,8 @@ Accept wildcard characters: True

Specifies the output type of the output assembly. By default, no output type is specified. This
parameter is valid only when an output assembly is specified in the command. For more information
about the values, see [OutputAssemblyType Enumeration](/dotnet/api/microsoft.powershell.commands.outputassemblytype).
about the values, see
[OutputAssemblyType Enumeration](/dotnet/api/microsoft.powershell.commands.outputassemblytype).

The acceptable values for this parameter are as follows:

Expand All @@ -590,7 +590,8 @@ Accept wildcard characters: False
### -PassThru

Returns a **System.Runtime** object that represents the types that were added. By default, this
cmdlet doesn't generate any output.
cmdlet doesn't generate any output. Use this parameter if you used **OutputAssembly** to create a
DLL file and you want to return the type from the newly created assembly.

```yaml
Type: System.Management.Automation.SwitchParameter
Expand Down Expand Up @@ -697,7 +698,8 @@ Accept wildcard characters: False

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose,
-WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
-WarningAction, and -WarningVariable. For more information, see
[about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

Expand All @@ -719,7 +721,8 @@ the new type.
## NOTES

The types that you add exist only in the current session. To use the types in all sessions, add them
to your PowerShell profile. For more information about the profile, see [about_Profiles](../Microsoft.PowerShell.Core/About/about_Profiles.md).
to your PowerShell profile. For more information about the profile, see
[about_Profiles](../Microsoft.PowerShell.Core/About/about_Profiles.md).

Type names and namespaces must be unique within a session. You can't unload a type or change it. If
you need to change the code for a type, you must change the name or start a new PowerShell session.
Expand Down
47 changes: 23 additions & 24 deletions reference/7.4/Microsoft.PowerShell.Utility/Add-Type.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
Locale: en-US
Module Name: Microsoft.PowerShell.Utility
ms.date: 08/15/2023
ms.date: 11/25/2024
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/add-type?view=powershell-7.4&WT.mc_id=ps-gethelp
schema: 2.0.0
title: Add-Type
Expand Down Expand Up @@ -72,15 +72,15 @@ You can use the parameters of `Add-Type` to specify an alternate language and co
default, compiler options, assembly dependencies, the class namespace, the names of the type, and
the resulting assembly.

Beginning in PowerShell 7, `Add-Type` does not compile a type if a type with the same name already
Beginning in PowerShell 7, `Add-Type` doesn't compile a type if a type with the same name already
exists. Also, `Add-Type` looks for assemblies in a `ref` folder under the folder that contains
`pwsh.dll`.

## EXAMPLES

### Example 1: Add a .NET type to a session

This example adds the **BasicTest** class to the session by specifying source code that is stored in
This example adds the **BasicTest** class to the session by specifying source code that's stored in
a variable. The **BasicTest** class is used to add integers, create an object, and multiply
integers.

Expand Down Expand Up @@ -247,7 +247,7 @@ PowerShell console. The method takes two parameters: the window handle, and an i
specifies how the window is displayed.

To minimize the PowerShell console, `ShowWindowAsync` uses the `Get-Process` cmdlet with the `$PID`
automatic variable to get the process that is hosting the current PowerShell session. Then it uses
automatic variable to get the process that's hosting the current PowerShell session. Then it uses
the **MainWindowHandle** property of the current process and a value of `2`, which represents the
`SW_MINIMIZE` value.

Expand Down Expand Up @@ -278,7 +278,6 @@ If .NET fails to resolve the name, PowerShell then looks in the current location
assembly. When you use wildcards in the **AssemblyName** parameter, the .NET assembly resolution
process fails causing PowerShell to look in the current location.


```yaml
Type: System.String[]
Parameter Sets: FromAssemblyName
Expand Down Expand Up @@ -330,7 +329,7 @@ Accept wildcard characters: False

### -Language

Specifies the language that is used in the source code. The acceptable value for this parameter is
Specifies the language that's used in the source code. The acceptable value for this parameter is
`CSharp`.

```yaml
Expand Down Expand Up @@ -370,7 +369,7 @@ Accept wildcard characters: False

### -MemberDefinition

Specifies new properties or methods for the class. `Add-Type` generates the template code that is
Specifies new properties or methods for the class. `Add-Type` generates the template code that's
required to support the properties or methods.

On Windows, you can use this feature to make Platform Invoke (P/Invoke) calls to unmanaged functions
Expand Down Expand Up @@ -411,12 +410,10 @@ Accept wildcard characters: False

### -Namespace

Specifies a namespace for the type.

If this parameter isn't included in the command, the type is created in the
**Microsoft.PowerShell.Commands.AddType.AutoGeneratedTypes** namespace. If the parameter is included
in the command with an empty string value or a value of `$Null`, the type is generated in the global
namespace.
By default, this command creates the type in the
**Microsoft.PowerShell.Commands.AddType.AutoGeneratedTypes** namespace. When you use this parameter,
the type is created in the specified namespace. If the value an empty string, the type is created in
the global namespace.

```yaml
Type: System.String
Expand All @@ -434,7 +431,8 @@ Accept wildcard characters: False

Generates a DLL file for the assembly with the specified name in the location. Enter an optional
path and filename. Wildcard characters are permitted. By default, `Add-Type` generates the assembly
only in memory.
only in memory. If you output the assembly to a file you should include the **PassThru** parameter
to return the type from the newly created assembly.

```yaml
Type: System.String
Expand All @@ -452,7 +450,8 @@ Accept wildcard characters: True

Specifies the output type of the output assembly. By default, no output type is specified. This
parameter is valid only when an output assembly is specified in the command. For more information
about the values, see [OutputAssemblyType Enumeration](/dotnet/api/microsoft.powershell.commands.outputassemblytype).
about the values, see
[OutputAssemblyType Enumeration](/dotnet/api/microsoft.powershell.commands.outputassemblytype).

The acceptable values for this parameter are as follows:

Expand All @@ -461,7 +460,7 @@ The acceptable values for this parameter are as follows:
- `WindowsApplication`

> [!IMPORTANT]
> As of PowerShell 7.1, `ConsoleApplication` and `WindowsApplication` are not supported and
> As of PowerShell 7.1, `ConsoleApplication` and `WindowsApplication` aren't supported and
> PowerShell throws a terminating error if either are specified as values for the **OutputType**
> parameter.

Expand All @@ -481,7 +480,8 @@ Accept wildcard characters: False
### -PassThru

Returns a **System.Runtime** object that represents the types that were added. By default, this
cmdlet doesn't generate any output.
cmdlet doesn't generate any output. Use this parameter if you used **OutputAssembly** to create a
DLL file and you want to return the type from the newly created assembly.

```yaml
Type: System.Management.Automation.SwitchParameter
Expand Down Expand Up @@ -521,11 +521,9 @@ Accept wildcard characters: False
### -ReferencedAssemblies

Specifies the assemblies upon which the type depends. By default, `Add-Type` references `System.dll`
and `System.Management.Automation.dll`. The assemblies that you specify by using this parameter are
referenced in addition to the default assemblies.

Beginning in PowerShell 6, **ReferencedAssemblies** doesn't include the default .NET assemblies. You
must include a specific reference to them in the value passed to this parameter.
and `System.Management.Automation.dll`. Beginning in PowerShell 6, **ReferencedAssemblies** doesn't
include the default .NET assemblies. You must include a specific reference to them in the value
passed to this parameter.

```yaml
Type: System.String[]
Expand Down Expand Up @@ -588,7 +586,8 @@ Accept wildcard characters: False

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose,
-WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
-WarningAction, and -WarningVariable. For more information, see
[about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

Expand Down Expand Up @@ -625,7 +624,7 @@ them. However, using `Add-Type` is still permitted to allow scripts to be implic
any version of PowerShell.

Assemblies in the GAC can be loaded by type name, rather than by path. Loading assemblies from an
arbitrary path requires `Add-Type`, since those assemblies cannot not be loaded automatically.
arbitrary path requires `Add-Type`, since those assemblies can't not be loaded automatically.

## RELATED LINKS

Expand Down
Loading