Powershell not working under Windows 7 #2

Closed
opened 2021-04-23 11:58:55 -04:00 by efrick · 4 comments
Owner

When run under Windows 7 the following error occurs:

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 line:52 char:26
+     $cs = Get-CimInstance <<<<  -ClassName Win32_ComputerSystem
    + CategoryInfo          : ObjectNotFound: (Get-CimInstance:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

The script is currently working fine under Windows 10.

When run under Windows 7 the following error occurs: ```powershell 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 line:52 char:26 + $cs = Get-CimInstance <<<< -ClassName Win32_ComputerSystem + CategoryInfo : ObjectNotFound: (Get-CimInstance:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException ``` The script is currently working fine under Windows 10.
efrick added the
bug
label 2021-04-23 12:03:40 -04:00
efrick self-assigned this 2021-04-23 12:03:47 -04:00
Author
Owner

I'm not sure if this is going to nessitate rewriting the script to use WMIC commands.
If it does it may mean keeping this current version of the powershell and copying the logic over as the text formatting with WMIC is very different and was a complete pain.

I'm not sure if this is going to nessitate rewriting the script to use WMIC commands. If it does it may mean keeping this current version of the powershell and copying the logic over as the text formatting with WMIC is very different and was a complete pain.
Author
Owner

It is posible to determin loosely with the following PS.

$os_name = wmic os get Caption
if( $os_name[2] -like "Microsoft Windows 7*" ){
    $output = "It's Win7 Jerry!!! `n" + $os_name[2]
} else {
    $output = "It's a computer Jerry!!!`nI don't know what the hell it is.`n" + $os_name[2]
}

Write-Output $output

On a Windows 7 machine it will output:

It's Win7 Jerry!!! 
Microsoft Windows 7 Professional

I will determin if this is an actual fix by seeing if it outputs correctly on a Windows 10 computer as well.

It is posible to determin loosely with the following PS. ```powershell $os_name = wmic os get Caption if( $os_name[2] -like "Microsoft Windows 7*" ){ $output = "It's Win7 Jerry!!! `n" + $os_name[2] } else { $output = "It's a computer Jerry!!!`nI don't know what the hell it is.`n" + $os_name[2] } Write-Output $output ``` On a Windows 7 machine it will output: ```shell It's Win7 Jerry!!! Microsoft Windows 7 Professional ``` I will determin if this is an actual fix by seeing if it outputs correctly on a Windows 10 computer as well.
Author
Owner

Confirmed.

It's a computer Jerry!!!
I don't know what the hell it is.
Microsoft Windows 10 Pro
Confirmed. ```shell It's a computer Jerry!!! I don't know what the hell it is. Microsoft Windows 10 Pro ```
Author
Owner

I think for the time being I'm going to solve this by reimplimating the functions with WMIC commands and a _7 suffix.

I think for the time being I'm going to solve this by reimplimating the functions with `WMIC` commands and a `_7` suffix.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: efrick/Sysinfo#2
No description provided.