Powershell switch type parameters
来源:互联网 发布:js url 编码 编辑:程序博客网 时间:2024/05/23 11:52
Copied from msgoodies blog, thanks.
http://msgoodies.blogspot.hk/2006/12/negating-powershell-switch-parameters.html
Below examples should tell it all.
set-psdebug -trace 1
# f1 is a normal function with a switch parameter
function f1([switch] $showOutput) {
if ($showOutput.isPresent) {
"f1"
}
}
# f2 is a function with a switch parameter defaulted to present
function f2([switch] $showOutput=[switch]::present) {
if ($showOutput.isPresent) {
"f2"
}
}
# f3 is a function with a switch parameter defaulted to true, this gives the same result
# as using [switch]::present
function f3([switch] $showOutput=$true) {
if ($showOutput.isPresent) {
"f3"
}
}
# run f1, no output shown
f1
# run f1, show output
f1 -showOutput
# run f2, show output
f2
# run f2, show output
f2 -showOutput
# run f2, no output
f2 -showOutput:$false
# run f3, same behavior as f2
f3
f3 -showOutput
f3 -showOutput:$false
# Show the acceptable values for a switch parameter
f2 -showOutput:no
# f2 : Cannot convert value "System.String" to type "System.Management.Automation.SwitchParameter",
# parameters of this type only accept booleans or numbers, use $true, $false, 1 or 0 instead.
# At line:1 char:16
# + f2 -showOutput:n <<<< o
- Powershell switch type parameters
- Windows PowerShell: Defining Parameters
- PowerShell之Switch语句
- Type in PowerShell
- C# - Passing Reference-Type Parameters
- Method Parameters And Type Conversion
- C++ non type template parameters
- 使用switch制作Powershell命令菜单
- Grails Goodness: Type Conversion on Parameters
- Passing Reference-Type Parameters (C# Programming Guide)
- Powershell commands 祥解之 Add-Type
- Parameters
- Parameters
- Parameters
- parameters
- [From msdn] Constraints on Type Parameters (C# Programming Guide)
- Constraints on Type Parameters (what does where T : class mean)
- Why C++ Supports both Class and Typename for Type Parameters
- tar命令的详细解释
- 十六进制转换为十进制,二进制转换为十进制
- 剖析Path侧边栏抽屉效果原理(抽屉效果,Path效果)
- 对象的特点
- 黑马程序员——Java中的方法重写与方法重载的区别
- Powershell switch type parameters
- 配置Memcache服务器并实现主从复制功能(repcached)
- Android之BaseAdapter适配器使用技巧
- c++学习总结
- 将封装了envi功能的IDL类导出成java类,方便java调用
- QQ 静态截图程序模拟实现 之 URL记录
- Ubuntu 创建桌面启动器
- 河内塔的递归算法的分析
- ipad弹出窗口