Skip to content

Commit 444edfd

Browse files
committed
Add note about PassThru
1 parent d0bbea5 commit 444edfd

File tree

3 files changed

+65
-63
lines changed

3 files changed

+65
-63
lines changed

reference/5.1/Microsoft.PowerShell.Utility/Add-Type.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Utility
5-
ms.date: 12/12/2022
5+
ms.date: 11/25/2024
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/add-type?view=powershell-5.1&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: Add-Type
@@ -64,7 +64,7 @@ the class is available in all PowerShell sessions.
6464

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

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

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

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

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

@@ -484,7 +484,7 @@ Accept wildcard characters: False
484484

485485
### -MemberDefinition
486486

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

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

526526
### -Namespace
527527

528-
Specifies a namespace for the type.
529-
530-
If this parameter isn't included in the command, the type is created in the
531-
**Microsoft.PowerShell.Commands.AddType.AutoGeneratedTypes** namespace. If the parameter is included
532-
in the command with an empty string value or a value of `$Null`, the type is generated in the global
533-
namespace.
528+
By default, this command creates the type in the
529+
**Microsoft.PowerShell.Commands.AddType.AutoGeneratedTypes** namespace. When you use this parameter,
530+
the type is created in the specified namespace. If the value an empty string, the type is created in
531+
the global namespace.
534532

535533
```yaml
536534
Type: System.String
@@ -548,7 +546,8 @@ Accept wildcard characters: False
548546

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

553552
```yaml
554553
Type: System.String
@@ -566,7 +565,8 @@ Accept wildcard characters: True
566565

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

571571
The acceptable values for this parameter are as follows:
572572

@@ -590,7 +590,8 @@ Accept wildcard characters: False
590590
### -PassThru
591591

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

595596
```yaml
596597
Type: System.Management.Automation.SwitchParameter
@@ -697,7 +698,8 @@ Accept wildcard characters: False
697698

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

702704
## INPUTS
703705

@@ -719,7 +721,8 @@ the new type.
719721
## NOTES
720722

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

724727
Type names and namespaces must be unique within a session. You can't unload a type or change it. If
725728
you need to change the code for a type, you must change the name or start a new PowerShell session.

reference/7.4/Microsoft.PowerShell.Utility/Add-Type.md

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Utility
5-
ms.date: 08/15/2023
5+
ms.date: 11/25/2024
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/add-type?view=powershell-7.4&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: Add-Type
@@ -72,15 +72,15 @@ You can use the parameters of `Add-Type` to specify an alternate language and co
7272
default, compiler options, assembly dependencies, the class namespace, the names of the type, and
7373
the resulting assembly.
7474

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

7979
## EXAMPLES
8080

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

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

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

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

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

281-
282281
```yaml
283282
Type: System.String[]
284283
Parameter Sets: FromAssemblyName
@@ -330,7 +329,7 @@ Accept wildcard characters: False
330329

331330
### -Language
332331

333-
Specifies the language that is used in the source code. The acceptable value for this parameter is
332+
Specifies the language that's used in the source code. The acceptable value for this parameter is
334333
`CSharp`.
335334

336335
```yaml
@@ -370,7 +369,7 @@ Accept wildcard characters: False
370369

371370
### -MemberDefinition
372371

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

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

412411
### -Namespace
413412

414-
Specifies a namespace for the type.
415-
416-
If this parameter isn't included in the command, the type is created in the
417-
**Microsoft.PowerShell.Commands.AddType.AutoGeneratedTypes** namespace. If the parameter is included
418-
in the command with an empty string value or a value of `$Null`, the type is generated in the global
419-
namespace.
413+
By default, this command creates the type in the
414+
**Microsoft.PowerShell.Commands.AddType.AutoGeneratedTypes** namespace. When you use this parameter,
415+
the type is created in the specified namespace. If the value an empty string, the type is created in
416+
the global namespace.
420417

421418
```yaml
422419
Type: System.String
@@ -434,7 +431,8 @@ Accept wildcard characters: False
434431

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

439437
```yaml
440438
Type: System.String
@@ -452,7 +450,8 @@ Accept wildcard characters: True
452450

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

457456
The acceptable values for this parameter are as follows:
458457

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

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

@@ -481,7 +480,8 @@ Accept wildcard characters: False
481480
### -PassThru
482481

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

486486
```yaml
487487
Type: System.Management.Automation.SwitchParameter
@@ -521,11 +521,9 @@ Accept wildcard characters: False
521521
### -ReferencedAssemblies
522522

523523
Specifies the assemblies upon which the type depends. By default, `Add-Type` references `System.dll`
524-
and `System.Management.Automation.dll`. The assemblies that you specify by using this parameter are
525-
referenced in addition to the default assemblies.
526-
527-
Beginning in PowerShell 6, **ReferencedAssemblies** doesn't include the default .NET assemblies. You
528-
must include a specific reference to them in the value passed to this parameter.
524+
and `System.Management.Automation.dll`. Beginning in PowerShell 6, **ReferencedAssemblies** doesn't
525+
include the default .NET assemblies. You must include a specific reference to them in the value
526+
passed to this parameter.
529527

530528
```yaml
531529
Type: System.String[]
@@ -588,7 +586,8 @@ Accept wildcard characters: False
588586

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

593592
## INPUTS
594593

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

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

630629
## RELATED LINKS
631630

0 commit comments

Comments
 (0)