Skip to content

Commit 1db828e

Browse files
committed
Add license query and management support
1 parent 0f40282 commit 1db828e

10 files changed

+291
-65
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
function Get-TargetResource {
2+
[CmdletBinding()]
3+
[OutputType([System.Collections.Hashtable])]
4+
param
5+
(
6+
[System.Management.Automation.PSCredential]
7+
$Credential,
8+
9+
[System.Management.Automation.PSCredential]
10+
$Serial,
11+
12+
[System.String]
13+
$UnityVersion,
14+
15+
[System.String]
16+
$Name
17+
)
18+
19+
@{ 'Licenses' = (Get-UnityLicense) }
20+
}
21+
22+
23+
function Set-TargetResource {
24+
[CmdletBinding()]
25+
param
26+
(
27+
[parameter(Mandatory = $true)]
28+
[System.Management.Automation.PSCredential]
29+
$Credential,
30+
31+
[ValidateSet("Present", "Absent")]
32+
[System.String]
33+
$Ensure = 'Present',
34+
35+
[parameter(Mandatory = $true)]
36+
[System.Management.Automation.PSCredential]
37+
$Serial,
38+
39+
[System.String]
40+
$UnityVersion,
41+
42+
[parameter(Mandatory = $true)]
43+
[System.String]
44+
$Name
45+
)
46+
47+
if ( Test-TargetResource @PSBoundParameters ) { return }
48+
49+
$unityArgs = @{
50+
'Credential' = $Credential
51+
'Wait' = $true
52+
}
53+
54+
if ( $UnityVersion ) { $unityArgs['Version'] = $UnityVersion }
55+
if ( $Ensure -eq 'Present' ) { $unityArgs['Serial'] = $Serial.Password }
56+
else { $unityArgs['ReturnLicense'] = $true }
57+
58+
Start-UnityEditor @unityArgs -Verbose
59+
}
60+
61+
62+
function Test-TargetResource {
63+
[CmdletBinding()]
64+
[OutputType([System.Boolean])]
65+
param
66+
(
67+
[System.Management.Automation.PSCredential]
68+
$Credential,
69+
70+
[ValidateSet("Present", "Absent")]
71+
[System.String]
72+
$Ensure = 'Present',
73+
74+
[parameter(Mandatory = $true)]
75+
[System.Management.Automation.PSCredential]
76+
$Serial,
77+
78+
[System.String]
79+
$UnityVersion,
80+
81+
[parameter(Mandatory = $true)]
82+
[System.String]
83+
$Name
84+
)
85+
86+
foreach ( $license in (Get-UnityLicense -Serial $Serial.Password) ) {
87+
Write-Verbose "Found license: $license"
88+
89+
$currentSerial = [System.Net.NetworkCredential]::new($null, $license.Serial).Password
90+
$passedSerial = $Serial.GetNetworkCredential().Password
91+
if ( $currentSerial -ne $passedSerial ) { continue }
92+
93+
return $Ensure -eq 'Present'
94+
}
95+
96+
return $Ensure -eq 'Absent'
97+
}
98+
99+
100+
Export-ModuleMember -Function *-TargetResource
101+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+

2+
[ClassVersion("1.0.0.0"), FriendlyName("xUnityLicense")]
3+
class xUnityLicense : OMI_BaseResource
4+
{
5+
[Key] string Name;
6+
[Required, EmbeddedInstance("MSFT_Credential")] String Credential;
7+
[Required, EmbeddedInstance("MSFT_Credential")] String Serial;
8+
[Write, ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure;
9+
[Write] string UnityVersion;
10+
};
11+

UnitySetup/Examples/Sample_xUnity.ps1

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<#
2+
Create a custom configuration by passing in necessary values
3+
#>
4+
Configuration Sample_xUnitySetupInstance {
5+
param
6+
(
7+
[System.String]
8+
$Versions = '2017.4.2f2'
9+
10+
[ValidateSet('Present', 'Absent')]
11+
[System.String]
12+
$Ensure = 'Present',
13+
14+
[System.String[]]
15+
$Components = @('Windows', 'Mac', 'Linux', 'Metro', 'iOS', 'Android'),
16+
17+
[PSCredential]
18+
$UnityCredential,
19+
20+
[PSCredential]
21+
$UnitySerial
22+
)
23+
24+
Import-DscResource -ModuleName UnitySetup
25+
26+
Node 'localhost' {
27+
28+
xUnitySetupInstance Unity {
29+
Versions = $Versions
30+
Components = $Components
31+
Ensure = $Ensure
32+
DependsOn = if( $Ensure -eq 'Absent' ) { '[xUnityLicense]UnityLicense' }
33+
}
34+
35+
xUnityLicense UnityLicense {
36+
Name = 'UL01'
37+
Credential = $UnityCredential
38+
Serial = $UnitySerial
39+
Ensure = $Ensure
40+
DependsOn = if( $Ensure -eq 'Present' ) { '[xUnitySetupInstance]Unity' }
41+
}
42+
}
43+
}

UnitySetup/Examples/Sample_xUnitySetupInstance.ps1

Lines changed: 0 additions & 28 deletions
This file was deleted.

UnitySetup/Examples/Sample_xUnitySetupInstance_Install.ps1

Lines changed: 0 additions & 16 deletions
This file was deleted.

UnitySetup/Examples/Sample_xUnitySetupInstance_Uninstall.ps1

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<#
2+
Install multiple versions of Unity and several components
3+
#>
4+
Configuration Sample_xUnitySetupInstance_Install {
5+
6+
param(
7+
[PSCredential]$UnityCredential,
8+
[PSCredential]$UnitySerial
9+
)
10+
11+
Import-DscResource -ModuleName UnitySetup
12+
13+
Node 'localhost' {
14+
15+
xUnitySetupInstance Unity {
16+
Versions = '2017.4.2f2'
17+
Components = 'Windows', 'Mac', 'Linux', 'Metro', 'iOS', 'Android'
18+
Ensure = 'Present'
19+
}
20+
21+
xUnityLicense UnityLicense {
22+
Name = 'UL01'
23+
Credential = $UnityCredential
24+
Serial = $UnitySerial
25+
Ensure = 'Present'
26+
UnityVersion = '2017.4.2f2'
27+
DependsOn = '[xUnitySetupInstance]Unity'
28+
}
29+
}
30+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<#
2+
Uninstall multiple versions of Unity
3+
#>
4+
Configuration Sample_xUnitySetupInstance_Install {
5+
6+
param(
7+
[PSCredential]$UnityCredential,
8+
[PSCredential]$UnitySerial
9+
)
10+
11+
Import-DscResource -ModuleName UnitySetup
12+
13+
Node 'localhost' {
14+
15+
xUnitySetupInstance Unity {
16+
Versions = '2017.4.2f2'
17+
Ensure = 'Absent'
18+
DependsOn = '[xUnityLicense]UnityLicense'
19+
}
20+
21+
xUnityLicense UnityLicense {
22+
Name = 'UL01'
23+
Credential = $UnityCredential
24+
Serial = $UnitySerial
25+
Ensure = 'Absent'
26+
UnityVersion = '2017.4.2f2'
27+
}
28+
}
29+
}

UnitySetup/UnitySetup.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@
8282
'Select-UnitySetupInstance',
8383
'Uninstall-UnitySetupInstance',
8484
'Start-UnityEditor',
85-
'ConvertTo-UnitySetupComponent'
85+
'ConvertTo-UnitySetupComponent',
86+
'Get-UnityLicense'
8687
)
8788

8889
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.

0 commit comments

Comments
 (0)