Skip to content

Commit cab9e80

Browse files
authored
Add info and link to about_Comments (#11749)
1 parent abced37 commit cab9e80

File tree

16 files changed

+545
-507
lines changed

16 files changed

+545
-507
lines changed

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

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes regular expressions in PowerShell.
33
Locale: en-US
4-
ms.date: 06/14/2024
4+
ms.date: 01/30/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_regular_expressions?view=powershell-5.1&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Regular_Expressions
@@ -17,19 +17,20 @@ Describes regular expressions in PowerShell.
1717
> [!NOTE]
1818
> This article shows the syntax and methods for using regular expressions in
1919
> PowerShell. It doesn't cover all possible expressions. For a more complete
20-
> reference, see the [Regular Expression Language - Quick Reference][03].
20+
> reference, see the [Regular Expression Language - Quick Reference][02].
2121
2222
A regular expression is a pattern used to match text. It can be made up of
23-
literal characters, operators, and other constructs.
23+
literal characters, operators, and other constructs. PowerShell uses the
24+
[.NET regex][03] engine.
2425

2526
This article demonstrates regular expression syntax in PowerShell. PowerShell
2627
has several operators and cmdlets that use regular expressions. You can read
2728
more about their syntax and usage at the links below.
2829

29-
- [Select-String][10]
30-
- [-match and -replace operators][06]
31-
- [-split operator][08]
32-
- [switch statement with -regex option][09]
30+
- [Select-String][11]
31+
- [-match and -replace operators][07]
32+
- [-split operator][09]
33+
- [switch statement with -regex option][10]
3334

3435
PowerShell regular expressions are case-insensitive by default. Each method
3536
shown above has a different way to force case sensitivity.
@@ -81,8 +82,8 @@ characters).
8182

8283
### Numbers
8384

84-
The `\d` character class will match any decimal digit. Conversely, `\D` will
85-
match any character except decimal digits.
85+
The `\d` character class matchs any decimal digit. Conversely, `\D` matches any
86+
character except decimal digits.
8687

8788
```powershell
8889
# This expression returns true if it matches a server name.
@@ -92,7 +93,7 @@ match any character except decimal digits.
9293

9394
### Word characters
9495

95-
The `\w` character class will match any word character `[a-zA-Z_0-9]`. To match
96+
The `\w` character class matches any word character `[a-zA-Z_0-9]`. To match
9697
any non-word character, use `\W`.
9798

9899
```powershell
@@ -103,8 +104,8 @@ any non-word character, use `\W`.
103104

104105
### Wildcards
105106

106-
The period (`.`) is a wildcard character in regular expressions. It will match
107-
any character except a newline (`\n`).
107+
The period (`.`) is a wildcard character in regular expressions. It matches any
108+
character except a newline (`\n`).
108109

109110
```powershell
110111
# This expression returns true.
@@ -155,7 +156,7 @@ The plus sign (`+`) matches the previous element one or more times.
155156
```
156157

157158
The question mark `?` matches the previous element zero or one time. Like
158-
asterisk `*`, it will even match strings where the element is absent.
159+
asterisk `*`, it even matches strings where the element is absent.
159160

160161
```powershell
161162
# This returns true for any server name, even server names without dashes.
@@ -208,7 +209,7 @@ When using anchors in PowerShell, you should understand the difference between
208209
instead of matching every character EXCEPT the newline `\n`.
209210

210211
To read more about these options and how to use them, visit the
211-
[Regular Expression Language - Quick Reference][03].
212+
[Regular Expression Language - Quick Reference][02].
212213

213214
## Escaping characters
214215

@@ -354,7 +355,7 @@ The provided regular expression extracts the username and domain from the
354355
message and stores them under the keys:**N** for name and **D** for domain.
355356
356357
```powershell
357-
$log = (Get-EventLog -LogName Security -Newest 1 -InstanceId 4689).Message
358+
$log = (Get-WinEvent -LogName Security -MaxEvents 1).Message
358359
$r = '(?s).*Account Name:\s*(?<N>.*).*Account Domain:\s*(?<D>[A-Z,0-9]*)'
359360
$log -match $r
360361
```
@@ -372,10 +373,10 @@ Name Value
372373
---- -----
373374
D CONTOSO
374375
N jsmith
375-
0 A process has exited....
376+
0 A process has exited...
376377
```
377378

378-
For more information, see [Grouping Constructs in Regular Expressions][02].
379+
For more information, see [Grouping Constructs in Regular Expressions][01].
379380

380381
### Substitutions in Regular Expressions
381382

@@ -461,18 +462,32 @@ Gobble Gobble
461462
For detailed information on substitution expressions, see
462463
[Substitutions in Regular Expressions][04].
463464
465+
## Comments in regular expressions
466+
467+
Regular expressions can be very complex and difficult to read. You can use
468+
comments to make them more understandable. There are two types of comments
469+
allowed in regular expressions.
470+
471+
- Inline comment (`(?#)`)
472+
- End-of-line comment (`#`)
473+
474+
For more information, see the _Regular expression comments_ section of
475+
[about_Comments][05].
476+
464477
## See also
465478
466-
- [about_Operators][07]
467-
- [about_Comparison_Operators][05]
479+
- [about_Operators][08]
480+
- [about_Comparison_Operators][06]
468481
469482
<!-- link references -->
470-
[02]: /dotnet/standard/base-types/grouping-constructs-in-regular-expressions
471-
[03]: /dotnet/standard/base-types/regular-expression-language-quick-reference
483+
[01]: /dotnet/standard/base-types/grouping-constructs-in-regular-expressions
484+
[02]: /dotnet/standard/base-types/regular-expression-language-quick-reference
485+
[03]: /dotnet/standard/base-types/regular-expressions
472486
[04]: /dotnet/standard/base-types/substitutions-in-regular-expressions
473-
[05]: about_Comparison_Operators.md
474-
[06]: about_Comparison_Operators.md#matching-operators
475-
[07]: about_Operators.md
476-
[08]: about_Split.md
477-
[09]: about_Switch.md
478-
[10]: xref:Microsoft.PowerShell.Utility.Select-String
487+
[05]: about_Comments.md#regular-expression-comments
488+
[06]: about_Comparison_Operators.md
489+
[07]: about_Comparison_Operators.md#matching-operators
490+
[08]: about_Operators.md
491+
[09]: about_Split.md
492+
[10]: about_Switch.md
493+
[11]: xref:Microsoft.PowerShell.Utility.Select-String

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Explains how to sign scripts so that they comply with the PowerShell execution policies.
33
Locale: en-US
4-
ms.date: 01/07/2025
4+
ms.date: 01/30/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_signing?view=powershell-5.1&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Signing
@@ -15,7 +15,7 @@ policies.
1515

1616
## Long description
1717

18-
The Restricted execution policy doesn't permit any scripts to run. The
18+
The **Restricted** execution policy doesn't permit any scripts to run. The
1919
**AllSigned** and **RemoteSigned** execution policies prevent PowerShell from
2020
running scripts that don't have a digital signature.
2121

@@ -141,10 +141,8 @@ certificate. Two types of certificates are suitable for signing a script file:
141141
not run on other computers.
142142

143143
Self-signed certificate should only be used to sign scripts for testing
144-
purposes.
145-
146-
It isn't appropriate for scripts that will be shared, even within an
147-
enterprise.
144+
purposes. Self-signed certificates aren't appropriate for scripts that you want
145+
to share.
148146

149147
If you create a self-signed certificate, be sure to enable strong private key
150148
protection on your certificate. This prevents malicious programs from signing
@@ -220,7 +218,7 @@ Directory: Microsoft.PowerShell.Security\Certificate::CurrentUser\My
220218
221219
Thumbprint Subject
222220
---------- -------
223-
4D4917CB140714BA5B81B96E0B18AAF2C4564FDF CN=PowerShell User ]
221+
4D4917CB140714BA5B81B96E0B18AAF2C4564FDF CN=PowerShell User
224222
```
225223

226224
## Sign a script
@@ -265,6 +263,10 @@ $cert = Get-ChildItem Cert:\CurrentUser\My -CodeSigningCert |
265263
Set-AuthenticodeSignature add-signature.ps1 $cert
266264
```
267265

266+
The `Set-AuthenticodeSignature` cmdlet adds the signature to the script file as
267+
a comment block at the end of the file. The comment block begins and ends with
268+
`# SIG #`.
269+
268270
After you sign the script, you can run it on the local computer. However, the
269271
script won't run on computers where the PowerShell execution policy requires a
270272
digital signature from a trusted authority. If you try, PowerShell displays the

reference/5.1/Microsoft.PowerShell.Utility/ConvertFrom-Json.md

Lines changed: 6 additions & 5 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: 11/29/2023
5+
ms.date: 01/30/2025
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/convertfrom-json?view=powershell-5.1&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: ConvertFrom-Json
@@ -35,10 +35,11 @@ To generate a JSON string from any object, use the `ConvertTo-Json` cmdlet.
3535
This cmdlet was introduced in PowerShell 3.0.
3636

3737
> [!NOTE]
38-
> Beginning with PowerShell 6, the cmdlet supports JSON with comments. JSON comments start with two
39-
> forward slashes (`//`) characters. JSON comments aren't captured in the objects output by the
40-
> cmdlet. Prior to PowerShell 6, `ConvertFrom-Json` would return an error when it encountered a JSON
41-
> comment.
38+
> In Windows PowerShell 5.1, `ConvertFrom-Json` returns an error when it encounters a JSON
39+
> comment. In PowerShell 6 and higher, the cmdlet supports JSON with comments. JSON comments aren't
40+
> captured in the objects output by the cmdlet. For more information, see the _JSON comments_
41+
> section of the
42+
> [about_Comments](/powershell/module/microsoft.powershell.core/about/about_comments) article.
4243
4344
## EXAMPLES
4445

reference/5.1/Microsoft.PowerShell.Utility/Invoke-RestMethod.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ The `Invoke-RestMethod` cmdlet sends HTTP and HTTPS requests to Representational
3232

3333
PowerShell formats the response based to the data type. For an RSS or ATOM feed, PowerShell returns
3434
the Item or Entry XML nodes. For JavaScript Object Notation (JSON) or XML, PowerShell converts, or
35-
deserializes, the content into `[PSCustomObject]` objects.
35+
deserializes, the content into `[PSCustomObject]` objects. Comments aren't permitted in the JSON
36+
data.
3637

3738
> [!NOTE]
3839
> When the REST endpoint returns multiple objects, the objects are received as an array. If you pipe
@@ -205,11 +206,11 @@ Accept wildcard characters: False
205206
206207
### -Certificate
207208
208-
Specifies the client certificate that is used for a secure web request. Enter a variable that
209+
Specifies the client certificate that's used for a secure web request. Enter a variable that
209210
contains a certificate or a command or expression that gets the certificate.
210211
211212
To find a certificate, use `Get-PfxCertificate` or use the `Get-ChildItem` cmdlet in the Certificate
212-
(`Cert:`) drive. If the certificate is not valid or does not have sufficient authority, the command
213+
(`Cert:`) drive. If the certificate isn't valid or doesn't have sufficient authority, the command
213214
fails.
214215

215216
```yaml
@@ -252,7 +253,7 @@ Accept wildcard characters: False
252253
Specifies the content type of the web request.
253254

254255
If this parameter is omitted and the request method is POST, `Invoke-RestMethod` sets the content
255-
type to "application/x-www-form-urlencoded". Otherwise, the content type is not specified in the
256+
type to `application/x-www-form-urlencoded`. Otherwise, the content type isn't specified in the
256257
call.
257258

258259
```yaml
@@ -305,7 +306,7 @@ Aliases:
305306
306307
Required: False
307308
Position: Named
308-
Default value: KeepAlive
309+
Default value: False
309310
Accept pipeline input: False
310311
Accept wildcard characters: False
311312
```
@@ -453,14 +454,14 @@ Accept wildcard characters: False
453454

454455
### -ProxyCredential
455456

456-
Specifies a user account that has permission to use the proxy server that is specified by the
457+
Specifies a user account that has permission to use the proxy server that's specified by the
457458
**Proxy** parameter. The default is the current user.
458459

459-
Type a user name, such as "User01" or "Domain01\User01", or enter a **PSCredential** object, such as
460-
one generated by the `Get-Credential` cmdlet.
460+
Type a user name, such as "User01" or "Domain01\User01", or enter a **PSCredential** object, such
461+
as one generated by the `Get-Credential` cmdlet.
461462

462-
This parameter is valid only when the **Proxy** parameter is also used in the command. You cannot
463-
use the **ProxyCredential** and **ProxyUseDefaultCredentials** parameters in the same command.
463+
This parameter is valid only when the **Proxy** parameter is also used in the command. You can't use
464+
the **ProxyCredential** and **ProxyUseDefaultCredentials** parameters in the same command.
464465

465466
```yaml
466467
Type: System.Management.Automation.PSCredential
@@ -479,8 +480,8 @@ Accept wildcard characters: False
479480
Uses the credentials of the current user to access the proxy server that is specified by the
480481
**Proxy** parameter.
481482

482-
This parameter is valid only when the **Proxy** parameter is also used in the command. You cannot
483-
use the **ProxyCredential** and **ProxyUseDefaultCredentials** parameters in the same command.
483+
This parameter is valid only when the **Proxy** parameter is also used in the command. You can't use
484+
the **ProxyCredential** and **ProxyUseDefaultCredentials** parameters in the same command.
484485

485486
```yaml
486487
Type: System.Management.Automation.SwitchParameter
@@ -576,7 +577,7 @@ Accept wildcard characters: False
576577

577578
### -Uri
578579

579-
Specifies the Uniform Resource Identifier (URI) of the Internet resource to which the web request is
580+
Specifies the Uniform Resource Identifier (URI) of the internet resource to which the web request is
580581
sent. This parameter supports HTTP, HTTPS, FTP, and FILE values.
581582

582583
This parameter is required. The parameter name (**Uri**) is optional.
@@ -630,12 +631,13 @@ Accept wildcard characters: False
630631

631632
Specifies a user agent string for the web request.
632633

633-
The default user agent is similar to "Mozilla/5.0 (Windows NT; Windows NT 6.1; en-US)
634-
WindowsPowerShell/3.0" with slight variations for each operating system and platform.
634+
The default user agent is similar to
635+
`Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.15063; en-US) PowerShell/6.0.0` with slight
636+
variations for each operating system and platform.
635637

636-
To test a website with the standard user agent string that is used by most Internet browsers, use
637-
the properties of the [PSUserAgent](/dotnet/api/microsoft.powershell.commands) class, such as
638-
Chrome, Firefox, Internet Explorer, Opera, and Safari.
638+
To test a website with the standard user agent string that's used by most internet browsers, use
639+
the properties of the [PSUserAgent](xref:Microsoft.PowerShell.Commands.PSUserAgent) class, such as
640+
Chrome, Firefox, InternetExplorer, Opera, and Safari.
639641

640642
```yaml
641643
Type: System.String
@@ -656,17 +658,17 @@ Specifies a web request session. Enter the variable name, including the dollar s
656658
To override a value in the web request session, use a cmdlet parameter, such as **UserAgent** or
657659
**Credential**. Parameter values take precedence over values in the web request session.
658660

659-
Unlike a remote session, the web request session is not a persistent connection. It is an object
660-
that contains information about the connection and the request, including cookies, credentials, the
661+
Unlike a remote session, the web request session isn't a persistent connection. It's an object that
662+
contains information about the connection and the request, including cookies, credentials, the
661663
maximum redirection value, and the user agent string. You can use it to share state and data among
662664
web requests.
663665

664-
To create a web request session, enter a variable name (without a dollar sign) in the value of the
666+
To create a web request session, enter a variable name, without a dollar sign, in the value of the
665667
**SessionVariable** parameter of an `Invoke-RestMethod` command. `Invoke-RestMethod` creates the
666668
session and saves it in the variable. In subsequent commands, use the variable as the value of the
667669
**WebSession** parameter.
668670

669-
You cannot use the **SessionVariable** and **WebSession** parameters in the same command.
671+
You can't use the **SessionVariable** and **WebSession** parameters in the same command.
670672

671673
```yaml
672674
Type: Microsoft.PowerShell.Commands.WebRequestSession

0 commit comments

Comments
 (0)