bat文件中的powershell和参数

时间:2015-01-29 15:54:19

标签: powershell batch-file

我无法在批处理文件中使用参数输入来运行我的powershell。有什么想法吗?

示例命令。一切都失败了:

  1. C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe .\Migrate.ps1 '\\\server\Shared\MSK Directory' '\\\server1\Shared\MSK Directory'

  2. C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe .\Migrate.ps1 "\\\server\Shared\MSK Directory" "\\\server1\Shared\MSK Directory"

  3. C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe .\Migrate.ps1 &"\\\server\Shared\MSK Directory" &"\\\server1\Shared\MSK Directory"

1 个答案:

答案 0 :(得分:0)

它适用于我,但你的UNC路径是错误的。 UNC路径只需要两个反斜杠。您还应确保与脚本位于同一文件夹中,否则,请使用完整路径。另外,我建议在调用脚本文件时使用-File参数。

powershell.exe -File .\Migrate.ps1 '\\server\Shared\MSK Directory' '\\server1\Shared\MSK Directory'

演示:

Untitled3.ps1

param($to, $from)

Write-Host "To: '$to'"
Write-Host "From: '$from'"

输出:

powershell .\Untitled3.ps1 '\\server\Shared\MSK Directory' '\\server1\Shared\MSK Directory'

To: '\\server\Shared\MSK Directory'
From: '\\server1\Shared\MSK Directory'

使用-File

powershell -File .\Untitled3.ps1 "\\server\Shared\MSK Directory" "\\server1\Shared\MSK Directory"

To: '\\server\Shared\MSK Directory'
From: '\\server1\Shared\MSK Directory'