Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions UnitySetup/DSCResources/xUnityLicense/xUnityLicense.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
function Get-TargetResource {
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[System.Management.Automation.PSCredential]
$Credential,

[System.Management.Automation.PSCredential]
$Serial,

[System.String]
$UnityVersion,

[System.String]
$Name
)

@{ 'Licenses' = (Get-UnityLicense) }
}


function Set-TargetResource {
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
$Credential,

[ValidateSet("Present", "Absent")]
[System.String]
$Ensure = 'Present',

[parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
$Serial,

[System.String]
$UnityVersion,

[parameter(Mandatory = $true)]
[System.String]
$Name
)

if ( Test-TargetResource @PSBoundParameters ) { return }

$unityArgs = @{
'Credential' = $Credential
'Wait' = $true
}

if ( $UnityVersion ) { $unityArgs['Version'] = $UnityVersion }
if ( $Ensure -eq 'Present' ) { $unityArgs['Serial'] = $Serial.Password }
else { $unityArgs['ReturnLicense'] = $true }

Start-UnityEditor @unityArgs -Verbose
}


function Test-TargetResource {
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[System.Management.Automation.PSCredential]
$Credential,

[ValidateSet("Present", "Absent")]
[System.String]
$Ensure = 'Present',

[parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
$Serial,

[System.String]
$UnityVersion,

[parameter(Mandatory = $true)]
[System.String]
$Name
)

foreach ( $license in (Get-UnityLicense -Serial $Serial.Password) ) {
Write-Verbose "Found license: $license"

$currentSerial = [System.Net.NetworkCredential]::new($null, $license.Serial).Password
$passedSerial = $Serial.GetNetworkCredential().Password
if ( $currentSerial -ne $passedSerial ) { continue }

return $Ensure -eq 'Present'
}

return $Ensure -eq 'Absent'
}


Export-ModuleMember -Function *-TargetResource

11 changes: 11 additions & 0 deletions UnitySetup/DSCResources/xUnityLicense/xUnityLicense.schema.mof
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

[ClassVersion("1.0.0.0"), FriendlyName("xUnityLicense")]
class xUnityLicense : OMI_BaseResource
{
[Key] string Name;
[Required, EmbeddedInstance("MSFT_Credential")] String Credential;
[Required, EmbeddedInstance("MSFT_Credential")] String Serial;
[Write, ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure;
[Write] string UnityVersion;
};

43 changes: 43 additions & 0 deletions UnitySetup/Examples/Sample_xUnity.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<#
Create a custom configuration by passing in necessary values
#>
Configuration Sample_xUnitySetupInstance {
param
(
[System.String]
$Versions = '2017.4.2f2'

[ValidateSet('Present', 'Absent')]
[System.String]
$Ensure = 'Present',

[System.String[]]
$Components = @('Windows', 'Mac', 'Linux', 'Metro', 'iOS', 'Android'),

[PSCredential]
$UnityCredential,

[PSCredential]
$UnitySerial
)

Import-DscResource -ModuleName UnitySetup

Node 'localhost' {

xUnitySetupInstance Unity {
Versions = $Versions
Components = $Components
Ensure = $Ensure
DependsOn = if( $Ensure -eq 'Absent' ) { '[xUnityLicense]UnityLicense' }
}

xUnityLicense UnityLicense {
Name = 'UL01'
Credential = $UnityCredential
Serial = $UnitySerial
Ensure = $Ensure
DependsOn = if( $Ensure -eq 'Present' ) { '[xUnitySetupInstance]Unity' }
}
}
}
28 changes: 0 additions & 28 deletions UnitySetup/Examples/Sample_xUnitySetupInstance.ps1

This file was deleted.

16 changes: 0 additions & 16 deletions UnitySetup/Examples/Sample_xUnitySetupInstance_Install.ps1

This file was deleted.

15 changes: 0 additions & 15 deletions UnitySetup/Examples/Sample_xUnitySetupInstance_Uninstall.ps1

This file was deleted.

30 changes: 30 additions & 0 deletions UnitySetup/Examples/Sample_xUnity_Install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<#
Install multiple versions of Unity and several components
#>
Configuration Sample_xUnitySetupInstance_Install {

param(
[PSCredential]$UnityCredential,
[PSCredential]$UnitySerial
)

Import-DscResource -ModuleName UnitySetup

Node 'localhost' {

xUnitySetupInstance Unity {
Versions = '2017.4.2f2'
Components = 'Windows', 'Mac', 'Linux', 'Metro', 'iOS', 'Android'
Ensure = 'Present'
}

xUnityLicense UnityLicense {
Name = 'UL01'
Credential = $UnityCredential
Serial = $UnitySerial
Ensure = 'Present'
UnityVersion = '2017.4.2f2'
DependsOn = '[xUnitySetupInstance]Unity'
}
}
}
29 changes: 29 additions & 0 deletions UnitySetup/Examples/Sample_xUnity_Uninstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<#
Uninstall multiple versions of Unity
#>
Configuration Sample_xUnitySetupInstance_Install {

param(
[PSCredential]$UnityCredential,
[PSCredential]$UnitySerial
)

Import-DscResource -ModuleName UnitySetup

Node 'localhost' {

xUnitySetupInstance Unity {
Versions = '2017.4.2f2'
Ensure = 'Absent'
DependsOn = '[xUnityLicense]UnityLicense'
}

xUnityLicense UnityLicense {
Name = 'UL01'
Credential = $UnityCredential
Serial = $UnitySerial
Ensure = 'Absent'
UnityVersion = '2017.4.2f2'
}
}
}
3 changes: 2 additions & 1 deletion UnitySetup/UnitySetup.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
'Select-UnitySetupInstance',
'Uninstall-UnitySetupInstance',
'Start-UnityEditor',
'ConvertTo-UnitySetupComponent'
'ConvertTo-UnitySetupComponent',
'Get-UnityLicense'
)

# 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.
Expand Down
Loading