我想跳过启动成绩单,停止转录本线,如果PowerShell脚本由Powersehll ISE运行。
这可能吗?我怎样才能做到这一点?
你可以做:
if ($host.name -eq 'ConsoleHost') # or -notmatch 'ISE'
{
.. do something ..
}
else
{
.. do something else..
}
知道这是相当长的一段前询问,并标记为已回答,但多了一个办法:
function Test-IsISE {
# try...catch accounts for:
# Set-StrictMode -Version latest
try {
return $psISE -ne $null;
}
catch {
return $false;
}
}
$ psISE可在ISE:
下面是查找qazxsw POI的存在,而不会产生异常的方法:
$psISE
另一种方法...
if (Test-Path variable:global:psISE)
{
...
}
这些都是伟大的答案!下面是我用$ host.name方式
我需要一种方法来:
使用ReadKey在我的脚本与PowerShell的ISE(不会在ISE工作),但仍然能够使用(和运行)的脚本。有办法让脚本知道它是否在控制台或ISE和激活ReadKey或分别读主机。
下面是该代码:
Try {
Start-Transcript -Path <somepath> | Out-Null
}
Catch [System.Management.Automation.PSNotSupportedException] {
# The current PowerShell Host doesn't support transcribing
}