Skip to content

Commit 776985c

Browse files
committed
update from WVD to AVD
1 parent 418f462 commit 776985c

21 files changed

+1251
-17
lines changed
File renamed without changes.
4.71 KB
Binary file not shown.
1.86 KB
Binary file not shown.
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Defines the values for the resource's Ensure property.
2+
enum Ensure
3+
{
4+
# The resource must be absent.
5+
Absent
6+
# The resource must be present.
7+
Present
8+
}
9+
10+
# [DscResource()] indicates the class is a DSC resource.
11+
[DscResource()]
12+
class AVDDSC
13+
{
14+
15+
# A DSC resource must define at least one key property.
16+
[DscProperty(Key)]
17+
[string]$PoolNameSuffix
18+
19+
[DscProperty()]
20+
[string]$ManagedIdentityClientID
21+
22+
[DscProperty()]
23+
[string]$ResourceGroupName
24+
25+
[DscProperty()]
26+
[string]$SubscriptionID
27+
28+
[DscProperty()]
29+
[string]$LogDirectory
30+
31+
[DscProperty(Key)]
32+
[string]$PackagePath
33+
34+
# Mandatory indicates the property is required and DSC will guarantee it is set.
35+
[DscProperty()]
36+
[Ensure]$Ensure = [Ensure]::Present
37+
38+
# Tests if the resource is in the desired state.
39+
[bool] Test()
40+
{
41+
try
42+
{
43+
return (Test-Path 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\RDInfraAgent')
44+
}
45+
catch
46+
{
47+
$ErrMsg = $PSItem | Format-List -Force | Out-String
48+
Write-Log -Err $ErrMsg
49+
throw [System.Exception]::new("Some error occurred in DSC ExecuteRdAgentInstallClient TestScript: $ErrMsg", $PSItem.Exception)
50+
}
51+
}
52+
53+
# Sets the desired state of the resource.
54+
[void] Set()
55+
{
56+
if (Test-Path -Path $this.PackagePath)
57+
{
58+
$joinKey = $this.GetHostPoolConnectionToken()
59+
$argumentList += " /i $($this.PackagePath) "
60+
$argumentList += " /qb /norestart /l*+ $($this.LogDirectory)\Microsoft.RDInfra.RDAgent.Installer.log"
61+
$argumentList += " REGISTRATIONTOKEN=$joinKey"
62+
63+
$retryTimeToSleepInSec = 30
64+
$retryCount = 0
65+
$sts = $null
66+
do
67+
{
68+
if ($retryCount -gt 0)
69+
{
70+
Start-Sleep -Seconds $retryTimeToSleepInSec
71+
}
72+
73+
$processResult = Start-Process -FilePath 'msiexec.exe' -ArgumentList $argumentList -Wait -PassThru
74+
$sts = $processResult.ExitCode
75+
76+
$retryCount++
77+
}
78+
while ($sts -eq 1618 -and $retryCount -lt 20) # Error code 1618 is ERROR_INSTALL_ALREADY_RUNNING see https://docs.microsoft.com/en-us/windows/win32/msi/-msiexecute-mutex .
79+
}
80+
else
81+
{
82+
throw "Package not found at $($this.PackagePath)"
83+
}
84+
}
85+
86+
# Gets the resource's current state.
87+
[AVDDSC] Get()
88+
{
89+
# Return this instance or construct a new instance.
90+
return $this
91+
}
92+
93+
<#
94+
Helper method to Get the ResourceID
95+
#>
96+
97+
[string] GetHostPoolConnectionToken()
98+
{
99+
#region Retrieve the token via the ManagedIdentity
100+
$WebRequest = @{
101+
UseBasicParsing = $true
102+
Uri = "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&client_id=$($this.ManagedIdentityClientID)&resource=https://management.azure.com/"
103+
Method = 'GET'
104+
Headers = @{Metadata = 'true' }
105+
ErrorAction = 'Stop'
106+
ContentType = 'application/json'
107+
}
108+
$response = Invoke-WebRequest @WebRequest
109+
$ArmToken = $response.Content | ConvertFrom-Json | ForEach-Object access_token
110+
#endregion retrieve token
111+
112+
#region only check the metadata service if details not passed in.
113+
if (-not $this.SubscriptionID -or -not $this.ResourceGroupName)
114+
{
115+
$URI = 'http://169.254.169.254/metadata/instance?api-version=2019-02-01'
116+
$VMMeta = Invoke-RestMethod -Headers @{'Metadata' = 'true' } -Uri $URI -Method GET
117+
$Compute = $VMMeta.compute
118+
119+
if (-not $this.SubscriptionID)
120+
{
121+
$this.SubscriptionID = $Compute.subscriptionId
122+
}
123+
124+
if (-not $this.ResourceGroupName)
125+
{
126+
$this.ResourceGroupName = $Compute.resourceGroupName
127+
}
128+
}
129+
#endregion retrieve optional information.
130+
131+
$Deployment = $this.ResourceGroupName -replace '-RG',''
132+
$PoolName = "{0}-avdhp{1}" -f $Deployment,$this.PoolNameSuffix
133+
$WebRequest['Headers'] = @{ Authorization = "Bearer $ArmToken" }
134+
$WebRequest['Uri'] = "https://management.azure.com/subscriptions/$($this.SubscriptionId)/resourceGroups/$($this.ResourceGroupName)/providers/Microsoft.DesktopVirtualization/hostPools/$($PoolName)?api-version=2019-12-10-preview"
135+
136+
137+
$Pool = (Invoke-WebRequest @WebRequest).content | ConvertFrom-Json
138+
$HostPoolConnectionToken = $Pool | ForEach-Object properties | ForEach-Object RegistrationInfo | ForEach-Object token
139+
if ($HostPoolConnectionToken)
140+
{
141+
return $HostPoolConnectionToken
142+
}
143+
else
144+
{
145+
throw "Registration token must be generated first, cannot continue"
146+
}
147+
}
148+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Ben Wilkinson
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# WVDDSC
2+
3+
PowerShell Web Access DSC __Class based Resource__
4+
5+
This is a DSC Resource for configuring Windows Virtual Destkop Host Pool (WVD)
6+
7+
__Requirements__
8+
* PowerShell Version 5.0 +
9+
* Server 2012 +
10+
11+
```powershell
12+
# sample configuation data
13+
14+
DirectoryPresentSource = @(
15+
@{
16+
filesSourcePath = '\\{0}.file.core.windows.net\source\WVD\'
17+
filesDestinationPath = 'F:\Source\WVD\'
18+
MatchSource = $true
19+
}
20+
)
21+
22+
SoftwarePackagePresent = @(
23+
@{
24+
Name = 'Remote Desktop Agent Boot Loader'
25+
Path = 'F:\Source\WVD\Microsoft.RDInfra.RDAgentBootLoader.Installer-x64.msi'
26+
ProductId = '{41439A3F-FED7-478A-A71B-8E15AF8A6607}'
27+
Arguments = '/log "F:\Source\WVD\AgentBootLoaderInstall.txt"'
28+
}
29+
30+
WVDInstall = @(
31+
@{
32+
PoolNameSuffix = 'hp01'
33+
PackagePath = 'F:\Source\WVD\Microsoft.RDInfra.RDAgent.Installer-x64-1.0.2548.6500.msi'
34+
}
35+
)
36+
```
37+
38+
39+
```powershell
40+
41+
$StringFilter = '\W', ''
42+
#-------------------------------------------------------------------
43+
foreach ($File in $Node.DirectoryPresentSource)
44+
{
45+
$Name = ($File.filesSourcePath -f $StorageAccountName + $File.filesDestinationPath) -replace $StringFilter
46+
File $Name
47+
{
48+
SourcePath = ($File.filesSourcePath -f $StorageAccountName)
49+
DestinationPath = $File.filesDestinationPath
50+
Ensure = 'Present'
51+
Recurse = $true
52+
Credential = $StorageCred
53+
MatchSource = IIF $File.MatchSource $File.MatchSource $False
54+
}
55+
$dependsonDirectory += @("[File]$Name")
56+
}
57+
58+
#-------------------------------------------------------------------
59+
# install any packages without dependencies
60+
foreach ($Package in $Node.SoftwarePackagePresent)
61+
{
62+
$Name = $Package.Name -replace $StringFilter
63+
xPackage $Name
64+
{
65+
Name = $Package.Name
66+
Path = $Package.Path
67+
Ensure = 'Present'
68+
ProductId = $Package.ProductId
69+
PsDscRunAsCredential = $credlookup['DomainCreds']
70+
DependsOn = $dependsonDirectory
71+
Arguments = $Package.Arguments
72+
}
73+
74+
$dependsonPackage += @("[xPackage]$($Name)")
75+
}
76+
77+
#-------------------------------------------------------------------
78+
# install WVD package
79+
if ($Node.WVDInstall)
80+
{
81+
WVDDSC RDInfraAgent
82+
{
83+
PoolNameSuffix = $Node.WVDInstall.PoolNameSuffix
84+
PackagePath = $Node.WVDInstall.PackagePath
85+
ManagedIdentityClientID = $AppInfo.ClientID
86+
}
87+
}
88+
```
89+
90+
Full sample available here
91+
92+
- DSC Configuration
93+
- [ADF/ext-DSC/DSC-AppServers.ps1](https://github.com/brwilkinson/AzureDeploymentFramework/blob/main/ADF/ext-DSC/DSC-AppServers.ps1#L7121)
94+
- DSC ConfigurationData
95+
- [ADF/ext-CD/WVD-ConfigurationData.psd1](https://github.com/brwilkinson/AzureDeploymentFramework/blob/main/ADF/ext-CD/WVD-ConfigurationData.psd1#L38)

ADF/bicep/00-ALL-MG.bicep

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
'AWU2'
77
'AWU3'
88
'AWCU'
9+
'UGAZ'
10+
'UGTX'
11+
'ASA1'
912
])
1013
param Prefix string
1114

ADF/bicep/00-ALL-SUB.bicep

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
'AWU2'
77
'AWU3'
88
'AWCU'
9+
'UGAZ'
10+
'UGTX'
11+
'ASA1'
912
])
1013
param Prefix string
1114

0 commit comments

Comments
 (0)