Get-WMIObject and Get-CimInstance not working

Hi there PSU community!

I’m brand spanking new to PSU and starting to mess around with scripts.

I’m running a simple get-ciminstance and getting an error.

Command I run.

“Get-CimInstance -ClassName Win32_ComputerSystem | select -ExpandProperty username”

The Error

[error] The ‘Get-CimInstance’ command was found in the module ‘CimCmdlets’, but the module could not be loaded. For more information, run ‘Import-Module CimCmdlets’.

I’m sure this is something I haven’t configured correctly but this is a very powerful tool and I’m getting a little lost.

Thank you!

Welcome!

Can you verify what environment you’re running in? The Default environment will run in the Integrated environment. That means the script runs within the PSU server. If you switch to either 7.x (if installed) or 5.1, do you have a similar issue?

That was exactly the issue. Thank you! If I could trouble you for one more, could you point me in the right direction on how to call scripts from a dashboard I’d greatly appreciate it. Thank you!

The PowerShell Universal module is automatically loaded into Dashboards. You can use those cmdlets to invoke scripts.

You will need an app token to do so. You can automatically grant one:

Or you can manually create one:

Thank you!

So there’s something I"m not understading with the app token piece. Here’s my dashboard code

New-PSUDashboard -Name ‘Dashboard’ -BaseUrl ‘/test’ -Framework “UniversalDashboard:Latest” -Authenticated -GrantAppToken

$Pages = @()

$Pages += New-UDPage -Name ‘Paradigm Preceision’ -Content {

"This is the landing page!"

}

$Pages += New-UDPage -Name ‘Script Test’ -Content {

New-UDButton -Text 'Job' -OnClick {

    Invoke-UAScript -Name 'wmitest.ps1'

}

}

New-UDDashboard -Pages $Pages -Title ‘Dashboard’

Here’s my error.

error occurred: Cannot retrieve the dynamic parameters for the cmdlet. Call failed with status code 401 (Unauthorized): GET http://localhost:5000/api/v1/Script/wmitest.ps1

Endpoint: 1293f7e8-56b9-4f32-89ee-1a1621b05c51

Session: 177c3fdd-cc01-47bb-8b6f-c809f22ab8cd

File:

Endpoint Start Line: 2

Endpoint End Line: 4

Stack Trace: at , : line 2

Try adding the app token and URL to the invoke.

Invoke-UAScript -Name 'wmitest.ps1' -AppToken $AppToken -ComputerName "http://localhost:5000"

I figured it out. I had to put -GrantAppToken in dashboard configuration .ps1. It wasn’t stated in the documentation so I was confused. I appreciate all of your help! Really great tool!

Ah, ok. I’ll get that cleaned up in the docs.