PowerShell与PowerShell ISE

时间:2017-01-13 07:06:10

标签: powershell

我遇到在任务计划程序中运行PowerShell脚本的问题。 我在PowerShell ISE中创建了脚本,它运行正常。

但是当我通过PowerShell运行它时会报告一些错误。

你有什么想法可以解决这个问题吗?

我尝试使用

创建单行文件
powershell_ise.exe -File D:\script.ps1

powershell.exe -File D:\script.ps1

但它都不起作用。 我已经检查了政策,但我没有限制。

我试图运行

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -Command d:\Script.ps1

在PowerShell ISE中,它运行正常。

当我在PowerShell中运行它时会显示错误:

The term '▬' is not recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
At line:1 char:1
$datetime = Get-Date -f yyyMMdd

$strFileName = "c:\test\BS_" + $datetime + ".txt"

if (Test-Path $strFileName) {
  exit
} else {
  exit
}

...

2 个答案:

答案 0 :(得分:0)

get-date cmdlet没有-format

的别名

请使用以下语法

$datetime = Get-Date -format "yyyyMMdd"

答案 1 :(得分:0)

问题在于

 $datetime = Get-date -f yyyymmdd

我用错了“ - ”。谢谢大家的建议