1 #!powershell
2 
3 # Copyright: (c) 2019, RusoSova
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5 
6 #AnsibleRequires -CSharpUtil Ansible.Basic
7 #AnsibleRequires -OSVersion 6.1
8 
9 $spec = @{
10     options = @{
11         owner = @{ type="str" }
12         organization = @{ type="str" }
13         description = @{ type="str" }
14     }
15     required_one_of = @(
16         ,@('owner', 'organization', 'description')
17     )
18     supports_check_mode = $true
19 }
20 
21 $module = [Ansible.Basic.AnsibleModule]::Create($args, $spec)
22 
23 $owner = $module.Params.owner
24 $organization = $module.Params.organization
25 $description = $module.Params.description
26 $regPath="HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
27 
28 #Change description
29 if ($description -or $description -eq "") {
30     $descriptionObject=Get-CimInstance -class "Win32_OperatingSystem"
31     if ($description -cne $descriptionObject.description) {
32         Set-CimInstance -InputObject $descriptionObject -Property @{"Description"="$description"} -WhatIf:$module.CheckMode
33         $module.Result.changed = $true
34     }
35 }
36 
37 #Change owner
38 if ($owner -or $owner -eq "") {
39     $curentOwner=(Get-ItemProperty -LiteralPath $regPath -Name RegisteredOwner).RegisteredOwner
40     if ($curentOwner -cne $owner) {
41         Set-ItemProperty -LiteralPath $regPath -Name "RegisteredOwner" -Value $owner -WhatIf:$module.CheckMode
42         $module.Result.changed = $true
43     }
44 }
45 
46 #Change organization
47 if ($organization -or $organization -eq "") {
48     $curentOrganization=(Get-ItemProperty -LiteralPath $regPath -Name RegisteredOrganization).RegisteredOrganization
49     if ($curentOrganization -cne $organization) {
50         Set-ItemProperty -LiteralPath $regPath -Name "RegisteredOrganization" -Value $organization -WhatIf:$module.CheckMode
51         $module.Result.changed = $true
52     }
53 }
54 $module.ExitJson()
55