Skip to content

Commit 740d5e1

Browse files
davidsmatlaksdwheeler
authored andcommitted
Fixes #4518 - Added the Assembly parameter to about_Requires (#4879)
* issue 4518 * removed broken links, fixed Output tag * fixed Assembly parameter description
1 parent 5b83405 commit 740d5e1

File tree

6 files changed

+195
-97
lines changed

6 files changed

+195
-97
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ locale: en-us
55
keywords: powershell,cmdlet
66
title: about_Requires
77
---
8+
89
# About Requires
910

1011
## Short description
1112
Prevents a script from running without the required elements.
1213

1314
## Long description
1415

15-
The `#Requires` statement prevents a script from running unless the
16-
PowerShell version, modules (and version), or snap-ins (and version)
17-
prerequisites are met. If the prerequisites are not met, PowerShell
18-
does not run the script.
16+
The `#Requires` statement prevents a script from running unless the PowerShell
17+
version, modules (and version), or snap-ins (and version) prerequisites are
18+
met. If the prerequisites aren't met, PowerShell doesn't run the script.
1919

2020
### Syntax
2121

@@ -48,7 +48,7 @@ Example:
4848
#Requires -Modules Hyper-V
4949
```
5050

51-
You might think that the above code should not run because the required module
51+
You might think that the above code shouldn't run because the required module
5252
was removed before the `#Requires` statement. However, the `#Requires` state
5353
had to be met before the script could even execute. Then the first line of the
5454
script invalidated the required state.
@@ -82,8 +82,8 @@ For example:
8282
Specifies PowerShell modules that the script requires. Enter the module name
8383
and an optional version number.
8484

85-
If the required modules are not in the current session, PowerShell imports
86-
them. If the modules cannot be imported, PowerShell throws a terminating error.
85+
If the required modules aren't in the current session, PowerShell imports them.
86+
If the modules can't be imported, PowerShell throws a terminating error.
8787

8888
For each module, type the module name (\<String\>) or a hash table. The value
8989
can be a combination of strings and hash tables. The hash table has the
@@ -110,8 +110,9 @@ Require that any version of `PSScheduledJob` and `PSWorkflow` are installed.
110110
#### -ShellId
111111

112112
Specifies the shell that the script requires. Enter the shell ID. If you use
113-
the **ShellId** parameter you must also include the **PSSnapin** parameter. You
114-
can find current ShellId by querying `$ShellId` automatic variable.
113+
the **ShellId** parameter, you must also include the **PSSnapin** parameter.
114+
You can find the current **ShellId** by querying the `$ShellId` automatic
115+
variable.
115116

116117
For example:
117118

@@ -121,12 +122,11 @@ For example:
121122

122123
> [!NOTE]
123124
> This parameter is intended for use in mini-shells, which have been deprecated.
124-
You can find current ShellId by querying `$ShellId` automatic variable.
125125
126126
### Examples
127127

128128
The following script has two `#Requires` statements. If the requirements
129-
specified in both statements are not met, the script does not run. Each
129+
specified in both statements aren't met, the script doesn't run. Each
130130
`#Requires` statement must be the first item on a line:
131131

132132
```powershell
@@ -143,10 +143,10 @@ Param
143143

144144
### Notes
145145

146-
In Windows PowerShell 3.0, the Windows PowerShell Core packages appear as
147-
modules in sessions started by using the InitialSessionState.CreateDefault2
148-
method, such as sessions started in the Windows PowerShell console. Otherwise,
149-
they appear as snap-ins. The exception is Microsoft.PowerShell.Core, which is
146+
In Windows PowerShell 3.0, the PowerShell Core packages appear as modules in
147+
sessions started by using the **InitialSessionState.CreateDefault2** method,
148+
such as sessions started in the Windows PowerShell console. Otherwise, they
149+
appear as snap-ins. The exception is `Microsoft.PowerShell.Core`, which is
150150
always a snap-in.
151151

152152
## See also

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ locale: en-us
55
keywords: powershell,cmdlet
66
title: about_Requires
77
---
8+
89
# About Requires
910

1011
## Short description
1112
Prevents a script from running without the required elements.
1213

1314
## Long description
1415

15-
The `#Requires` statement prevents a script from running unless the
16-
PowerShell version, modules (and version), or snap-ins (and version)
17-
prerequisites are met. If the prerequisites are not met, PowerShell
18-
does not run the script.
16+
The `#Requires` statement prevents a script from running unless the PowerShell
17+
version, modules (and version), or snap-ins (and version) prerequisites are
18+
met. If the prerequisites aren't met, PowerShell doesn't run the script.
1919

2020
### Syntax
2121

@@ -49,7 +49,7 @@ Example:
4949
#Requires -Modules Hyper-V
5050
```
5151

52-
You might think that the above code should not run because the required module
52+
You might think that the above code shouldn't run because the required module
5353
was removed before the `#Requires` statement. However, the `#Requires` state
5454
had to be met before the script could even execute. Then the first line of the
5555
script invalidated the required state.
@@ -83,8 +83,8 @@ For example:
8383
Specifies PowerShell modules that the script requires. Enter the module name
8484
and an optional version number.
8585

86-
If the required modules are not in the current session, PowerShell imports
87-
them. If the modules cannot be imported, PowerShell throws a terminating error.
86+
If the required modules aren't in the current session, PowerShell imports them.
87+
If the modules can't be imported, PowerShell throws a terminating error.
8888

8989
For each module, type the module name (\<String\>) or a hash table. The value
9090
can be a combination of strings and hash tables. The hash table has the
@@ -111,8 +111,9 @@ Require that any version of `PSScheduledJob` and `PSWorkflow` are installed.
111111
#### -ShellId
112112

113113
Specifies the shell that the script requires. Enter the shell ID. If you use
114-
the **ShellId** parameter you must also include the **PSSnapin** parameter. You
115-
can find current ShellId by querying `$ShellId` automatic variable.
114+
the **ShellId** parameter, you must also include the **PSSnapin** parameter.
115+
You can find the current **ShellId** by querying the `$ShellId` automatic
116+
variable.
116117

117118
For example:
118119

@@ -139,7 +140,7 @@ For example:
139140
### Examples
140141

141142
The following script has two `#Requires` statements. If the requirements
142-
specified in both statements are not met, the script does not run. Each
143+
specified in both statements aren't met, the script doesn't run. Each
143144
`#Requires` statement must be the first item on a line:
144145

145146
```powershell

reference/5.0/Microsoft.PowerShell.Core/About/about_Requires.md

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,32 @@ locale: en-us
55
keywords: powershell,cmdlet
66
title: about_Requires
77
---
8+
89
# About Requires
910

1011
## Short description
1112
Prevents a script from running without the required elements.
1213

1314
## Long description
1415

15-
The `#Requires` statement prevents a script from running unless the
16-
PowerShell version, modules (and version), or snap-ins (and version)
17-
prerequisites are met. If the prerequisites are not met, PowerShell
18-
does not run the script.
16+
The `#Requires` statement prevents a script from running unless the PowerShell
17+
version, modules (and version), or snap-ins (and version) prerequisites are
18+
met. If the prerequisites aren't met, PowerShell doesn't run the script.
1919

2020
### Syntax
2121

2222
```
23+
#Requires -Assembly { <Path to .dll> | <.NET assembly specification> }
2324
#Requires -Version <N>[.<n>]
2425
#Requires -PSSnapin <PSSnapin-Name> [-Version <N>[.<n>]]
2526
#Requires -Modules { <Module-Name> | <Hashtable> }
2627
#Requires -ShellId <ShellId> -PSSnapin <PSSnapin-Name> [-Version <N>[.<n>]]
2728
#Requires -RunAsAdministrator
2829
```
2930

31+
For more information about the syntax, see
32+
[ScriptRequirements](/dotnet/api/system.management.automation.language.scriptrequirements).
33+
3034
### Rules for use
3135

3236
A script can include more than one `#Requires` statement. The `#Requires`
@@ -49,13 +53,30 @@ Example:
4953
#Requires -Modules Hyper-V
5054
```
5155

52-
You might think that the above code should not run because the required module
56+
You might think that the above code shouldn't run because the required module
5357
was removed before the `#Requires` statement. However, the `#Requires` state
5458
had to be met before the script could even execute. Then the first line of the
5559
script invalidated the required state.
5660

5761
### Parameters
5862

63+
#### -Assembly \<Assembly path> | \<.NET assembly specification>
64+
65+
Specifies the path to the assembly DLL file or a .NET assembly name. The
66+
**Assembly** parameter was introduced in PowerShell 5.0. For more information
67+
about .NET assemblies, see [Assembly names](/dotnet/standard/assembly/names).
68+
69+
For example:
70+
71+
```
72+
#Requires -Assembly path\to\foo.dll
73+
```
74+
75+
```
76+
#Requires -Assembly "System.Management.Automation, Version=3.0.0.0,
77+
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
78+
```
79+
5980
#### -Version \<N\>[.\<n\>]
6081

6182
Specifies the minimum version of PowerShell that the script requires. Enter a
@@ -83,22 +104,22 @@ For example:
83104
Specifies PowerShell modules that the script requires. Enter the module name
84105
and an optional version number.
85106

86-
If the required modules are not in the current session, PowerShell imports
87-
them. If the modules cannot be imported, PowerShell throws a terminating error.
107+
If the required modules aren't in the current session, PowerShell imports them.
108+
If the modules can't be imported, PowerShell throws a terminating error.
88109

89110
For each module, type the module name (\<String\>) or a hash table. The value
90111
can be a combination of strings and hash tables. The hash table has the
91112
following keys.
92113

93114
- `ModuleName` - **Required** Specifies the module name.
94115
- `GUID` - **Optional** Specifies the GUID of the module.
95-
- It is also **Required** to specify one of the two below keys. These keys
96-
cannot be used together.
116+
- It's also **Required** to specify one of the two below keys. These keys can't
117+
be used together.
97118
- `ModuleVersion` - Specifies a minimum acceptable version of the module.
98119
- `RequiredVersion` - Specifies an exact, required version of the module.
99120

100121
> [!NOTE]
101-
> `RequiredVersion` was added in Windows PowerShell 5.0.
122+
> `RequiredVersion` was added in PowerShell 5.0.
102123
103124
For example:
104125

@@ -127,13 +148,14 @@ the version string you wish to require.
127148
Get-Module Hyper-V
128149
```
129150

130-
```output
151+
```Output
131152
ModuleType Version Name ExportedCommands
132153
---------- ------- ---- ------------------
133154
Binary 2.0.0.0 hyper-v {Add-VMAssignableDevice, ...}
134155
```
135156

136-
This will **FAIL**, because "2.0.0" does not exactly match "2.0.0.0"
157+
The following example fails because **2.0.0** doesn't exactly match
158+
**2.0.0.0**.
137159

138160
```powershell
139161
#Requires -Modules @{ ModuleName="Hyper-V"; RequiredVersion="2.0.0" }
@@ -142,8 +164,9 @@ This will **FAIL**, because "2.0.0" does not exactly match "2.0.0.0"
142164
#### -ShellId
143165

144166
Specifies the shell that the script requires. Enter the shell ID. If you use
145-
the **ShellId** parameter you must also include the **PSSnapin** parameter. You
146-
can find current ShellId by querying `$ShellId` automatic variable.
167+
the **ShellId** parameter, you must also include the **PSSnapin** parameter.
168+
You can find the current **ShellId** by querying the `$ShellId` automatic
169+
variable.
147170

148171
For example:
149172

@@ -156,10 +179,11 @@ For example:
156179
157180
#### -RunAsAdministrator
158181

159-
When this switch parameter is added to your requires statement, it specifies
160-
that the Windows PowerShell session in which you are running the script must
161-
be started with elevated user rights (Run as Administrator).
162-
The RunAsAdministrator parameter is introduced in Windows PowerShell 4.0.
182+
When this switch parameter is added to your `#Requires` statement, it specifies
183+
that the PowerShell session in which you're running the script must be started
184+
with elevated user rights. The **RunAsAdministrator** parameter is ignored on a
185+
non-Windows operating system. The **RunAsAdministrator** parameter was
186+
introduced in PowerShell 4.0.
163187

164188
For example:
165189

@@ -170,7 +194,7 @@ For example:
170194
### Examples
171195

172196
The following script has two `#Requires` statements. If the requirements
173-
specified in both statements are not met, the script does not run. Each
197+
specified in both statements aren't met, the script doesn't run. Each
174198
`#Requires` statement must be the first item on a line:
175199

176200
```powershell
@@ -193,4 +217,4 @@ Param
193217

194218
[about_PSSnapins](about_PSSnapins.md)
195219

196-
[Get-PSSnapin](../Get-PSSnapin.md)
220+
[Get-PSSnapin](../Get-PSSnapin.md)

0 commit comments

Comments
 (0)