Repository navigation
CHEF-20278: Support platform detection via Get-CimInstance for newer Windows versions - #788
Merged
Merged
Conversation
…ewer Windows versions Signed-off-by: Sonu Saha <sonu.saha@progress.com>
Get-CimInstance for newer Windows versions
ahasunos
force-pushed
the
ss/wmic-deprecation-alternative-cmd
branch
from
April 15, 2025 10:07
261b271 to
dcec43a
Compare
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>
| end | ||
|
|
||
| def windows_uuid_from_cim | ||
| cmd = 'powershell -Command "(Get-CimInstance -Class Win32_ComputerSystemProduct).UUID"' |
Contributor
There was a problem hiding this comment.
backend is eitherway going to run this in powershell right ?
Contributor
Author
There was a problem hiding this comment.
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
approved these changes
Apr 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR extends Windows platform details detection to support modern environments where
wmicis deprecated or unavailable. It introduces fallback logic using PowerShell'sGet-CimInstancefor: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-CimInstancecmdlet for WMI operations instead.Guidance for Transitioning to PowerShell's
Get-CimInstance: WMI command line (WMIC) utility deprecation: Next stepsAdditionally, 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
Checklist: