diff --git a/reference/5.1/Microsoft.PowerShell.Utility/Add-Type.md b/reference/5.1/Microsoft.PowerShell.Utility/Add-Type.md index 171b27073d56..3fd79b0a7d52 100644 --- a/reference/5.1/Microsoft.PowerShell.Utility/Add-Type.md +++ b/reference/5.1/Microsoft.PowerShell.Utility/Add-Type.md @@ -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 @@ -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. @@ -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. @@ -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. @@ -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 @@ -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 @@ -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 @@ -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: @@ -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 @@ -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 @@ -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. diff --git a/reference/7.4/Microsoft.PowerShell.Utility/Add-Type.md b/reference/7.4/Microsoft.PowerShell.Utility/Add-Type.md index 69a4aea3e74c..406eb724c637 100644 --- a/reference/7.4/Microsoft.PowerShell.Utility/Add-Type.md +++ b/reference/7.4/Microsoft.PowerShell.Utility/Add-Type.md @@ -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 @@ -72,7 +72,7 @@ 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`. @@ -80,7 +80,7 @@ exists. Also, `Add-Type` looks for assemblies in a `ref` folder under the folder ### 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. @@ -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. @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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: @@ -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. @@ -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 @@ -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[] @@ -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 @@ -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 diff --git a/reference/7.5/Microsoft.PowerShell.Utility/Add-Type.md b/reference/7.5/Microsoft.PowerShell.Utility/Add-Type.md index 4a6a6e338839..d57c3cde8288 100644 --- a/reference/7.5/Microsoft.PowerShell.Utility/Add-Type.md +++ b/reference/7.5/Microsoft.PowerShell.Utility/Add-Type.md @@ -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.5&WT.mc_id=ps-gethelp schema: 2.0.0 title: Add-Type @@ -72,7 +72,7 @@ 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`. @@ -80,7 +80,7 @@ exists. Also, `Add-Type` looks for assemblies in a `ref` folder under the folder ### 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. @@ -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. @@ -329,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 @@ -369,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 @@ -410,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 @@ -433,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 @@ -451,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: @@ -460,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. @@ -480,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 @@ -520,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[] @@ -587,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 @@ -624,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