2017-01-13 26 views
-1

タスクスケジューラでPowerShellスクリプトを実行する際に問題があります。 PowerShell ISEでスクリプトを作成しても問題ありません。PowerShellとPowerShell ISE

しかし、PowerShellで実行すると、いくつかの間違いが報告されます。

これはなぜ起こり得るのですか?

私は

powershell_ise.exe -File D:\script.ps1 

または

powershell.exe -File D:\script.ps1 

で単一行ファイルを作成しようとしました。しかし、それのどちらも動作します。 ポリシーを確認しましたが、制限はありません。

私はPowerShellのISEに

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

を実行しようとしている、それが正常に動作します。私はPowerShellでそれを実行すると

は、それがエラーを示しています。-formatため

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 
} 

... 
+1

「いくつかの間違いがあります」というエラーメッセージが含まれているのでしょうか。それらは問題に関連していないと思います。何故ですか? – vonPryz

+0

.ps1ファイルはダッシュ '--'で始まりますか? – vonPryz

+0

いいえ、BS_test.ps1 – HeadOverFeet

答えて

0

get-dateコマンドレットは持っていないとエイリアス

以下の構文を使用してください

$datetime = Get-Date -format "yyyyMMdd" 
+0

あなたはまあまあですが、間違いは " - "でしたが、-fでもうまくいきます。 – HeadOverFeet

+0

上記のコードで何を達成しようとしていますか? – YanivK

0

問題があった

$datetime = Get-date -f yyyymmdd 

私は間違った " - "を使用しました。アドバイスありがとうございました

関連する問題