-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
win_product_facts: New module to get Windows product information #35206
Conversation
So this is actually a very nice way to get product key information from systems collected centrally. Especially with systems that have been upgraded from Windows 7 or Windows 8 to Windows 10 may not have a valid Windows 10 product license key printed anywhere, it was a digital license. If you ever have to reinstall the system, you may recover the system from the recovery partition, or the original media, but cannot upgrade to Windows 10 for free. By collecting the product key, one can always reinstall your free Windows upgrade. My only question is, do we want this to be part of the default facts, as it may be considered important information. Or should we make a special **win_product_key_facts** ?
ansible_os_product_id = (Get-CimInstance Win32_OperatingSystem).SerialNumber | ||
ansible_os_product_key = Get-ProductKey | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No Exit-Json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed now.
#!powershell | ||
# This file is part of Ansible | ||
|
||
# Copyright: (c) 2017, Dag Wieers (dagwieers) <dag@wieers.com> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's 2018 now :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code originated from 2017 ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just living the the past, gotta let it go :)
''' | ||
|
||
EXAMPLES = r''' | ||
- name: Set product id and product key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/set/get/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, depends from what perspective ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM, just maybe a little defensive coding around the lookup/parsing of the fallback and tiny doc typo
''' | ||
|
||
EXAMPLES = r''' | ||
- name: Set product id and product key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Set/Get
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depends on your perspective ;-)
|
||
if (-not $product_key) { | ||
# Else try to get it from the registry instead | ||
$data = Get-ItemPropertyValue -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion" -Name DigitalProductId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if it's not there or not in the format you're expecting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if-it's-not-there is now covered. If the format is not as I expect the resulting key will be corrupted. I wouldn't expect this to be the case though.
|
||
Function Get-ProductKey { | ||
# First try to find the product key from ACPI | ||
$product_key = (Get-CimInstance -Class SoftwareLicensingService).OA3xOriginalProductKey |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably also want a -ErrorAction Continue
here in case the CIM class or property is not defined (eg, Server 2008)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then you cannot get to the OA3xOriginalProductKey property either. So should it be a try/catch instead ?
65fcf23
to
c09c1f6
Compare
c09c1f6
to
586698d
Compare
So I think I covered everything, except a corrupted registry key. I don't know if that's to be expected. |
1ffec01
to
e93dacc
Compare
72522b6
to
027a5de
Compare
…ible#35206) * win_setup: Add Product ID and Product Key in facts So this is actually a very nice way to get product key information from systems collected centrally. Especially with systems that have been upgraded from Windows 7 or Windows 8 to Windows 10 may not have a valid Windows 10 product license key printed anywhere, it was a digital license. If you ever have to reinstall the system, you may recover the system from the recovery partition, or the original media, but cannot upgrade to Windows 10 for free. By collecting the product key, one can always reinstall your free Windows upgrade. My only question is, do we want this to be part of the default facts, as it may be considered important information. Or should we make a special **win_product_key_facts** ? * Add ACPI product key support * Add integration test * Remove Get-ProductKey function, move inline
SUMMARY
This PR includes a new module that returns Windows product information, and includes product id and product key information.
ISSUE TYPE
COMPONENT NAME
win_product_facts
ANSIBLE VERSION
v2.5