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