PowerShell vs PowerShell ISE



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

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

您知道为什么会发生这种情况吗?

我尝试创建一个单行文件

powershell_ise.exe -File D:script.ps1

powershell.exe -File D:script.ps1

但两者都不起作用。我已经检查了政策,但我有不受限制的政策。

我试过跑

C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -NonInteractive -Command d:Script.ps1

在PowerShell ISE中,它工作正常。

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

术语"▬"不被识别为 cmdlet、函数、脚本文件、或可操作的程序。检查名称的拼写,或者是否包含路径,验证路径是否正确,然后重试。行:1 字符:1
$datetime = Get-Date -f yyyMMdd
$strFileName = "c:testBS_" + $datetime + ".txt"
if (Test-Path $strFileName) {
  exit
} else {
  exit
}
...

get-date cmdlet 没有 -format 的别名

请使用以下语法

$datetime = Get-Date -format "yyyyMMdd"

问题出在

 $datetime = Get-date -f yyyymmdd

呵,我用错了"-"。谢谢大家的建议

最新更新