From aaf62dc2527e114c07a8b7a0355da0c416b422b5 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Thu, 16 Jan 2020 12:38:05 -0500 Subject: [PATCH] Add a state to activate a computer with it's BIOS key --- _states/auto_activate.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 _states/auto_activate.py diff --git a/_states/auto_activate.py b/_states/auto_activate.py new file mode 100644 index 0000000..d560f0c --- /dev/null +++ b/_states/auto_activate.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import, unicode_literals, print_function + +def auto_activate(name): + ret = {'name': name, + 'result': True, + 'comment': '', + 'changes': {}} + + if __salt__['license.licensed'](): + ret['comment'] = 'Windows is already activated' + return ret + + licensing = __salt__['cmd.powershell']("Get-WmiObject SoftwareLicensingService") + if licensing is not None: + OEM_key = licensing.get('OA3xOriginalProductKey', '') + if OEM_key != "": + return __states__['license.activate'](OEM_key) + + ret['comment'] = 'No Windows Key found in BIOS' + ret['result'] = False + return ret