PS> get-help about_functions_advanced
...
get-help About_Functions_CmdletBindingAttribute
...
PS> [CmdletBinding] example-foo
Unexpected token 'example-foo' in expression or statement.
At line:1 char:28
+ [CmdletBinding] example-foo <<<<
+ CategoryInfo : ParserError: (example-foo:String) [],
ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
PS> function example()
>> {
>> [CmdletBinding]
>>
>> [Parameter(Mandatory=$true)]
>> [string] $server
>> [Parameter(Mandatory=$false)]
>> [string] $user
>> [Parameter(Mandatory=$true)]
>> [boolean] $enable
>> [Parameter(Mandatory=$false)]
>> [boolean] $verbose
>> Process
>> {
>> '& cscript "test.wsf" //Job:"example" @psBoundParameters'
>> }
>> }
>>
PS> example
Unable to find type [CmdletBinding]: make sure that the assembly containing
this type is loaded.
At line:3 char:20
+ [CmdletBinding] <<<<
+ CategoryInfo : InvalidOperation: (CmdletBinding:String) [],
RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar
JL> The following syntax can be parsed but I must be doing something
JL> wrong..
JL>
PS>> function example()
PS>>
>>> {
>>> [CmdletBinding]
>>> [Parameter(Mandatory=$true)]
>>> [string] $server
>>> [Parameter(Mandatory=$false)]
>>> [string] $user
>>> [Parameter(Mandatory=$true)]
>>> [boolean] $enable
>>> [Parameter(Mandatory=$false)]
>>> [boolean] $verbose
>>> Process
>>> {
>>> '& cscript "test.wsf" //Job:"example" @psBoundParameters'
>>> }
>>> }
PS>> example
PS>>
JL> Unable to find type [CmdletBinding]: make sure that the assembly
JL> containing
JL> this type is loaded.
JL> At line:3 char:20
JL> + [CmdletBinding] <<<<
JL> + CategoryInfo : InvalidOperation:
JL> (CmdletBinding:String) [],
JL> RuntimeException
JL> + FullyQualifiedErrorId : TypeNotFound
[CmdletBinding(SupportsShouldProcess=<Boolean>,
SupportsTransactions=<Boolean>,
ConfirmImpact=<String>,
DefaultParameterSetName=<String>)]
SupportsShouldProcess:
When set to $true, the function can support –confirm and –whatif
SupportsTransactions:
When set to $true, the function can support transactions
ConfirmImpact:
High, Medium, Low, or None
DefaultParameterSetName:
The name of the default parameter set.
---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar
SL> [CmdletBinding()]
SL>
SL> ---
SL> Shay Levy
SL> Windows PowerShell MVP
SL> http://blogs.microsoft.co.il/blogs/ScriptFanatic
SL> PowerShell Toolbar: http://tinyurl.com/PSToolbar
function example() {
[CmdletBinding()]
PARAM(
[Parameter(Mandatory=$true)]
[string]$server,
[Parameter(Mandatory=$false)]
[string]$user,
[Parameter(Mandatory=$true)]
[boolean]$enable,
[Parameter(Mandatory=$false)]
[boolean]$verbose
)
PROCESS {
"..."
}
}
And I just found out overriding default parameters is a little more
complicated
PS> get-help example
Get-Help : A parameter with the name 'Verbose' was defined multiple times
for the command.
At line:1 char:9
+ get-help <<<< example
+ CategoryInfo : MetadataError: (:) [Get-Help],
MetadataException
+ FullyQualifiedErrorId :
ParameterNameAlreadyExistsForCommand,Microsoft.PowerShell.Commands.GetHelpCommand
"Shay Levy [MVP]" <n...@addre.ss> wrote in message
news:95d808935ed358...@news.microsoft.com...
--
Joel "Jaykul" Bennett
http://HuddledMasses.org
What does this attribute actually do?
--
Thomas Lee
doct...@gmail.com
MVP - Admin Frameworks and Security
SupportsShouldProcess
DefaultParameterSet
ConfirmImpact
See also these help files:
About_Functions_CmdletBinding
About_Functions_CmdletBindingAttribute
---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar
TL> In message <95d808935ed2b8...@news.microsoft.com>, Shay
TL> Levy <?@addre.ss.invalid> writes
TL>
>> [CmdletBinding()]
>>
TL> What does this attribute actually do?
TL>