Primalscript / Primalforms无法识别powershell cmdlet

时间:2016-06-21 08:17:55

标签: powershell

我有一个PowerShell脚本,可以在powershell ISE中运行和编译。但是,我需要将其压缩为.exe,以便使用我的应用程序的用户可以轻松打开它。要做到这一点,我发现我应该使用primalcript或primalforms。问题是,当我尝试运行脚本时,某些cmdlet会在这两个程序中输出错误消息。

例如行:

$freeRam = Get-CimInstance -ClassName win32_operatingsystem | 
Select-Object -expand FreePhysicalMemory

在PrimalScript中返回:

  

错误:Get-CimInstance:无法识别“Get-CimInstance”一词   作为cmdlet,函数,脚本文件或可运行程序的名称。   检查名称的拼写,或者如果包含路径,请验证   路径是正确的,然后再次尝试在C:\ Users \ sieredzkian \ Desktop \ New   folder \ User_Launched_Application_3.ps1:166 char:31 + $ freeRam =   Get-CimInstance<<<< -ClassName win32_operatingsystem |选择-对象   -expand FreePhysicalMemory + CategoryInfo:ObjectNotFound:(Get-CimInstance:String)[],CommandNotFoundException +   FullyQualifiedErrorId:CommandNotFoundException

而在powershell中它运行...

为什么找不到cmdlet?它也适用于像Out-GridView

这样的其他几个cmdlet

编辑: 我原来的问题是由使用primalscript 2011引起的,其中只支持powershell V2。我能够通过安装primalscript 2016的试用版来解决这个问题。这使我能够拥有像我在ISE中使用的PowerShell V3。

1 个答案:

答案 0 :(得分:1)

Get-CimInstance需要PowerShell版本3及更高版本...确保在PowerShell版本菜单中设置它

Serach for this menu

另一个选项(如果你的PowerShell版本是2或更低)是使用Get-WmiObject而不是Get-CimInstance所以它应该是这样的:

$freeRam = Get-WmiObject -ClassName win32_operatingsystem | Select-Object -expand FreePhysicalMemory