How to run a Powershell script from the command line and pass a directory as a parameter

前端 未结 6 1113
醉梦人生
醉梦人生 2020-12-24 04:40
PowerShell -Command .\\Foo.ps1
  • Foo.ps1:

    
    
            
6条回答
  •  孤城傲影
    2020-12-24 05:12

    Add the param declation at the top of ps1 file

    test.ps1

    param(
      # Our preferred encoding
      [parameter(Mandatory=$false)]
      [ValidateSet("UTF8","Unicode","UTF7","ASCII","UTF32","BigEndianUnicode")]
      [string]$Encoding = "UTF8"
    )
    
    write ("Encoding : {0}" -f $Encoding)
    

    result

    C:\temp> .\test.ps1 -Encoding ASCII
    Encoding : ASCII
    

提交回复
热议问题