0
votes

I have a powershell script that runs and compiles within the powershell ISE. However, I need to compress it into an .exe so that the users that will use my application can open it easily. To do this I have found that I should use either primalcript or primalforms. The problem is that when I try to run the script, certain cmdlets output error messages on either of these two programs.

For example the line:

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

Returns this in PrimalScript:

ERROR: Get-CimInstance : The term 'Get-CimInstance' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again At C:\Users\sieredzkian\Desktop\New folder\User_Launched_Application_3.ps1:166 char:31 + $freeRam = Get-CimInstance <<<< -ClassName win32_operatingsystem | Select-Object -expand FreePhysicalMemory + CategoryInfo : ObjectNotFound: (Get-CimInstance:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

Whereas in powershell it runs...

Why can it not find the cmdlets? It also does this for a few other cmdlets like Out-GridView

EDIT: My original problem was caused by using primalscript 2011 where only powershell V2 was supported. I was able to fix this by installing the trial version of primalscript 2016. This enabled me to have powershell V3 like I was using in the ISE.

1
Did you set a powershell version preference? Primalscript (2016) should compile code up to Powershell v5Martin

1 Answers

1
votes

Get-CimInstance Require PowerShell version 3 and later... make sure you set it in the PowerShell version menu

Serach for this menu

Another option (in case your PowerShell version is 2 or less) is to use Get-WmiObject instead of Get-CimInstance so it should looks like:

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