Skip to content

Commit 54b06e9

Browse files
authored
Merge pull request #4751 from davidsmatlak/ds-issue4725
Fixes #4725 - Added document cross-references
2 parents 2d3623e + e7541a2 commit 54b06e9

File tree

12 files changed

+690
-556
lines changed

12 files changed

+690
-556
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ being used, and the **ShouldProcess** method adds the **WhatIf** and
369369
**Confirm** parameters to the cmdlet dynamically.
370370

371371
For more information about the `$PSCmdlet` automatic variable, see
372-
[about_Functions_Advanced](about_Functions_Advanced.md).
372+
[about_Functions_CmdletBindingAttribute](about_Functions_CmdletBindingAttribute.md)
373+
and [about_Functions_Advanced](about_Functions_Advanced.md).
373374

374375
### $PSCommandPath
375376

@@ -417,7 +418,7 @@ selected objects in a pipeline.
417418

418419
Contains the directory from which a script is being run.
419420

420-
In PowerShell 2.0, this variable is valid only in script modules (.psm1).
421+
In PowerShell 2.0, this variable is valid only in script modules (`.psm1`).
421422
Beginning in PowerShell 3.0, it's valid in all scripts.
422423

423424
### $PSSenderInfo
@@ -843,6 +844,18 @@ Default (Current): End
843844

844845
## See also
845846

847+
[about_Functions](about_Functions.md)
848+
849+
[about_Functions_Advanced](about_Functions_Advanced.md)
850+
851+
[about_Functions_Advanced_Methods](about_Functions_Advanced_Methods.md)
852+
853+
[about_Functions_Advanced_Parameters](about_Functions_Advanced_Parameters.md)
854+
855+
[about_Functions_OutputTypeAttribute](about_Functions_OutputTypeAttribute.md)
856+
857+
[about_Functions_CmdletBindingAttribute](about_Functions_CmdletBindingAttribute.md)
858+
846859
[about_Hash_Tables](about_Hash_Tables.md)
847860

848861
[about_Preference_Variables](about_Preference_Variables.md)

reference/3.0/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Methods.md

Lines changed: 100 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ locale: en-us
55
keywords: powershell,cmdlet
66
title: about_Functions_Advanced_Methods
77
---
8+
89
# About Functions Advanced Methods
910

1011
## Short description
@@ -15,54 +16,64 @@ methods and properties that are available to compiled cmdlets.
1516
## Long description
1617

1718
Functions that specify the `CmdletBinding` attribute can access a number of
18-
methods and properties through the `$pscmdlet` variable. These methods include
19+
methods and properties through the `$PSCmdlet` variable. These methods include
1920
the following methods:
2021

2122
- Input-processing methods that compiled cmdlets use to do their work.
22-
- The `ShouldProcess` and `ShouldContinue` methods that are used to get
23-
user feedback before an action is performed.
23+
- The `ShouldProcess` and `ShouldContinue` methods that are used to get user
24+
feedback before an action is performed.
2425
- The `ThrowTerminatingError` method for generating error records.
25-
- Several Write methods that return different types of output.
26+
- Several `Write` methods that return different types of output.
27+
28+
All the methods and properties of the **PSCmdlet** class are available to
29+
advanced functions. For more information, see
30+
[System.Management.Automation.PSCmdlet](/dotnet/api/system.management.automation.pscmdlet).
2631

27-
All the methods and properties of the `PSCmdlet` class are available to
28-
advanced functions. For more information about these methods and properties,
29-
see [`System.Management.Automation.PSCmdlet`](http://go.microsoft.com/fwlink/?LinkId=142139) in the MSDN library.
32+
For more information about the `CmdletBinding` attribute, see
33+
[about_Functions_CmdletBindingAttribute](about_Functions_CmdletBindingAttribute.md).
34+
For the **CmdletBindingAttribute** class, see
35+
[System.Management.Automation.Cmdlet.CmdletBindingAttribute](/dotnet/api/system.management.automation.cmdletbindingattribute).
3036

31-
### Input Processing Methods
37+
### Input processing methods
3238

3339
The methods described in this section are referred to as the input processing
3440
methods. For functions, these three methods are represented by the `Begin`,
35-
`Process`, and `End` blocks of the function. You are not required to use
36-
any of these blocks in your functions.
41+
`Process`, and `End` blocks of the function. You aren't required to use any of
42+
these blocks in your functions.
3743

3844
> [!NOTE]
39-
> These blocks are also available to functions that do not use the
45+
> These blocks are also available to functions that don't use the
4046
> `CmdletBinding` attribute.
4147
4248
#### Begin
4349

44-
This block is used to provide optional one-time preprocessing for the
45-
function. The PowerShell runtime uses the code in this block one time
46-
for each instance of the function in the pipeline.
50+
This block is used to provide optional one-time preprocessing for the function.
51+
The PowerShell runtime uses the code in this block once for each instance of
52+
the function in the pipeline.
4753

4854
#### Process
4955

50-
This block is used to provide record-by-record processing for the function.
51-
You can use a `Process` block without defining the other blocks. The number
52-
of `Process` block executions depends on how you use the function and what
53-
input the function receives.
54-
55-
- Calling the function at the beginning, or outside of a pipeline, executes
56-
the `Process` block once.
57-
- Within a pipeline, the `Process` block executes once for each input
58-
object that reaches the function.
59-
- If the pipeline input that reaches the function is empty, the `Process`
60-
block does NOT execute.
56+
This block is used to provide record-by-record processing for the function. You
57+
can use a `Process` block without defining the other blocks. The number of
58+
`Process` block executions depends on how you use the function and what input
59+
the function receives.
60+
61+
The automatic variable `$_` or `$PSItem` contains the current object in the
62+
pipeline for use in the `Process` block. The `$input` automatic variable
63+
contains an enumerator that's only available to functions and script blocks.
64+
For more information, see [about_Automatic_Variables](about_Automatic_Variables.md).
65+
66+
- Calling the function at the beginning, or outside of a pipeline, executes the
67+
`Process` block once.
68+
- Within a pipeline, the `Process` block executes once for each input object
69+
that reaches the function.
70+
- If the pipeline input that reaches the function is empty, the `Process` block
71+
**does not** execute.
6172
- The `Begin` and `End` blocks still execute.
6273

6374
> [!IMPORTANT]
6475
> If a function parameter is set to accept pipeline input, and a `Process`
65-
> block is not defined, record-by-record processing will fail. In this case,
76+
> block isn't defined, record-by-record processing will fail. In this case,
6677
> your function will only execute once, regardless of the input.
6778
6879
#### End
@@ -87,128 +98,124 @@ Function Test-ScriptCmdlet
8798

8899
> [!NOTE]
89100
> Using either a `Begin` or `End` block requires that you define all three
90-
> blocks. When using all three blocks, all PowerShell code must be inside
91-
> one of the blocks.
101+
> blocks. When using all three blocks, all PowerShell code must be inside one
102+
> of the blocks.
92103
93-
### Confirmation Methods
104+
### Confirmation methods
94105

95106
#### ShouldProcess
96107

97-
This method is called to request confirmation from the user before the
98-
function performs an action that would change the system. The function can
99-
continue based on the Boolean value returned by the method. This method can
100-
only be called only from within the `Process{}` block of the function. The
108+
This method is called to request confirmation from the user before the function
109+
performs an action that would change the system. The function can continue
110+
based on the Boolean value returned by the method. This method can only be
111+
called only from within the `Process{}` block of the function. The
101112
`CmdletBinding` attribute must also declare that the function supports
102113
`ShouldProcess` (as shown in the previous example).
103114

104115
For more information about this method, see
105-
[`System.Management.Automation.Cmdlet.ShouldProcess`](http://go.microsoft.com/fwlink/?LinkId=142142)
106-
in the MSDN library.
116+
[System.Management.Automation.Cmdlet.ShouldProcess](/dotnet/api/system.management.automation.cmdlet.shouldprocess).
107117

108118
For more information about how to request confirmation, see
109-
[Requesting Confirmation](http://go.microsoft.com/fwlink/?LinkID=136658)
110-
in the MSDN library.
119+
[Requesting Confirmation](/powershell/developer/cmdlet/requesting-confirmation).
111120

112121
#### ShouldContinue
113122

114123
This method is called to request a second confirmation message. It should be
115124
called when the `ShouldProcess` method returns `$true`. For more information
116-
about this method, see `System.Management.Automation.Cmdlet.ShouldContinue` in
117-
the MSDN library at http://go.microsoft.com/fwlink/?LinkId=142143.
125+
about this method, see
126+
[System.Management.Automation.Cmdlet.ShouldContinue](/dotnet/api/system.management.automation.cmdlet.shouldcontinue).
118127

119-
### Error Methods
128+
### Error methods
120129

121130
Functions can call two different methods when errors occur. When a
122131
non-terminating error occurs, the function should call the `WriteError` method,
123-
which is described in the "Write Methods" section. When a terminating error
124-
occurs and the function cannot continue, it should call the
132+
which is described in the `Write` methods section. When a terminating error
133+
occurs and the function can't continue, it should call the
125134
`ThrowTerminatingError` method. You can also use the `Throw` statement for
126-
terminating errors and the `Write-Error` cmdlet for nonterminating errors.
135+
terminating errors and the [Write-Error](../../Microsoft.PowerShell.Utility/Write-Error.md)
136+
cmdlet for non-terminating errors.
127137

128138
For more information, see
129-
[`System.Management.Automation.Cmdlet.ThrowTerminatingError`](http://go.microsoft.com/fwlink/?LinkId=142144)
130-
in the MSDN libray.
139+
[System.Management.Automation.Cmdlet.ThrowTerminatingError](/dotnet/api/system.management.automation.cmdlet.throwterminatingerror).
131140

132-
### Write Methods
141+
### Write methods
133142

134143
A function can call the following methods to return different types of output.
135144
Notice that not all the output goes to the next command in the pipeline. You
136-
can also use the various Write cmdlets, such as Write-Error.
145+
can also use the various `Write` cmdlets, such as `Write-Error`.
137146

138147
#### WriteCommandDetail
139148

140149
For information about the `WriteCommandDetails` method, see
141-
[`System.Management.Automation.Cmdlet.WriteCommandDetail`](http://go.microsoft.com/fwlink/?LinkId=142155)
142-
in the MSDN library.
150+
[System.Management.Automation.Cmdlet.WriteCommandDetail](/dotnet/api/system.management.automation.cmdlet.writecommanddetail).
143151

144152
#### WriteDebug
145153

146154
To provide information that can be used to troubleshoot a function, make the
147-
function call the `WriteDebug` method. This displays debug messages to the
148-
user. For more information, see
149-
[`System.Management.Automation.Cmdlet.WriteDebug`](http://go.microsoft.com/fwlink/?LinkId=142156)
150-
in the MSDN library.
155+
function call the `WriteDebug` method. The `WriteDebug` method displays debug
156+
messages to the user. For more information, see
157+
[System.Management.Automation.Cmdlet.WriteDebug](/dotnet/api/system.management.automation.cmdlet.writedebug).
151158

152159
#### WriteError
153160

154-
Functions should call this method when nonterminating errors occur and the
161+
Functions should call this method when non-terminating errors occur and the
155162
function is designed to continue processing records. For more information, see
156-
[`System.Management.Automation.Cmdlet.WriteError`](http://go.microsoft.com/fwlink/?LinkId=142157)
157-
in the MSDN library.
163+
[System.Management.Automation.Cmdlet.WriteError](/dotnet/api/system.management.automation.cmdlet.writeerror).
158164

159-
Note: If a terminating error occurs, the function should call the
160-
`ThrowTerminatingError` method.
165+
> [!NOTE]
166+
> If a terminating error occurs, the function should call the
167+
> [ThrowTerminatingError](/dotnet/api/system.management.automation.cmdlet.throwterminatingerror)
168+
> method.
161169
162170
#### WriteObject
163171

164-
This method allows the function to send an object to the next command in the
165-
pipeline. In most cases, this is the method to use when the function returns
166-
data. For more information, see
167-
[`System.Management.Automation.PSCmdlet.WriteObject`](http://go.microsoft.com/fwlink/?LinkId=142158)
168-
in the MSDN library.
172+
The `WriteObject` method allows the function to send an object to the next
173+
command in the pipeline. In most cases, `WriteObject` is the method to use when
174+
the function returns data. For more information, see
175+
[System.Management.Automation.PSCmdlet.WriteObject](/dotnet/api/system.management.automation.cmdlet.writeobject).
169176

170177
#### WriteProgress
171178

172-
For functions whose actions take a long time to complete, this method allows
173-
the function to call the `WriteProgress` method so that progress information
174-
is displayed. For example, you can display the percent completed. For more
175-
information, see [`System.Management.Automation.PSCmdlet.WriteProgress`](http://go.microsoft.com/fwlink/?LinkId=142160)
176-
in the MSDN library.
179+
For functions with actions that take a long time to complete, this method
180+
allows the function to call the `WriteProgress` method so that progress
181+
information is displayed. For example, you can display the percent completed.
182+
For more information, see
183+
[System.Management.Automation.PSCmdlet.WriteProgress](/dotnet/api/system.management.automation.cmdlet.writeprogress).
177184

178185
#### WriteVerbose
179186

180187
To provide detailed information about what the function is doing, make the
181188
function call the `WriteVerbose` method to display verbose messages to the
182-
user. By default, verbose messages are not displayed. For more information,
183-
see
184-
[`System.Management.Automation.PSCmdlet.WriteVerbose`](http://go.microsoft.com/fwlink/?LinkId=142162)
185-
in the MSDN library.
189+
user. By default, verbose messages aren't displayed. For more information, see
190+
[System.Management.Automation.PSCmdlet.WriteVerbose](/dotnet/api/system.management.automation.cmdlet.writeverbose).
186191

187192
#### WriteWarning
188193

189-
To provide information about conditions that may cause unexpected results,
190-
make the function call the WriteWarning method to display warning messages to
191-
the user. By default, warning messages are displayed. For more information,
192-
see [`System.Management.Automation.PSCmdlet.WriteWarning`](http://go.microsoft.com/fwlink/?LinkId=142164)
193-
in the MSDN library.
194+
To provide information about conditions that may cause unexpected results, make
195+
the function call the WriteWarning method to display warning messages to the
196+
user. By default, warning messages are displayed. For more information, see
197+
[System.Management.Automation.PSCmdlet.WriteWarning](/dotnet/api/system.management.automation.cmdlet.writewarning).
194198

195-
Note: You can also display warning messages by configuring the
196-
`WarningPreference` variable or by using the `Verbose` and `Debug`
197-
command-line options.
199+
> [!NOTE]
200+
> You can also display warning messages by configuring the `$WarningPreference`
201+
> variable or by using the `Verbose` and `Debug` command-line options. for more
202+
> information about the `$WarningPreference` variable, see [about_Preference_Variables](about_Preference_Variables.md).
203+
204+
### Other methods and properties
198205

199-
### Other Methods and Properties
206+
For information about the other methods and properties that can be accessed
207+
through the `$PSCmdlet` variable, see
208+
[System.Management.Automation.PSCmdlet](/dotnet/api/system.management.automation.pscmdlet).
200209

201-
For information about the other methods and properties that can be
202-
accessed through the `$PSCmdlet` variable, see
203-
[`System.Management.Automation.PSCmdlet`](http://go.microsoft.com/fwlink/?LinkId=142139)
204-
in the MSDN library.
210+
For example, the
211+
[ParameterSetName](/dotnet/api/system.management.automation.pscmdlet.parametersetname)
212+
property allows you to see the parameter set that is being used. Parameter sets
213+
allow you to create a function that performs different tasks based on the
214+
parameters that are specified when the function is run.
205215

206-
For example, the `ParameterSetName` property allows you to see the parameter
207-
set that is being used. Parameter sets allow you to create a function that
208-
performs different tasks based on the parameters that are specified when the
209-
function is run.
216+
## See also
210217

211-
## SEE ALSO
218+
[about_Automatic_Variables](about_Automatic_Variables.md)
212219

213220
[about_Functions](about_Functions.md)
214221

@@ -218,4 +225,6 @@ function is run.
218225

219226
[about_Functions_CmdletBindingAttribute](about_Functions_CmdletBindingAttribute.md)
220227

221-
[about_Functions_OutputTypeAttribute](about_Functions_OutputTypeAttribute.md)
228+
[about_Functions_OutputTypeAttribute](about_Functions_OutputTypeAttribute.md)
229+
230+
[about_Preference_Variables](about_Preference_Variables.md)

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ being used, and the **ShouldProcess** method adds the **WhatIf** and
369369
**Confirm** parameters to the cmdlet dynamically.
370370

371371
For more information about the `$PSCmdlet` automatic variable, see
372-
[about_Functions_Advanced](about_Functions_Advanced.md).
372+
[about_Functions_CmdletBindingAttribute](about_Functions_CmdletBindingAttribute.md)
373+
and [about_Functions_Advanced](about_Functions_Advanced.md).
373374

374375
### $PSCommandPath
375376

@@ -417,7 +418,7 @@ selected objects in a pipeline.
417418

418419
Contains the directory from which a script is being run.
419420

420-
In PowerShell 2.0, this variable is valid only in script modules (.psm1).
421+
In PowerShell 2.0, this variable is valid only in script modules (`.psm1`).
421422
Beginning in PowerShell 3.0, it's valid in all scripts.
422423

423424
### $PSSenderInfo
@@ -843,6 +844,18 @@ Default (Current): End
843844

844845
## See also
845846

847+
[about_Functions](about_Functions.md)
848+
849+
[about_Functions_Advanced](about_Functions_Advanced.md)
850+
851+
[about_Functions_Advanced_Methods](about_Functions_Advanced_Methods.md)
852+
853+
[about_Functions_Advanced_Parameters](about_Functions_Advanced_Parameters.md)
854+
855+
[about_Functions_OutputTypeAttribute](about_Functions_OutputTypeAttribute.md)
856+
857+
[about_Functions_CmdletBindingAttribute](about_Functions_CmdletBindingAttribute.md)
858+
846859
[about_Hash_Tables](about_Hash_Tables.md)
847860

848861
[about_Preference_Variables](about_Preference_Variables.md)

0 commit comments

Comments
 (0)