Powershell参数if else

时间:2016-12-09 06:20:30

标签: powershell-v3.0

     var data1=[
["2016-01-01", 0, 20.0],
["2016-01-01", 1, 9.0],
["2016-01-01", 2, 10.0]

]
为什么我的其他声明不起作用?我只得到if ######语句的结果,我运行get-shares或get-shares localhost

1 个答案:

答案 0 :(得分:0)

您一定要查看Get-Help About_Function_Advanced

在这里,您可以在Param()块本身中提及$ ComputerName的默认值。 并且允许null属性必须在Param块中提到n =,而不是在

之外
Param(
[AllowNull()]
$ComputerName = 'localhost'
)

如果$ComputerName ID为localhost,则无需使用gwmi -computername $ComputerName,只需gwmi -Class Win32_Share即可。

这里的主要问题是,即使您提到$ComputerName的值,它也会被$ComputerNme = 'localhost'替换,并且仅在传递时才会被替换。

此致

kvprasoon