Skip to content

Commit 71a8603

Browse files
authored
Merge pull request #11645 from MicrosoftDocs/main
1/7/2025 PM Publish
2 parents 2043a7e + 9fa040c commit 71a8603

File tree

12 files changed

+577
-487
lines changed

12 files changed

+577
-487
lines changed

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

Lines changed: 84 additions & 84 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Provides information about how PowerShell background jobs run a command or expression in the background without interacting with the current session.
33
Locale: en-US
4-
ms.date: 08/29/2022
4+
ms.date: 01/07/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_jobs?view=powershell-5.1&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Jobs
@@ -242,7 +242,7 @@ results would be incomplete. You can use the `Receive-Job` cmdlet repeatedly to
242242
get all of the results. Use the **State** property to determine when the job is
243243
complete.
244244

245-
You can also use the **Wait** parameter of the `Receive-Job` cmdlet. When use
245+
You can also use the **Wait** parameter of the `Receive-Job` cmdlet. When you
246246
use this parameter, the cmdlet doesn't return the command prompt until the job
247247
is completed and all results are available.
248248

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

Lines changed: 44 additions & 40 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: 10/23/2023
4+
ms.date: 01/07/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
@@ -33,33 +33,39 @@ PowerShell checks the Authenticode signature of the following type types:
3333
- `.xaml` XAML script files
3434

3535
For more information about PowerShell execution policies, see
36-
[about_Execution_Policies][01].
36+
[about_Execution_Policies][03].
3737

38-
## To permit signed scripts to run
38+
## Permit the execution of signed scripts
3939

4040
When you start PowerShell on a computer for the first time, the **Restricted**
4141
execution policy, which is the default, is likely to be in effect.
4242

43-
The **Restricted** policy doesn't permit any scripts to run.
43+
The **Restricted** policy prevents all scripts from running.
4444

4545
To find the effective execution policy on your computer, type:
4646

4747
```powershell
4848
Get-ExecutionPolicy
4949
```
5050

51-
To run unsigned scripts that you write on your local computer and signed
52-
scripts from other users, start PowerShell with the **Run as Administrator**
53-
option and then use the following command to change the execution policy on the
54-
computer to **RemoteSigned**:
51+
The **RemoteSigned** policy allows you to run signed scripts or unsigned
52+
scripts that you create locally. To configure this policy, start PowerShell
53+
with the **Run as Administrator** option and then use the following command to
54+
change the execution policy.
5555

5656
```powershell
5757
Set-ExecutionPolicy RemoteSigned
5858
```
5959

6060
For more information, see the help topic for the `Set-ExecutionPolicy` cmdlet.
6161

62-
## Running unsigned scripts using the RemoteSigned execution policy
62+
To run a signed script, the script must have a digital signature from a trusted
63+
publisher. The code signing certificate must be issued by a certification
64+
must be issued by a certification authority that is trusted on the computer.
65+
Self-signed certificates must be installed in the **Trusted Root Certificates**
66+
store on the computer.
67+
68+
## Run unsigned scripts using the RemoteSigned policy
6369

6470
If your PowerShell execution policy is **RemoteSigned**, PowerShell won't run
6571
unsigned scripts that are downloaded from the internet, including unsigned
@@ -85,7 +91,7 @@ procedure.
8591
1. Right-click the script file, and then click **Properties**.
8692
1. Click **Unblock**.
8793

88-
If a script that was downloaded from the internet is digitally signed, but you
94+
If a script that you downloaded from the internet is digitally signed, but you
8995
haven't yet chosen to trust its publisher, PowerShell displays the following
9096
message:
9197

@@ -110,10 +116,8 @@ You can sign the scripts that you write and the scripts that you get from other
110116
sources. Before you sign any script, examine each command to verify that it's
111117
safe to run.
112118

113-
For best practices about code signing, see [Code-Signing Best Practices][02].
114-
115119
For more information about how to sign a script file, see
116-
[Set-AuthenticodeSignature][03].
120+
[Set-AuthenticodeSignature][06].
117121

118122
The `New-SelfSignedCertificate` cmdlet, introduced in the PKI module in
119123
PowerShell 3.0, creates a self-signed certificate that's appropriate for
@@ -136,10 +140,11 @@ certificate. Two types of certificates are suitable for signing a script file:
136140
on your computer. However, a script signed by a self-signed certificate will
137141
not run on other computers.
138142

139-
Typically, you would use a self-signed certificate only to sign scripts that
140-
you write for your own use and to sign scripts that you get from other sources
141-
that you have verified to be safe. It isn't appropriate for scripts that will
142-
be shared, even within an enterprise.
143+
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.
143148

144149
If you create a self-signed certificate, be sure to enable strong private key
145150
protection on your certificate. This prevents malicious programs from signing
@@ -148,7 +153,7 @@ topic.
148153

149154
## Create a self-signed certificate
150155

151-
To create a self-signed certificate, use the [New-SelfSignedCertificate][04]
156+
To create a self-signed certificate, use the [New-SelfSignedCertificate][08]
152157
cmdlet in the PKI module. This module is introduced in PowerShell 3.0. For more
153158
information, see the help topic for the `New-SelfSignedCertificate` cmdlet.
154159

@@ -169,7 +174,7 @@ Certificate Creation tool `MakeCert.exe`. This tool is included in the
169174
Microsoft .NET SDK (versions 1.1 and later) and in the Microsoft Windows SDK.
170175

171176
For more information about the syntax and the parameter descriptions of the
172-
`MakeCert.exe` tool, see [Certificate Creation Tool (MakeCert.exe)][05].
177+
`MakeCert.exe` tool, see [Certificate Creation Tool (MakeCert.exe)][01].
173178

174179
To use the `MakeCert.exe` tool to create a certificate, run the following
175180
commands in an SDK Command Prompt window.
@@ -201,7 +206,7 @@ a certificate file in the file system directory.
201206
At the PowerShell prompt, type:
202207

203208
```powershell
204-
Get-ChildItem cert:\CurrentUser\my -codesigning
209+
Get-ChildItem cert:\CurrentUser\my -CodeSigning
205210
```
206211

207212
This command uses the PowerShell Certificate provider to view information
@@ -229,10 +234,9 @@ you are using the **AllSigned** execution policy, you must sign the
229234
`Add-Signature.ps1` script before you run it.
230235

231236
> [!IMPORTANT]
232-
> The script must be saved using ASCII or UTF8NoBOM encoding. You can sign a
233-
> script file that uses a different encoding, but the script fails to run or
234-
> the module containing the script fails to import. The script will also fail
235-
> if the file contains Unicode (UTF8) characters.
237+
> Before PowerShell 7.2, the script must be saved using ASCII or UTF8NoBOM
238+
> encoding. PowerShell 7.2 and higher supports signed scripts for any encoding
239+
> format.
236240
237241
To use this script, copy the following text into a text file, and name it
238242
`Add-Signature.ps1`.
@@ -321,19 +325,19 @@ stamp server ensures that users can use your script for many years to come.
321325

322326
## See also
323327

324-
- [about_Execution_Policies][01]
325-
- [about_Profiles][06]
326-
- [Set-AuthenticodeSignature][03]
327-
- [Get-ExecutionPolicy][07]
328-
- [Set-ExecutionPolicy][08]
329-
- [Introduction to Code Signing][09]
330-
331-
[01]: about_Execution_Policies.md
332-
[02]: /previous-versions/windows/hardware/design/dn653556(v=vs.85)
333-
[03]: xref:Microsoft.PowerShell.Security.Set-AuthenticodeSignature
334-
[04]: xref:pki.New-SelfSignedCertificate
335-
[05]: /previous-versions/dotnet/netframework-2.0/bfsktky3(v=vs.80)
336-
[06]: about_Profiles.md
337-
[07]: xref:Microsoft.PowerShell.Security.Get-ExecutionPolicy
338-
[08]: xref:Microsoft.PowerShell.Security.Set-ExecutionPolicy
339-
[09]: /previous-versions/windows/internet-explorer/ie-developer/platform-apis/ms537361(v=vs.85)
328+
- [about_Execution_Policies][03]
329+
- [about_Profiles][04]
330+
- [Set-AuthenticodeSignature][06]
331+
- [Get-ExecutionPolicy][05]
332+
- [Set-ExecutionPolicy][07]
333+
- [Introduction to Code Signing][02]
334+
335+
<!-- link references -->
336+
[01]: /previous-versions/dotnet/netframework-2.0/bfsktky3(v=vs.80)
337+
[02]: /previous-versions/windows/internet-explorer/ie-developer/platform-apis/ms537361(v=vs.85)
338+
[03]: about_Execution_Policies.md
339+
[04]: about_Profiles.md
340+
[05]: xref:Microsoft.PowerShell.Security.Get-ExecutionPolicy
341+
[06]: xref:Microsoft.PowerShell.Security.Set-AuthenticodeSignature
342+
[07]: xref:Microsoft.PowerShell.Security.Set-ExecutionPolicy
343+
[08]: xref:pki.New-SelfSignedCertificate

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

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
---
22
description: Describes how to use the `try`, `catch`, and `finally` blocks to handle terminating errors.
33
Locale: en-US
4-
ms.date: 11/12/2021
4+
ms.date: 01/07/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_try_catch_finally?view=powershell-5.1&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Try_Catch_Finally
88
---
99
# about_Try_Catch_Finally
1010

1111
## Short description
12+
1213
Describes how to use the `try`, `catch`, and `finally` blocks to handle
1314
terminating errors.
1415

1516
## Long description
1617

1718
Use `try`, `catch`, and `finally` blocks to respond to or handle terminating
1819
errors in scripts. The `Trap` statement can also be used to handle terminating
19-
errors in scripts. For more information, see [about_Trap](about_Trap.md).
20+
errors in scripts. For more information, see [about_Trap][05].
2021

2122
A terminating error stops a statement from running. If PowerShell does not
2223
handle a terminating error in some way, PowerShell also stops running the
@@ -71,9 +72,9 @@ Error types appear in brackets. The outermost brackets indicate the element is
7172
optional.
7273

7374
The `catch` keyword is followed by an optional list of error type
74-
specifications and a statement list. If a terminating error occurs in the
75-
`try` block, PowerShell searches for an appropriate `catch` block. If
76-
one is found, the statements in the `catch` block are executed.
75+
specifications and a statement list. If a terminating error occurs in the `try`
76+
block, PowerShell searches for an appropriate `catch` block. If one is found,
77+
the statements in the `catch` block are executed.
7778

7879
The `catch` block can specify one or more error types. An error type is a
7980
Microsoft .NET Framework exception or an exception that is derived from a .NET
@@ -117,7 +118,7 @@ block.
117118
PowerShell does not recognize "NonsenseString" as a cmdlet or other item.
118119
Running this script returns the following result:
119120

120-
```powershell
121+
```Output
121122
An error occurred.
122123
```
123124

@@ -132,16 +133,13 @@ two `catch` blocks:
132133

133134
```powershell
134135
try {
135-
$wc = new-object System.Net.WebClient
136-
$wc.DownloadFile("http://www.contoso.com/MyDoc.doc","c:\temp\MyDoc.doc")
137-
}
138-
catch [System.Net.WebException],[System.IO.IOException] {
136+
$wc = New-Object System.Net.WebClient
137+
$wc.DownloadFile("http://www.contoso.com/MyDoc.doc","c:\temp\MyDoc.doc")
138+
} catch [System.Net.WebException],[System.IO.IOException] {
139139
"Unable to download MyDoc.doc from http://www.contoso.com."
140-
}
141-
catch {
140+
} catch {
142141
"An error occurred that could not be resolved."
143142
}
144-
145143
```
146144

147145
The first `catch` block handles errors of the **System.Net.WebException** and
@@ -155,8 +153,9 @@ from the specified class. The following example contains a `catch` block that
155153
catches a "Command Not Found" error:
156154

157155
```powershell
158-
catch [System.Management.Automation.CommandNotFoundException]
159-
{"Inherited Exception" }
156+
catch [System.Management.Automation.CommandNotFoundException] {
157+
"Inherited Exception"
158+
}
160159
```
161160

162161
The specified error type, **CommandNotFoundException**, inherits from the
@@ -181,23 +180,23 @@ block for the derived class before the `catch` block for the general class.
181180
## Using Traps in a Try Catch
182181

183182
When a terminating error occurs in a `try` block with a `Trap` defined within
184-
the `try` block, even if there is a matching `catch` block, the `Trap` statement
185-
takes control.
183+
the `try` block, even if there is a matching `catch` block, the `Trap`
184+
statement takes control.
186185

187186
If a `Trap` exists at a higher block than the `try`, and there is no matching
188187
`catch` block within the current scope, the `Trap` will take control, even if
189188
any parent scope has a matching `catch` block.
190189

191190
## Accessing exception information
192191

193-
Within a `catch` block, the current error can be accessed using `$_`, which
194-
is also known as `$PSItem`. The object is of type **ErrorRecord**.
192+
Within a `catch` block, the current error can be accessed using `$_`, which is
193+
also known as `$PSItem`. The object is of type **ErrorRecord**.
195194

196195
```powershell
197196
try { NonsenseString }
198197
catch {
199-
Write-Host "An error occurred:"
200-
Write-Host $_
198+
Write-Host "An error occurred:"
199+
Write-Host $_
201200
}
202201
```
203202

@@ -210,21 +209,21 @@ script file, or operable program. Check the spelling of the name, or if a path
210209
was included, verify that the path is correct and try again.
211210
```
212211

213-
There are additional properties that can be accessed, such as **ScriptStackTrace**,
214-
**Exception**, and **ErrorDetails**. For example, if we change the script to the
215-
following:
212+
There are additional properties that can be accessed, such as
213+
**ScriptStackTrace**, **Exception**, and **ErrorDetails**. For example, if we
214+
change the script to the following:
216215

217216
```powershell
218217
try { NonsenseString }
219218
catch {
220-
Write-Host "An error occurred:"
221-
Write-Host $_.ScriptStackTrace
219+
Write-Host "An error occurred:"
220+
Write-Host $_.ScriptStackTrace
222221
}
223222
```
224223

225224
The result will be similar to:
226225

227-
```
226+
```Output
228227
An Error occurred:
229228
at <ScriptBlock>, <No file>: line 2
230229
```
@@ -240,10 +239,37 @@ A `finally` block runs even if you use <kbd>CTRL</kbd>+<kbd>C</kbd> to stop the
240239
script. A `finally` block also runs if an Exit keyword stops the script from
241240
within a `catch` block.
242241

242+
In the following example, the `try` block attempts to download a file to the
243+
`c:\temp` folder. The `catch` blocks handle errors that occur during the
244+
download. The `finally` block disposes of the `WebClient` object and removes
245+
the temporary file if it exists.
246+
247+
```powershell
248+
try {
249+
$wc = New-Object System.Net.WebClient
250+
$tempFile = "c:\temp\MyDoc.doc"
251+
$wc.DownloadFile("http://www.contoso.com/MyDoc.doc",$tempFile)
252+
} catch [System.Net.WebException],[System.IO.IOException] {
253+
"Unable to download MyDoc.doc from http://www.contoso.com."
254+
} catch {
255+
"An error occurred that could not be resolved."
256+
} finally {
257+
$wc.Dispose()
258+
if (Test-Path $tempPath) { Remove-item $tempFile }
259+
}
260+
```
261+
243262
## See also
244263

245-
- [about_Break](about_Break.md)
246-
- [about_Continue](about_Continue.md)
247-
- [about_Scopes](about_Scopes.md)
248-
- [about_Throw](about_Throw.md)
249-
- [about_Trap](about_Trap.md)
264+
- [about_Break][01]
265+
- [about_Continue][02]
266+
- [about_Scopes][03]
267+
- [about_Throw][04]
268+
- [about_Trap][05]
269+
270+
<!-- link references -->
271+
[01]: about_Break.md
272+
[02]: about_Continue.md
273+
[03]: about_Scopes.md
274+
[04]: about_Throw.md
275+
[05]: about_Trap.md

0 commit comments

Comments
 (0)