0

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 v5 Commented Jun 21, 2016 at 9:08

1 Answer 1

1

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 
Sign up to request clarification or add additional context in comments.

3 Comments

I am unable to select v3 on the UI for some reason
so if not later then v3, change your script to Get-WmiObject, as explained.
I ended up being able to clear the cache and restarted the program. The v3 button became clickable. Thanks for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.