2017-12-18 267 views
0

我有一个bat.file,我打电话给我的ps1脚本。 我就会犯路径PS1脚本如何从批处理提交路径变量到ps1

蝙蝠:

... 
set path="\\wka-wn-stda3\xKarten\A\" 
PowerShell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%~dpn0.ps1'" 

PS1:

$path="\\wka-wn-stda3\xKarten\A\" 
... 

我会从批处理文件中PS1-里面的路径文件。我怎么能意识到这一点? 希望有人能帮助我!

回答

0
  1. 阅读并遵守about_Environment_Variables

您还可以显示和更改环境变量的值 不使用cmdlet的使用Windows PowerShell中的表达式解析器。要显示的环境变量的值,可以使用 以下语法:

$Env:<variable-name> 
  • 不要设置%PATH%环境变量任意地,读%PATH% command
  • %PATH%环境变量包含文件夹列表。当在CMD提示符处发出 命令时,操作系统将首先在当前文件夹中查找可执行文件,如果未找到,则 将扫描%PATH%以查找它。

  • 应用set "varname=value"语法,而不是 set varname="value" (的"双引号注的位置)。例如:
  • ==> set var="%cd%" 
    
    ==> powershell -noprofile -command (Get-Childitem $env:var -filter "*.ps1").Name 
    Get-Childitem : Cannot find drive. A drive with the name '"d' does not exist. 
    At line:1 char:2 
    + (Get-Childitem $env:var -filter *.ps1).Name 
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
        + CategoryInfo   : ObjectNotFound: ("d:String) [Get-ChildItem], DriveNotFoundException 
        + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand 
    
    
    ==> set "var=%cd%" 
    
    ==> powershell -noprofile -command (Get-Childitem "$env:var" -filter "*.ps1").Name 
    cliparser.ps1 
    
    ==>