简体   繁体   English

PowerShell 与 PowerShell ISE

[英]PowerShell vs PowerShell ISE

I have a problem of running my PowerShell script in Task Scheduler.我在任务计划程序中运行我的 PowerShell 脚本时遇到问题。 I created script in PowerShell ISE and it works fine.我在 PowerShell ISE 中创建了脚本,它运行良好。

But when I run it by PowerShell it reports some mistakes.但是当我用 PowerShell 运行它时,它报告了一些错误。

Do you have any ideas why this can happen?你知道为什么会发生这种情况吗?

I have tried to create a single line file with我试图创建一个单行文件

powershell_ise.exe -File D:\script.ps1

or或者

powershell.exe -File D:\script.ps1

But neither of it works.但两者都不起作用。 I have checked policy, but I have it unrestricted.我检查了政策,但我没有限制。

I have tried to run我试过跑

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

in PowerShell ISE and it works fine.在 PowerShell ISE 中,它工作正常。

When I run it in PowerShell it shows error:当我在 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
}

...

The get-date cmdlet doesn't have and alias for -format get-date cmdlet 没有 -format 的别名

Please use the below syntax请使用以下语法

$datetime = Get-Date -format "yyyyMMdd"

The problem was with问题是

 $datetime = Get-date -f yyyymmdd

whehe I used wrong "-".我用错了“-”。 Thank you all for advices谢谢大家的建议

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM