1.向程序传递参数
param
(
    
    [string]
$hostName
    
#how many servers to create
     [int]$serverNumber=8,
    [string]
$actions="both"
)
通过在此处直接复制,可以实现类似可选参数的功能。这里提到了类似,就是这个参数我们还是一定要有的。加入我们希望让¥hostname是可选参数,即可以为空,此时就无法实现,运行时会提示没有参数,此功能在powershell2中有相应的方法可以解决

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表示目录

相关文章:

  • 2021-11-09
  • 2021-12-10
  • 2022-01-11
  • 2021-08-31
  • 2021-08-02
  • 2021-07-02
  • 2021-11-05
猜你喜欢
  • 2022-02-04
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2022-01-03
  • 2021-11-19
  • 2022-02-03
相关资源
相似解决方案