1.向程序传递参数
2.测试目录或者文件是否存在
param
(
[string]$hostName,
#how many servers to create
[int]$serverNumber=8,
[string]$actions="both"
)
通过在此处直接复制,可以实现类似可选参数的功能。这里提到了类似,就是这个参数我们还是一定要有的。加入我们希望让¥hostname是可选参数,即可以为空,此时就无法实现,运行时会提示没有参数,此功能在powershell2中有相应的方法可以解决(
[string]$hostName,
#how many servers to create
[int]$serverNumber=8,
[string]$actions="both"
)
2.测试目录或者文件是否存在
if(!(test-path ".\NetworkSwitch.vbs" -pathtype Leaf))
{
Write-Host -ForegroundColor Red "Couldn't find the NetworkSwitch.vbs. Please check the current path."
return
}
此处主要是-pathtype这个参数,leaf表示文件,containor表示目录
{
Write-Host -ForegroundColor Red "Couldn't find the NetworkSwitch.vbs. Please check the current path."
return
}
浙公网安备 33010602011771号