Skip to content

CHEF-20278: Support platform detection via Get-CimInstance for newer Windows versions - #788

Merged
sathish-progress merged 7 commits into
mainfrom
ss/wmic-deprecation-alternative-cmd
Apr 24, 2025
Merged

sathish-progress merged 7 commits into
mainfrom
ss/wmic-deprecation-alternative-cmd

Conversation

@ahasunos

@ahasunos ahasunos commented Apr 15, 2025 •

Copy link
Copy Markdown
Contributor

Description

This PR extends Windows platform details detection to support modern environments where wmic is deprecated or unavailable. It introduces fallback logic using PowerShell's Get-CimInstance for:

  • OS details (Caption, Version, BuildNumber)
  • CPU architecture
  • System UUID

As per Microsoft's official documentation, the wmic utility has been deprecated starting with Windows 10 version 21H1 and Windows Server 2022. Microsoft recommends using PowerShell's Get-CimInstance cmdlet for WMI operations instead.

Guidance for Transitioning to PowerShell's Get-CimInstance: WMI command line (WMIC) utility deprecation: Next steps

Additionally, in PowerShell 6 and later, the Get-WmiObject cmdlet is deprecated, and Microsoft recommends using Get-CimInstance for new development: Working with WMI - PowerShell

Related Issue

CHEF-20278: The "train" gem does not properly return if result.stdout is NIL

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New content (non-breaking change)
  • Breaking change (a content change which would break existing functionality or processes)

Checklist:

  • I have read the CONTRIBUTING document.

…ewer Windows versions

Signed-off-by: Sonu Saha <sonu.saha@progress.com>
@ahasunos ahasunos changed the title extend(windows): support platform detection via Get-CimInstance for newer Windows versions CHEF-20278: Support platform detection via Get-CimInstance for newer Windows versions Apr 15, 2025
@ahasunos ahasunos changed the title CHEF-20278: Support platform detection via Get-CimInstance for newer Windows versions CHEF-20278: Support platform detection via Get-CimInstance for newer Windows versions Apr 15, 2025
@ahasunos
ahasunos force-pushed the ss/wmic-deprecation-alternative-cmd branch from 261b271 to dcec43a Compare April 15, 2025 10:07
Signed-off-by: Sonu Saha <sonu.saha@progress.com>
…cated

Signed-off-by: Sonu Saha <sonu.saha@progress.com>
Signed-off-by: Sonu Saha <sonu.saha@progress.com>
Signed-off-by: Sonu Saha <sonu.saha@progress.com>
Signed-off-by: Sonu Saha <sonu.saha@progress.com>
@ahasunos
ahasunos marked this pull request as ready for review April 16, 2025 10:30
@ahasunos
ahasunos requested a review from a team as a code owner April 16, 2025 10:30
end

def windows_uuid_from_cim
cmd = 'powershell -Command "(Get-CimInstance -Class Win32_ComputerSystemProduct).UUID"'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backend is eitherway going to run this in powershell right ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested whether the backend defaults to PowerShell for command execution, but it appears that it doesn't.

See below debug statements:

(byebug) result = @backend.run_command('(Get-CimInstance -Class Win32_ComputerSystemProduct)')
#<struct Train::Extras::CommandResult stdout="", stderr="'Get-CimInstance' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n", exit_
status=1>
(byebug) result.exit_status
1
(byebug) result.stderr
"'Get-CimInstance' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n"
(byebug) result.stdout
""

(byebug) result = @backend.run_command('powershell -Command "(Get-CimInstance -Class Win32_ComputerSystemProduct).UUID"')
#<struct Train::Extras::CommandResult stdout="EC20EBD7-8E03-06A8-645F-2D22E5A3BA4B\r\n", stderr="", exit_status=0>
(byebug) result.exit_status
0
(byebug) result.stdout
"EC20EBD7-8E03-06A8-645F-2D22E5A3BA4B\r\n"
(byebug) result.stderr
""
(byebug) result = @backend.run_command('(Get-CimInstance -Class Win32_ComputerSystemProduct).UUID')
#<struct Train::Extras::CommandResult stdout="", stderr=".UUID was unexpected at this time.\r\n", exit_status=1>
(byebug) result.exit_status
1
(byebug) result.stderr
".UUID was unexpected at this time.\r\n"
(byebug) result.exit_status
1
(byebug)

@sathish-progress
sathish-progress merged commit 00b591f into main Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants