22external help file : Microsoft.PowerShell.Commands.Utility.dll-Help.xml
33Locale : en-US
44Module Name : Microsoft.PowerShell.Utility
5- ms.date : 08/15/2023
5+ ms.date : 11/25/2024
66online version : https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/add-type?view=powershell-7.4&WT.mc_id=ps-gethelp
77schema : 2.0.0
88title : Add-Type
@@ -72,15 +72,15 @@ You can use the parameters of `Add-Type` to specify an alternate language and co
7272default, compiler options, assembly dependencies, the class namespace, the names of the type, and
7373the 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
7676exists. 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
8484a variable. The ** BasicTest** class is used to add integers, create an object, and multiply
8585integers.
8686
@@ -247,7 +247,7 @@ PowerShell console. The method takes two parameters: the window handle, and an i
247247specifies how the window is displayed.
248248
249249To 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
251251the ** 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
278278assembly. When you use wildcards in the ** AssemblyName** parameter, the .NET assembly resolution
279279process fails causing PowerShell to look in the current location.
280280
281-
282281``` yaml
283282Type : System.String[]
284283Parameter 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
374373required to support the properties or methods.
375374
376375On 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
422419Type: System.String
@@ -434,7 +431,8 @@ Accept wildcard characters: False
434431
435432Generates a DLL file for the assembly with the specified name in the location. Enter an optional
436433path 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
440438Type: System.String
@@ -452,7 +450,8 @@ Accept wildcard characters: True
452450
453451Specifies the output type of the output assembly. By default, no output type is specified. This
454452parameter 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
457456The 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
483482Returns 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
487487Type: System.Management.Automation.SwitchParameter
@@ -521,11 +521,9 @@ Accept wildcard characters: False
521521# ## -ReferencedAssemblies
522522
523523Specifies 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
531529Type: System.String[]
@@ -588,7 +586,8 @@ Accept wildcard characters: False
588586
589587This 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
625624any version of PowerShell.
626625
627626Assemblies 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