PowerShellスクリプトがPowersehll ISEによって実行されている場合、Start-Transcript、Stop-Transcript行をスキップします。スクリプトがPowerShell ISEによって実行されているかどうかを確認する方法はありますか?
これは可能ですか?そして私はこれをどのように達成することができますか?
PowerShellスクリプトがPowersehll ISEによって実行されている場合、Start-Transcript、Stop-Transcript行をスキップします。スクリプトがPowerShell ISEによって実行されているかどうかを確認する方法はありますか?
これは可能ですか?そして私はこれをどのように達成することができますか?
あなたは行うことができます。
if ($host.name -eq 'ConsoleHost') # or -notmatch 'ISE'
{
.. do something ..
}
else
{
.. do something else..
}
別の代替...
Try {
Start-Transcript -Path <somepath> | Out-Null
}
Catch [System.Management.Automation.PSNotSupportedException] {
# The current PowerShell Host doesn't support transcribing
}
が、これはかなり長い間前に聞くと、すでに答えとしてマークされていた知っているが、もう一つの方法:
をfunction Test-IsISE {
# try...catch accounts for:
# Set-StrictMode -Version latest
try {
return $psISE -ne $null;
}
catch {
return $false;
}
}
$ psISEはISEで利用可能です:
ここでの例外生成せず$psISE
のexistance探しの方法です:
if (Test-Path variable:global:psISE)
{
...
}
は