Skip to content

Commit a1d2be5

Browse files
authored
Fixes #10828 - Update description of using assembly (#10862)
* Update description of `using assembly` * Fix broken links
1 parent d7fb685 commit a1d2be5

File tree

11 files changed

+238
-241
lines changed

11 files changed

+238
-241
lines changed

reference/5.1/Microsoft.PowerShell.Core/About/about_Using.md

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Allows you to specify namespaces to use in the session.
33
Locale: en-US
4-
ms.date: 08/17/2023
4+
ms.date: 02/06/2024
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_using?view=powershell-5.1&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about Using
@@ -37,6 +37,33 @@ using namespace <.NET-namespace>
3737

3838
Specifying a namespace makes it easier to reference types by their short names.
3939

40+
### Example - Add namespaces for typename resolution
41+
42+
The following script gets the cryptographic hash for the "Hello World" string.
43+
44+
Note how the `using namespace System.Text` and `using namespace System.IO`
45+
simplify the references to `[UnicodeEncoding]` in `System.Text` and `[Stream]`
46+
and `[MemoryStream]` in `System.IO`.
47+
48+
```powershell
49+
using namespace System.Text
50+
using namespace System.IO
51+
52+
[string]$string = "Hello World"
53+
## Valid values are "SHA1", "SHA256", "SHA384", "SHA512", "MD5"
54+
[string]$algorithm = "SHA256"
55+
56+
[byte[]]$stringBytes = [UnicodeEncoding]::Unicode.GetBytes($string)
57+
58+
[Stream]$memoryStream = [MemoryStream]::new($stringBytes)
59+
$getFileHashSplat = @{
60+
InputStream = $memoryStream
61+
Algorithm = $algorithm
62+
}
63+
$hashFromStream = Get-FileHash @getFileHashSplat
64+
$hashFromStream.Hash.ToString()
65+
```
66+
4067
## Module syntax
4168

4269
To load classes and enumerations from a PowerShell module:
@@ -85,54 +112,7 @@ To ensure that you're running the latest version, you must start a new session.
85112
Classes and enumerations defined in PowerShell and imported with a `using`
86113
statement can't be unloaded.
87114

88-
## Assembly syntax
89-
90-
To preload types from a .NET assembly:
91-
92-
```
93-
using assembly <.NET-assembly-path>
94-
using assembly <.NET-namespace>
95-
```
96-
97-
Loading an assembly preloads .NET types from that assembly into a script at
98-
parse time. This allows you to create new PowerShell classes that use types
99-
from the preloaded assembly.
100-
101-
In Windows PowerShell 5.1 you can load the assembly by path name or by
102-
name. When you use the name, PowerShell searches the .NET Global Assembly
103-
Cache (GAC) for the associated assembly.
104-
105-
If you aren't creating new PowerShell classes, use the `Add-Type` cmdlet
106-
instead. For more information, see
107-
[Add-Type](xref:Microsoft.PowerShell.Utility.Add-Type).
108-
109-
## Examples
110-
111-
### Example 1 - Add namespaces for typename resolution
112-
113-
The following script gets the cryptographic hash for the "Hello World" string.
114-
115-
Note how the `using namespace System.Text` and `using namespace System.IO`
116-
simplify the references to `[UnicodeEncoding]` in `System.Text` and `[Stream]`
117-
and `[MemoryStream]` in `System.IO`.
118-
119-
```powershell
120-
using namespace System.Text
121-
using namespace System.IO
122-
123-
[string]$string = "Hello World"
124-
## Valid values are "SHA1", "SHA256", "SHA384", "SHA512", "MD5"
125-
[string]$algorithm = "SHA256"
126-
127-
[byte[]]$stringbytes = [UnicodeEncoding]::Unicode.GetBytes($string)
128-
129-
[Stream]$memorystream = [MemoryStream]::new($stringbytes)
130-
$hashfromstream = Get-FileHash -InputStream $memorystream `
131-
-Algorithm $algorithm
132-
$hashfromstream.Hash.ToString()
133-
```
134-
135-
### Example 2 - Load classes from a script module
115+
### Example - Load classes from a script module
136116

137117
In this example, a PowerShell script module named **CardGames** defines the
138118
following classes:
@@ -154,7 +134,22 @@ $deck.Shuffle()
154134
[Card[]]$hand3 = $deck.Deal(5)
155135
```
156136

157-
### Example 3 - Load classes from an assembly
137+
## Assembly syntax
138+
139+
The following syntax preloads .NET types from that assembly into a script at
140+
the beginning of execution. You must use a fully-qualified path to the assembly
141+
file.
142+
143+
```Syntax
144+
using assembly <.NET-assembly-path>
145+
```
146+
147+
The `using assembly` statement is similar to using the `Add-Type` cmdlet.
148+
However, the `Add-Type` cmdlet adds the type at the time that `Add-Type` is
149+
executed, rather than at the start of execution of the script. For more
150+
information, see [Add-Type](xref:Microsoft.PowerShell.Utility.Add-Type).
151+
152+
### Example - Load types from an assembly
158153

159154
This example loads an assembly so that its classes can be used when processing
160155
data. The following script converts data into a YAML format.

reference/5.1/Microsoft.PowerShell.Utility/Send-MailMessage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ The `Send-MailMessage` cmdlet is obsolete. For more information, see
439439
[Platform Compatibility note DE0005](https://aka.ms/SendMailMessage). This cmdlet doesn't guarantee
440440
secure connections to SMTP servers.
441441

442-
_DE0005_ suggests using the third-party library, [MailKit](http://www.mimekit.net/). If you are
443-
using Exchange Online, you can use the
442+
_DE0005_ suggests using the third-party library, [MailKit](https://github.com/jstedfast/MimeKit). If
443+
you are using Exchange Online, you can use the
444444
[Send-MgUserMail](/powershell/module/microsoft.graph.users.actions/send-mgusermail) from the
445445
Microsoft Graph PowerShell SDK.
446446

reference/7.2/Microsoft.PowerShell.Core/About/about_Using.md

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Allows you to specify namespaces to use in the session.
33
Locale: en-US
4-
ms.date: 08/17/2023
4+
ms.date: 02/06/2024
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_using?view=powershell-7.2&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about Using
@@ -37,6 +37,33 @@ using namespace <.NET-namespace>
3737

3838
Specifying a namespace makes it easier to reference types by their short names.
3939

40+
### Example - Add namespaces for typename resolution
41+
42+
The following script gets the cryptographic hash for the "Hello World" string.
43+
44+
Note how the `using namespace System.Text` and `using namespace System.IO`
45+
simplify the references to `[UnicodeEncoding]` in `System.Text` and `[Stream]`
46+
and `[MemoryStream]` in `System.IO`.
47+
48+
```powershell
49+
using namespace System.Text
50+
using namespace System.IO
51+
52+
[string]$string = "Hello World"
53+
## Valid values are "SHA1", "SHA256", "SHA384", "SHA512", "MD5"
54+
[string]$algorithm = "SHA256"
55+
56+
[byte[]]$stringBytes = [UnicodeEncoding]::Unicode.GetBytes($string)
57+
58+
[Stream]$memoryStream = [MemoryStream]::new($stringBytes)
59+
$getFileHashSplat = @{
60+
InputStream = $memoryStream
61+
Algorithm = $algorithm
62+
}
63+
$hashFromStream = Get-FileHash @getFileHashSplat
64+
$hashFromStream.Hash.ToString()
65+
```
66+
4067
## Module syntax
4168

4269
To load classes and enumerations from a PowerShell module:
@@ -85,49 +112,7 @@ To ensure that you're running the latest version, you must start a new session.
85112
Classes and enumerations defined in PowerShell and imported with a `using`
86113
statement can't be unloaded.
87114

88-
## Assembly syntax
89-
90-
To preload types from a .NET assembly:
91-
92-
```
93-
using assembly <.NET-assembly-path>
94-
```
95-
96-
Loading an assembly preloads .NET types from that assembly into a script at
97-
parse time. This allows you to create new PowerShell classes that use types
98-
from the preloaded assembly.
99-
100-
If you aren't creating new PowerShell classes, use the `Add-Type` cmdlet
101-
instead. For more information, see
102-
[Add-Type](xref:Microsoft.PowerShell.Utility.Add-Type).
103-
104-
## Examples
105-
106-
### Example 1 - Add namespaces for typename resolution
107-
108-
The following script gets the cryptographic hash for the "Hello World" string.
109-
110-
Note how the `using namespace System.Text` and `using namespace System.IO`
111-
simplify the references to `[UnicodeEncoding]` in `System.Text` and `[Stream]`
112-
and `[MemoryStream]` in `System.IO`.
113-
114-
```powershell
115-
using namespace System.Text
116-
using namespace System.IO
117-
118-
[string]$string = "Hello World"
119-
## Valid values are "SHA1", "SHA256", "SHA384", "SHA512", "MD5"
120-
[string]$algorithm = "SHA256"
121-
122-
[byte[]]$stringbytes = [UnicodeEncoding]::Unicode.GetBytes($string)
123-
124-
[Stream]$memorystream = [MemoryStream]::new($stringbytes)
125-
$hashfromstream = Get-FileHash -InputStream $memorystream `
126-
-Algorithm $algorithm
127-
$hashfromstream.Hash.ToString()
128-
```
129-
130-
### Example 2 - Load classes from a script module
115+
### Example - Load classes from a script module
131116

132117
In this example, a PowerShell script module named **CardGames** defines the
133118
following classes:
@@ -149,7 +134,22 @@ $deck.Shuffle()
149134
[Card[]]$hand3 = $deck.Deal(5)
150135
```
151136

152-
### Example 3 - Load classes from an assembly
137+
## Assembly syntax
138+
139+
The following syntax preloads .NET types from that assembly into a script at
140+
the beginning of execution. You must use a fully-qualified path to the assembly
141+
file.
142+
143+
```Syntax
144+
using assembly <.NET-assembly-path>
145+
```
146+
147+
The `using assembly` statement is similar to using the `Add-Type` cmdlet.
148+
However, the `Add-Type` cmdlet adds the type at the time that `Add-Type` is
149+
executed, rather than at the start of execution of the script. For more
150+
information, see [Add-Type](xref:Microsoft.PowerShell.Utility.Add-Type).
151+
152+
### Example - Load types from an assembly
153153

154154
This example loads an assembly so that its classes can be used when processing
155155
data. The following script converts data into a YAML format.

reference/7.2/Microsoft.PowerShell.Utility/Send-MailMessage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ The `Send-MailMessage` cmdlet is obsolete. For more information, see
465465
[Platform Compatibility note DE0005](https://aka.ms/SendMailMessage). This cmdlet doesn't guarantee
466466
secure connections to SMTP servers.
467467

468-
_DE0005_ suggests using the third-party library, [MailKit](http://www.mimekit.net/). If you are
469-
using Exchange Online, you can use the
468+
_DE0005_ suggests using the third-party library, [MailKit](https://github.com/jstedfast/MimeKit). If
469+
you are using Exchange Online, you can use the
470470
[Send-MgUserMail](/powershell/module/microsoft.graph.users.actions/send-mgusermail) from the
471471
Microsoft Graph PowerShell SDK.
472472

reference/7.3/Microsoft.PowerShell.Core/About/about_Using.md

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Allows you to specify namespaces to use in the session.
33
Locale: en-US
4-
ms.date: 08/17/2023
4+
ms.date: 02/06/2024
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_using?view=powershell-7.3&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about Using
@@ -37,6 +37,33 @@ using namespace <.NET-namespace>
3737

3838
Specifying a namespace makes it easier to reference types by their short names.
3939

40+
### Example - Add namespaces for typename resolution
41+
42+
The following script gets the cryptographic hash for the "Hello World" string.
43+
44+
Note how the `using namespace System.Text` and `using namespace System.IO`
45+
simplify the references to `[UnicodeEncoding]` in `System.Text` and `[Stream]`
46+
and `[MemoryStream]` in `System.IO`.
47+
48+
```powershell
49+
using namespace System.Text
50+
using namespace System.IO
51+
52+
[string]$string = "Hello World"
53+
## Valid values are "SHA1", "SHA256", "SHA384", "SHA512", "MD5"
54+
[string]$algorithm = "SHA256"
55+
56+
[byte[]]$stringBytes = [UnicodeEncoding]::Unicode.GetBytes($string)
57+
58+
[Stream]$memoryStream = [MemoryStream]::new($stringBytes)
59+
$getFileHashSplat = @{
60+
InputStream = $memoryStream
61+
Algorithm = $algorithm
62+
}
63+
$hashFromStream = Get-FileHash @getFileHashSplat
64+
$hashFromStream.Hash.ToString()
65+
```
66+
4067
## Module syntax
4168

4269
To load classes and enumerations from a PowerShell module:
@@ -85,49 +112,7 @@ To ensure that you're running the latest version, you must start a new session.
85112
Classes and enumerations defined in PowerShell and imported with a `using`
86113
statement can't be unloaded.
87114

88-
## Assembly syntax
89-
90-
To preload types from a .NET assembly:
91-
92-
```
93-
using assembly <.NET-assembly-path>
94-
```
95-
96-
Loading an assembly preloads .NET types from that assembly into a script at
97-
parse time. This allows you to create new PowerShell classes that use types
98-
from the preloaded assembly.
99-
100-
If you aren't creating new PowerShell classes, use the `Add-Type` cmdlet
101-
instead. For more information, see
102-
[Add-Type](xref:Microsoft.PowerShell.Utility.Add-Type).
103-
104-
## Examples
105-
106-
### Example 1 - Add namespaces for typename resolution
107-
108-
The following script gets the cryptographic hash for the "Hello World" string.
109-
110-
Note how the `using namespace System.Text` and `using namespace System.IO`
111-
simplify the references to `[UnicodeEncoding]` in `System.Text` and `[Stream]`
112-
and `[MemoryStream]` in `System.IO`.
113-
114-
```powershell
115-
using namespace System.Text
116-
using namespace System.IO
117-
118-
[string]$string = "Hello World"
119-
## Valid values are "SHA1", "SHA256", "SHA384", "SHA512", "MD5"
120-
[string]$algorithm = "SHA256"
121-
122-
[byte[]]$stringbytes = [UnicodeEncoding]::Unicode.GetBytes($string)
123-
124-
[Stream]$memorystream = [MemoryStream]::new($stringbytes)
125-
$hashfromstream = Get-FileHash -InputStream $memorystream `
126-
-Algorithm $algorithm
127-
$hashfromstream.Hash.ToString()
128-
```
129-
130-
### Example 2 - Load classes from a script module
115+
### Example - Load classes from a script module
131116

132117
In this example, a PowerShell script module named **CardGames** defines the
133118
following classes:
@@ -149,7 +134,22 @@ $deck.Shuffle()
149134
[Card[]]$hand3 = $deck.Deal(5)
150135
```
151136

152-
### Example 3 - Load classes from an assembly
137+
## Assembly syntax
138+
139+
The following syntax preloads .NET types from that assembly into a script at
140+
the beginning of execution. You must use a fully-qualified path to the assembly
141+
file.
142+
143+
```Syntax
144+
using assembly <.NET-assembly-path>
145+
```
146+
147+
The `using assembly` statement is similar to using the `Add-Type` cmdlet.
148+
However, the `Add-Type` cmdlet adds the type at the time that `Add-Type` is
149+
executed, rather than at the start of execution of the script. For more
150+
information, see [Add-Type](xref:Microsoft.PowerShell.Utility.Add-Type).
151+
152+
### Example - Load types from an assembly
153153

154154
This example loads an assembly so that its classes can be used when processing
155155
data. The following script converts data into a YAML format.

reference/7.3/Microsoft.PowerShell.Utility/Send-MailMessage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ The `Send-MailMessage` cmdlet is obsolete. For more information, see
465465
[Platform Compatibility note DE0005](https://aka.ms/SendMailMessage). This cmdlet doesn't guarantee
466466
secure connections to SMTP servers.
467467

468-
_DE0005_ suggests using the third-party library, [MailKit](http://www.mimekit.net/). If you are
469-
using Exchange Online, you can use the
468+
_DE0005_ suggests using the third-party library, [MailKit](https://github.com/jstedfast/MimeKit). If
469+
you are using Exchange Online, you can use the
470470
[Send-MgUserMail](/powershell/module/microsoft.graph.users.actions/send-mgusermail) from the
471471
Microsoft Graph PowerShell SDK.
472472

0 commit comments

Comments
 (0)