-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
418f462
commit 776985c
Showing
21 changed files
with
1,251 additions
and
17 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
# Defines the values for the resource's Ensure property. | ||
enum Ensure | ||
{ | ||
# The resource must be absent. | ||
Absent | ||
# The resource must be present. | ||
Present | ||
} | ||
|
||
# [DscResource()] indicates the class is a DSC resource. | ||
[DscResource()] | ||
class AVDDSC | ||
{ | ||
|
||
# A DSC resource must define at least one key property. | ||
[DscProperty(Key)] | ||
[string]$PoolNameSuffix | ||
|
||
[DscProperty()] | ||
[string]$ManagedIdentityClientID | ||
|
||
[DscProperty()] | ||
[string]$ResourceGroupName | ||
|
||
[DscProperty()] | ||
[string]$SubscriptionID | ||
|
||
[DscProperty()] | ||
[string]$LogDirectory | ||
|
||
[DscProperty(Key)] | ||
[string]$PackagePath | ||
|
||
# Mandatory indicates the property is required and DSC will guarantee it is set. | ||
[DscProperty()] | ||
[Ensure]$Ensure = [Ensure]::Present | ||
|
||
# Tests if the resource is in the desired state. | ||
[bool] Test() | ||
{ | ||
try | ||
{ | ||
return (Test-Path 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\RDInfraAgent') | ||
} | ||
catch | ||
{ | ||
$ErrMsg = $PSItem | Format-List -Force | Out-String | ||
Write-Log -Err $ErrMsg | ||
throw [System.Exception]::new("Some error occurred in DSC ExecuteRdAgentInstallClient TestScript: $ErrMsg", $PSItem.Exception) | ||
} | ||
} | ||
|
||
# Sets the desired state of the resource. | ||
[void] Set() | ||
{ | ||
if (Test-Path -Path $this.PackagePath) | ||
{ | ||
$joinKey = $this.GetHostPoolConnectionToken() | ||
$argumentList += " /i $($this.PackagePath) " | ||
$argumentList += " /qb /norestart /l*+ $($this.LogDirectory)\Microsoft.RDInfra.RDAgent.Installer.log" | ||
$argumentList += " REGISTRATIONTOKEN=$joinKey" | ||
|
||
$retryTimeToSleepInSec = 30 | ||
$retryCount = 0 | ||
$sts = $null | ||
do | ||
{ | ||
if ($retryCount -gt 0) | ||
{ | ||
Start-Sleep -Seconds $retryTimeToSleepInSec | ||
} | ||
|
||
$processResult = Start-Process -FilePath 'msiexec.exe' -ArgumentList $argumentList -Wait -PassThru | ||
$sts = $processResult.ExitCode | ||
|
||
$retryCount++ | ||
} | ||
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 . | ||
} | ||
else | ||
{ | ||
throw "Package not found at $($this.PackagePath)" | ||
} | ||
} | ||
|
||
# Gets the resource's current state. | ||
[AVDDSC] Get() | ||
{ | ||
# Return this instance or construct a new instance. | ||
return $this | ||
} | ||
|
||
<# | ||
Helper method to Get the ResourceID | ||
#> | ||
|
||
[string] GetHostPoolConnectionToken() | ||
{ | ||
#region Retrieve the token via the ManagedIdentity | ||
$WebRequest = @{ | ||
UseBasicParsing = $true | ||
Uri = "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&client_id=$($this.ManagedIdentityClientID)&resource=https://management.azure.com/" | ||
Method = 'GET' | ||
Headers = @{Metadata = 'true' } | ||
ErrorAction = 'Stop' | ||
ContentType = 'application/json' | ||
} | ||
$response = Invoke-WebRequest @WebRequest | ||
$ArmToken = $response.Content | ConvertFrom-Json | ForEach-Object access_token | ||
#endregion retrieve token | ||
|
||
#region only check the metadata service if details not passed in. | ||
if (-not $this.SubscriptionID -or -not $this.ResourceGroupName) | ||
{ | ||
$URI = 'http://169.254.169.254/metadata/instance?api-version=2019-02-01' | ||
$VMMeta = Invoke-RestMethod -Headers @{'Metadata' = 'true' } -Uri $URI -Method GET | ||
$Compute = $VMMeta.compute | ||
|
||
if (-not $this.SubscriptionID) | ||
{ | ||
$this.SubscriptionID = $Compute.subscriptionId | ||
} | ||
|
||
if (-not $this.ResourceGroupName) | ||
{ | ||
$this.ResourceGroupName = $Compute.resourceGroupName | ||
} | ||
} | ||
#endregion retrieve optional information. | ||
|
||
$Deployment = $this.ResourceGroupName -replace '-RG','' | ||
$PoolName = "{0}-avdhp{1}" -f $Deployment,$this.PoolNameSuffix | ||
$WebRequest['Headers'] = @{ Authorization = "Bearer $ArmToken" } | ||
$WebRequest['Uri'] = "https://management.azure.com/subscriptions/$($this.SubscriptionId)/resourceGroups/$($this.ResourceGroupName)/providers/Microsoft.DesktopVirtualization/hostPools/$($PoolName)?api-version=2019-12-10-preview" | ||
|
||
|
||
$Pool = (Invoke-WebRequest @WebRequest).content | ConvertFrom-Json | ||
$HostPoolConnectionToken = $Pool | ForEach-Object properties | ForEach-Object RegistrationInfo | ForEach-Object token | ||
if ($HostPoolConnectionToken) | ||
{ | ||
return $HostPoolConnectionToken | ||
} | ||
else | ||
{ | ||
throw "Registration token must be generated first, cannot continue" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Ben Wilkinson | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# WVDDSC | ||
|
||
PowerShell Web Access DSC __Class based Resource__ | ||
|
||
This is a DSC Resource for configuring Windows Virtual Destkop Host Pool (WVD) | ||
|
||
__Requirements__ | ||
* PowerShell Version 5.0 + | ||
* Server 2012 + | ||
|
||
```powershell | ||
# sample configuation data | ||
DirectoryPresentSource = @( | ||
@{ | ||
filesSourcePath = '\\{0}.file.core.windows.net\source\WVD\' | ||
filesDestinationPath = 'F:\Source\WVD\' | ||
MatchSource = $true | ||
} | ||
) | ||
SoftwarePackagePresent = @( | ||
@{ | ||
Name = 'Remote Desktop Agent Boot Loader' | ||
Path = 'F:\Source\WVD\Microsoft.RDInfra.RDAgentBootLoader.Installer-x64.msi' | ||
ProductId = '{41439A3F-FED7-478A-A71B-8E15AF8A6607}' | ||
Arguments = '/log "F:\Source\WVD\AgentBootLoaderInstall.txt"' | ||
} | ||
WVDInstall = @( | ||
@{ | ||
PoolNameSuffix = 'hp01' | ||
PackagePath = 'F:\Source\WVD\Microsoft.RDInfra.RDAgent.Installer-x64-1.0.2548.6500.msi' | ||
} | ||
) | ||
``` | ||
|
||
|
||
```powershell | ||
$StringFilter = '\W', '' | ||
#------------------------------------------------------------------- | ||
foreach ($File in $Node.DirectoryPresentSource) | ||
{ | ||
$Name = ($File.filesSourcePath -f $StorageAccountName + $File.filesDestinationPath) -replace $StringFilter | ||
File $Name | ||
{ | ||
SourcePath = ($File.filesSourcePath -f $StorageAccountName) | ||
DestinationPath = $File.filesDestinationPath | ||
Ensure = 'Present' | ||
Recurse = $true | ||
Credential = $StorageCred | ||
MatchSource = IIF $File.MatchSource $File.MatchSource $False | ||
} | ||
$dependsonDirectory += @("[File]$Name") | ||
} | ||
#------------------------------------------------------------------- | ||
# install any packages without dependencies | ||
foreach ($Package in $Node.SoftwarePackagePresent) | ||
{ | ||
$Name = $Package.Name -replace $StringFilter | ||
xPackage $Name | ||
{ | ||
Name = $Package.Name | ||
Path = $Package.Path | ||
Ensure = 'Present' | ||
ProductId = $Package.ProductId | ||
PsDscRunAsCredential = $credlookup['DomainCreds'] | ||
DependsOn = $dependsonDirectory | ||
Arguments = $Package.Arguments | ||
} | ||
$dependsonPackage += @("[xPackage]$($Name)") | ||
} | ||
#------------------------------------------------------------------- | ||
# install WVD package | ||
if ($Node.WVDInstall) | ||
{ | ||
WVDDSC RDInfraAgent | ||
{ | ||
PoolNameSuffix = $Node.WVDInstall.PoolNameSuffix | ||
PackagePath = $Node.WVDInstall.PackagePath | ||
ManagedIdentityClientID = $AppInfo.ClientID | ||
} | ||
} | ||
``` | ||
|
||
Full sample available here | ||
|
||
- DSC Configuration | ||
- [ADF/ext-DSC/DSC-AppServers.ps1](https://github.com/brwilkinson/AzureDeploymentFramework/blob/main/ADF/ext-DSC/DSC-AppServers.ps1#L7121) | ||
- DSC ConfigurationData | ||
- [ADF/ext-CD/WVD-ConfigurationData.psd1](https://github.com/brwilkinson/AzureDeploymentFramework/blob/main/ADF/ext-CD/WVD-ConfigurationData.psd1#L38) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ | |
'AWU2' | ||
'AWU3' | ||
'AWCU' | ||
'UGAZ' | ||
'UGTX' | ||
'ASA1' | ||
]) | ||
param Prefix string | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ | |
'AWU2' | ||
'AWU3' | ||
'AWCU' | ||
'UGAZ' | ||
'UGTX' | ||
'ASA1' | ||
]) | ||
param Prefix string | ||
|
||
|
Oops, something went wrong.