【问题标题】:So what is special about Powershell PSC1 files?那么 Powershell PSC1 文件有什么特别之处呢?
【发布时间】:2011-11-22 01:18:25
【问题描述】:

在我的 PowerShell 快捷方式中,我有以下内容:

C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -psc "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noe -c ". \"C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\""

不过,我更愿意添加管理单元注册并在我的配置文件中运行 PowerCLI 环境的初始化。

所以在我的个人资料中添加以下内容:

Add-PSSnapin VMware.VimAutomation.Core
& "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1"

然而,Get-VICommand 不再可用此方法。为什么?

【问题讨论】:

    标签: powershell powercli


    【解决方案1】:

    PSC1 文件是“PowerShell 控制台文件”。它们是 XML 配置文件,用于告诉 PowerShell 自动加载哪些管理单元。另一种方法是在您的Profile.ps1 脚本中调用Import-ModuleAdd-PSSnapin

    您可以使用Export-Console 创建自己的 psc1 文件。

    【讨论】:

      【解决方案2】:

      试试这样:

      add-pssnapin VMware.VimAutomation.Core
      
      . 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1' # dot sourcing!
      

      【讨论】:

      • ^ 这行得通,但它确实减慢了 powershell 初始化所需的时间。特别是如果您运行的是 Powershell 3.0,我个人在 powershell、power-cli 和常规命令提示符上有默认的 powershell 控制台参数,每个参数都有不同的背景颜色以避免混淆。
      猜你喜欢
      • 2016-04-01
      • 2016-01-21
      • 1970-01-01
      • 2011-04-18
      • 2017-02-19
      • 2016-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多