2017-04-25 143 views
2

PowerShell有一个名为$ShellId的内置变量。它在#Requires documentation中提到,它是RunspaceConfiguration的财产。但是我找不到有关它应该做什么的文档。我可以在#Requires声明中指定它的事实表明它有一些预期的目的,但我找不到什么。什么是ShellId?我为什么需要它?

$ShellId的用途是什么?在什么情况下,我会使它成为我的脚本的依赖项?

+1

请参阅[本文](https://www.simple-talk.com/sysadmin/powershell/persistent-powershell-the-powershell-profile/)。 – wOxxOm

回答

1

首先我想让你了解The Shell and The Host之间的区别。

无论我们在ISE或PSConsole中运行什么,它们都是主机。

#Requires –ShellId Microsoft.PowerShell --- 这使用默认的PowerShell Shell。

当你测试$ shellid,控制台和ISE都返回Microsoft.PowerShell。

您可以指定本地shell,如:

#requires –ShellId MyLocalShell 

如果它是一个独立的外壳,不论控制台和inturns使用PowerShell引擎在后端,那么我们需要shellId基本。主要在运行空间。

$ shellId包含当前shell的标识符。

相关问题