From d6eecb03aafcacd9742689c1cf10d83dce918be7 Mon Sep 17 00:00:00 2001 From: Jim Priestley Date: Fri, 13 Jan 2017 17:55:58 -0500 Subject: [PATCH 1/3] Added validation of 1-15 length to CollectionName parameter, and added tests to validate that invalid length throws an exception --- .../MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1 | 263 +++++++-------- .../MSFT_xRDSessionCollection.psm1 | 167 +++++----- ...SFT_xRDSessionCollectionConfiguration.psm1 | 301 +++++++++--------- tests/unit/MSFT_xRDRemoteApp.tests.ps1 | 90 ++++++ .../unit/MSFT_xRDSessionCollection.tests.ps1 | 79 +++++ ...RDSessionCollectionConfiguration.tests.ps1 | 78 +++++ 6 files changed, 617 insertions(+), 361 deletions(-) create mode 100644 tests/unit/MSFT_xRDRemoteApp.tests.ps1 create mode 100644 tests/unit/MSFT_xRDSessionCollection.tests.ps1 create mode 100644 tests/unit/MSFT_xRDSessionCollectionConfiguration.tests.ps1 diff --git a/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1 b/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1 index 8fd6898..c3ff64f 100644 --- a/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1 +++ b/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1 @@ -1,130 +1,133 @@ -Import-Module -Name "$PSScriptRoot\..\..\xRemoteDesktopSessionHostCommon.psm1" -if (!(Test-xRemoteDesktopSessionHostOsRequirement)) { Throw "The minimum OS requirement was not met."} -Import-Module RemoteDesktop -$localhost = [System.Net.Dns]::GetHostByName((hostname)).HostName - -####################################################################### -# The Get-TargetResource cmdlet. -####################################################################### -function Get-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [parameter(Mandatory)] - [string] $CollectionName = "Tenant", - [parameter(Mandatory)] - [string] $DisplayName = "Calculator", - [parameter(Mandatory)] - [string] $FilePath = "C:\Windows\System32\calc.exe", - [parameter(Mandatory)] - [string] $Alias = "calc", - [string] $FileVirtualPath, - [string] $FolderName, - [string] $CommandLineSetting, - [string] $RequiredCommandLine, - [uint32] $IconIndex, - [string] $IconPath, - [string] $UserGroups, - [boolean] $ShowInWebAccess - ) - Write-Verbose "Getting published RemoteApp program $DisplayName, if one exists." - $CollectionName = Get-RDSessionCollection | % {Get-RDSessionHost $_.CollectionName} | ? {$_.SessionHost -ieq $localhost} | % {$_.CollectionName} - $remoteApp = Get-RDRemoteApp -CollectionName $CollectionName -DisplayName $DisplayName -Alias $Alias - - @{ - "CollectionName" = $remoteApp.CollectionName; - "DisplayName" = $remoteApp.DisplayName; - "FilePath" = $remoteApp.FilePath; - "Alias" = $remoteApp.Alias; - "FileVirtualPath" = $remoteApp.FileVirtualPath; - "FolderName" = $remoteApp.FolderName; - "CommandLineSetting" = $remoteApp.CommandLineSetting; - "RequiredCommandLine" = $remoteApp.RequiredCommandLine; - "IconIndex" = $remoteApp.IconIndex; - "IconPath" = $remoteApp.IconPath; - "UserGroups" = $remoteApp.UserGroups; - "ShowInWebAccess" = $remoteApp.ShowInWebAccess; - } -} - - -######################################################################## -# The Set-TargetResource cmdlet. -######################################################################## -function Set-TargetResource - -{ - [CmdletBinding()] - param - ( - [parameter(Mandatory)] - [string] $CollectionName, - [parameter(Mandatory)] - [string] $DisplayName, - [parameter(Mandatory)] - [string] $FilePath, - [parameter(Mandatory)] - [string] $Alias, - [string] $FileVirtualPath, - [string] $FolderName, - [string] $CommandLineSetting, - [string] $RequiredCommandLine, - [uint32] $IconIndex, - [string] $IconPath, - [string] $UserGroups, - [boolean] $ShowInWebAccess - ) - Write-Verbose "Making updates to RemoteApp." - $CollectionName = Get-RDSessionCollection | % {Get-RDSessionHost $_.CollectionName} | ? {$_.SessionHost -ieq $localhost} | % {$_.CollectionName} - $PSBoundParameters.collectionName = $CollectionName - if (!$(Get-RDRemoteApp -Alias $Alias)) { - New-RDRemoteApp @PSBoundParameters - } - else { - Set-RDRemoteApp @PSBoundParameters - } -} - - -####################################################################### -# The Test-TargetResource cmdlet. -####################################################################### -function Test-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - [parameter(Mandatory)] - [string] $CollectionName, - [parameter(Mandatory)] - [string] $DisplayName, - [parameter(Mandatory)] - [string] $FilePath, - [parameter(Mandatory)] - [string] $Alias, - [string] $FileVirtualPath, - [string] $FolderName, - [string] $CommandLineSetting, - [string] $RequiredCommandLine, - [uint32] $IconIndex, - [string] $IconPath, - [string] $UserGroups, - [boolean] $ShowInWebAccess - ) - Write-Verbose "Testing if RemoteApp is published." - $collectionName = Get-RDSessionCollection | % {Get-RDSessionHost $_.CollectionName} | ? {$_.SessionHost -ieq $localhost} | % {$_.CollectionName} - $PSBoundParameters.Remove("Verbose") | out-null - $PSBoundParameters.Remove("Debug") | out-null - $PSBoundParameters.Remove("ConnectionBroker") | out-null - $Check = $true - - $Get = Get-TargetResource -CollectionName $CollectionName -DisplayName $DisplayName -FilePath $FilePath -Alias $Alias - $PSBoundParameters.keys | % {if ($PSBoundParameters[$_] -ne $Get[$_]) {$Check = $false} } - $Check -} - -Export-ModuleMember -Function *-TargetResource - +Import-Module -Name "$PSScriptRoot\..\..\xRemoteDesktopSessionHostCommon.psm1" +if (!(Test-xRemoteDesktopSessionHostOsRequirement)) { Throw "The minimum OS requirement was not met."} +Import-Module RemoteDesktop +$localhost = [System.Net.Dns]::GetHostByName((hostname)).HostName + +####################################################################### +# The Get-TargetResource cmdlet. +####################################################################### +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [parameter(Mandatory)] + [ValidateLength(1,15)] + [string] $CollectionName = "Tenant", + [parameter(Mandatory)] + [string] $DisplayName = "Calculator", + [parameter(Mandatory)] + [string] $FilePath = "C:\Windows\System32\calc.exe", + [parameter(Mandatory)] + [string] $Alias = "calc", + [string] $FileVirtualPath, + [string] $FolderName, + [string] $CommandLineSetting, + [string] $RequiredCommandLine, + [uint32] $IconIndex, + [string] $IconPath, + [string] $UserGroups, + [boolean] $ShowInWebAccess + ) + Write-Verbose "Getting published RemoteApp program $DisplayName, if one exists." + $CollectionName = Get-RDSessionCollection | % {Get-RDSessionHost $_.CollectionName} | ? {$_.SessionHost -ieq $localhost} | % {$_.CollectionName} + $remoteApp = Get-RDRemoteApp -CollectionName $CollectionName -DisplayName $DisplayName -Alias $Alias + + @{ + "CollectionName" = $remoteApp.CollectionName; + "DisplayName" = $remoteApp.DisplayName; + "FilePath" = $remoteApp.FilePath; + "Alias" = $remoteApp.Alias; + "FileVirtualPath" = $remoteApp.FileVirtualPath; + "FolderName" = $remoteApp.FolderName; + "CommandLineSetting" = $remoteApp.CommandLineSetting; + "RequiredCommandLine" = $remoteApp.RequiredCommandLine; + "IconIndex" = $remoteApp.IconIndex; + "IconPath" = $remoteApp.IconPath; + "UserGroups" = $remoteApp.UserGroups; + "ShowInWebAccess" = $remoteApp.ShowInWebAccess; + } +} + + +######################################################################## +# The Set-TargetResource cmdlet. +######################################################################## +function Set-TargetResource + +{ + [CmdletBinding()] + param + ( + [parameter(Mandatory)] + [ValidateLength(1,15)] + [string] $CollectionName, + [parameter(Mandatory)] + [string] $DisplayName, + [parameter(Mandatory)] + [string] $FilePath, + [parameter(Mandatory)] + [string] $Alias, + [string] $FileVirtualPath, + [string] $FolderName, + [string] $CommandLineSetting, + [string] $RequiredCommandLine, + [uint32] $IconIndex, + [string] $IconPath, + [string] $UserGroups, + [boolean] $ShowInWebAccess + ) + Write-Verbose "Making updates to RemoteApp." + $CollectionName = Get-RDSessionCollection | % {Get-RDSessionHost $_.CollectionName} | ? {$_.SessionHost -ieq $localhost} | % {$_.CollectionName} + $PSBoundParameters.collectionName = $CollectionName + if (!$(Get-RDRemoteApp -Alias $Alias)) { + New-RDRemoteApp @PSBoundParameters + } + else { + Set-RDRemoteApp @PSBoundParameters + } +} + + +####################################################################### +# The Test-TargetResource cmdlet. +####################################################################### +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [parameter(Mandatory)] + [ValidateLength(1,15)] + [string] $CollectionName, + [parameter(Mandatory)] + [string] $DisplayName, + [parameter(Mandatory)] + [string] $FilePath, + [parameter(Mandatory)] + [string] $Alias, + [string] $FileVirtualPath, + [string] $FolderName, + [string] $CommandLineSetting, + [string] $RequiredCommandLine, + [uint32] $IconIndex, + [string] $IconPath, + [string] $UserGroups, + [boolean] $ShowInWebAccess + ) + Write-Verbose "Testing if RemoteApp is published." + $collectionName = Get-RDSessionCollection | % {Get-RDSessionHost $_.CollectionName} | ? {$_.SessionHost -ieq $localhost} | % {$_.CollectionName} + $PSBoundParameters.Remove("Verbose") | out-null + $PSBoundParameters.Remove("Debug") | out-null + $PSBoundParameters.Remove("ConnectionBroker") | out-null + $Check = $true + + $Get = Get-TargetResource -CollectionName $CollectionName -DisplayName $DisplayName -FilePath $FilePath -Alias $Alias + $PSBoundParameters.keys | % {if ($PSBoundParameters[$_] -ne $Get[$_]) {$Check = $false} } + $Check +} + +Export-ModuleMember -Function *-TargetResource + diff --git a/DSCResources/MSFT_xRDSessionCollection/MSFT_xRDSessionCollection.psm1 b/DSCResources/MSFT_xRDSessionCollection/MSFT_xRDSessionCollection.psm1 index d0f5f7e..12845d5 100644 --- a/DSCResources/MSFT_xRDSessionCollection/MSFT_xRDSessionCollection.psm1 +++ b/DSCResources/MSFT_xRDSessionCollection/MSFT_xRDSessionCollection.psm1 @@ -1,82 +1,85 @@ -Import-Module -Name "$PSScriptRoot\..\..\xRemoteDesktopSessionHostCommon.psm1" -if (!(Test-xRemoteDesktopSessionHostOsRequirement)) { Throw "The minimum OS requirement was not met."} -Import-Module RemoteDesktop -$localhost = [System.Net.Dns]::GetHostByName((hostname)).HostName - -####################################################################### -# The Get-TargetResource cmdlet. -####################################################################### -function Get-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [parameter(Mandatory)] - [string] $CollectionName, - [parameter(Mandatory)] - [string] $SessionHost, - [string] $CollectionDescription, - [string] $ConnectionBroker - ) - Write-Verbose "Getting information about RDSH collection." - $Collection = Get-RDSessionCollection -ErrorAction SilentlyContinue - @{ - "CollectionName" = $Collection.CollectionName; - "CollectionDescription" = $Collection.CollectionDescription - "SessionHost" = $localhost - "ConnectionBroker" = $ConnectionBroker - } -} - - -######################################################################## -# The Set-TargetResource cmdlet. -######################################################################## -function Set-TargetResource - -{ - [CmdletBinding()] - param - ( - [parameter(Mandatory)] - [string] $CollectionName, - [parameter(Mandatory)] - [string] $SessionHost, - [string] $CollectionDescription, - [string] $ConnectionBroker - ) - Write-Verbose "Creating a new RDSH collection." - if ($localhost -eq $ConnectionBroker) { - New-RDSessionCollection @PSBoundParameters - } - else { - $PSBoundParameters.Remove("Description") - Add-RDSessionHost @PSBoundParameters - } -} - - -####################################################################### -# The Test-TargetResource cmdlet. -####################################################################### -function Test-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - [parameter(Mandatory)] - [string] $CollectionName, - [parameter(Mandatory)] - [string] $SessionHost, - [string] $CollectionDescription, - [string] $ConnectionBroker - ) - Write-Verbose "Checking for existance of RDSH collection." - (Get-TargetResource @PSBoundParameters).CollectionName -ne $null -} - - -Export-ModuleMember -Function *-TargetResource - +Import-Module -Name "$PSScriptRoot\..\..\xRemoteDesktopSessionHostCommon.psm1" +if (!(Test-xRemoteDesktopSessionHostOsRequirement)) { Throw "The minimum OS requirement was not met."} +Import-Module RemoteDesktop +$localhost = [System.Net.Dns]::GetHostByName((hostname)).HostName + +####################################################################### +# The Get-TargetResource cmdlet. +####################################################################### +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [parameter(Mandatory)] + [ValidateLength(1,15)] + [string] $CollectionName, + [parameter(Mandatory)] + [string] $SessionHost, + [string] $CollectionDescription, + [string] $ConnectionBroker + ) + Write-Verbose "Getting information about RDSH collection." + $Collection = Get-RDSessionCollection -ErrorAction SilentlyContinue + @{ + "CollectionName" = $Collection.CollectionName; + "CollectionDescription" = $Collection.CollectionDescription + "SessionHost" = $localhost + "ConnectionBroker" = $ConnectionBroker + } +} + + +######################################################################## +# The Set-TargetResource cmdlet. +######################################################################## +function Set-TargetResource + +{ + [CmdletBinding()] + param + ( + [parameter(Mandatory)] + [ValidateLength(1,15)] + [string] $CollectionName, + [parameter(Mandatory)] + [string] $SessionHost, + [string] $CollectionDescription, + [string] $ConnectionBroker + ) + Write-Verbose "Creating a new RDSH collection." + if ($localhost -eq $ConnectionBroker) { + New-RDSessionCollection @PSBoundParameters + } + else { + $PSBoundParameters.Remove("Description") + Add-RDSessionHost @PSBoundParameters + } +} + + +####################################################################### +# The Test-TargetResource cmdlet. +####################################################################### +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [parameter(Mandatory)] + [ValidateLength(1,15)] + [string] $CollectionName, + [parameter(Mandatory)] + [string] $SessionHost, + [string] $CollectionDescription, + [string] $ConnectionBroker + ) + Write-Verbose "Checking for existance of RDSH collection." + (Get-TargetResource @PSBoundParameters).CollectionName -ne $null +} + + +Export-ModuleMember -Function *-TargetResource + diff --git a/DSCResources/MSFT_xRDSessionCollectionConfiguration/MSFT_xRDSessionCollectionConfiguration.psm1 b/DSCResources/MSFT_xRDSessionCollectionConfiguration/MSFT_xRDSessionCollectionConfiguration.psm1 index ae11853..bdb56f0 100644 --- a/DSCResources/MSFT_xRDSessionCollectionConfiguration/MSFT_xRDSessionCollectionConfiguration.psm1 +++ b/DSCResources/MSFT_xRDSessionCollectionConfiguration/MSFT_xRDSessionCollectionConfiguration.psm1 @@ -1,149 +1,152 @@ -Import-Module -Name "$PSScriptRoot\..\..\xRemoteDesktopSessionHostCommon.psm1" -if (!(Test-xRemoteDesktopSessionHostOsRequirement)) { Throw "The minimum OS requirement was not met."} -Import-Module RemoteDesktop -$localhost = [System.Net.Dns]::GetHostByName((hostname)).HostName - - -####################################################################### -# The Get-TargetResource cmdlet. -####################################################################### -function Get-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [parameter(Mandatory)] - [string] $CollectionName, - [uint32] $ActiveSessionLimitMin, - [boolean] $AuthenticateUsingNLA, - [boolean] $AutomaticReconnectionEnabled, - [string] $BrokenConnectionAction, - [string] $ClientDeviceRedirectionOptions, - [boolean] $ClientPrinterAsDefault, - [boolean] $ClientPrinterRedirected, - [string] $CollectionDescription, - [string] $ConnectionBroker, - [string] $CustomRdpProperty, - [uint32] $DisconnectedSessionLimitMin, - [string] $EncryptionLevel, - [uint32] $IdleSessionLimitMin, - [uint32] $MaxRedirectedMonitors, - [boolean] $RDEasyPrintDriverEnabled, - [string] $SecurityLayer, - [boolean] $TemporaryFoldersDeletedOnExit, - [string] $UserGroup - ) - Write-Verbose "Getting currently configured RDSH Collection properties" - $collectionName = Get-RDSessionCollection | % {Get-RDSessionHost $_.CollectionName} | ? {$_.SessionHost -ieq $localhost} | % {$_.CollectionName} - - $collectionGeneral = Get-RDSessionCollectionConfiguration -CollectionName $CollectionName - $collectionClient = Get-RDSessionCollectionConfiguration -CollectionName $CollectionName -Client - $collectionConnection = Get-RDSessionCollectionConfiguration -CollectionName $CollectionName -Connection - $collectionSecurity = Get-RDSessionCollectionConfiguration -CollectionName $CollectionName -Security - $collectionUserGroup = Get-RDSessionCollectionConfiguration -CollectionName $CollectionName -UserGroup - @{ - "CollectionName" = $collectionGeneral.CollectionName; - "ActiveSessionLimitMin" = $collectionConnection.ActiveSessionLimitMin; - "AuthenticateUsingNLA" = $collectionSecurity.AuthenticateUsingNLA; - "AutomaticReconnectionEnabled" = $collectionConnection.AutomaticReconnectionEnabled; - "BrokenConnectionAction" = $collectionConnection.BrokenConnectionAction; - "ClientDeviceRedirectionOptions" = $collectionClient.ClientDeviceRedirectionOptions; - "ClientPrinterAsDefault" = $collectionClient.ClientPrinterAsDefault; - "ClientPrinterRedirected" = $collectionClient.ClientPrinterRedirected; - "CollectionDescription" = $collectionGeneral.CollectionDescription; - "CustomRdpProperty" = $collectionGeneral.CustomRdpProperty; - "DisconnectedSessionLimitMin" = $collectionGeneral.DisconnectedSessionLimitMin; - "EncryptionLevel" = $collectionSecurity.EncryptionLevel; - "IdleSessionLimitMin" = $collectionConnection.IdleSessionLimitMin; - "MaxRedirectedMonitors" = $collectionClient.MaxRedirectedMonitors; - "RDEasyPrintDriverEnabled" = $collectionClient.RDEasyPrintDriverEnabled; - "SecurityLayer" = $collectionSecurity.SecurityLayer; - "TemporaryFoldersDeletedOnExit" = $collectionConnection.TemporaryFoldersDeletedOnExit; - "UserGroup" = $collectionUserGroup.UserGroup; - } -} - - -######################################################################## -# The Set-TargetResource cmdlet. -######################################################################## -function Set-TargetResource - -{ - [CmdletBinding()] - param - ( - [parameter(Mandatory)] - [string] $CollectionName, - [uint32] $ActiveSessionLimitMin, - [boolean] $AuthenticateUsingNLA, - [boolean] $AutomaticReconnectionEnabled, - [string] $BrokenConnectionAction, - [string] $ClientDeviceRedirectionOptions, - [boolean] $ClientPrinterAsDefault, - [boolean] $ClientPrinterRedirected, - [string] $CollectionDescription, - [string] $ConnectionBroker, - [string] $CustomRdpProperty, - [uint32] $DisconnectedSessionLimitMin, - [string] $EncryptionLevel, - [uint32] $IdleSessionLimitMin, - [uint32] $MaxRedirectedMonitors, - [boolean] $RDEasyPrintDriverEnabled, - [string] $SecurityLayer, - [boolean] $TemporaryFoldersDeletedOnExit, - [string] $UserGroup - ) - Write-Verbose "Setting DSC collection properties" - $discoveredCollectionName = Get-RDSessionCollection | % {Get-RDSessionHost $_.CollectionName} | ? {$_.SessionHost -ieq $localhost} | % {$_.CollectionName} - if ($collectionName -ne $discoveredCollectionName) {$PSBoundParameters.collectionName = $discoveredCollectionName} - Set-RDSessionCollectionConfiguration @PSBoundParameters -} - - -####################################################################### -# The Test-TargetResource cmdlet. -####################################################################### -function Test-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - [parameter(Mandatory)] - [string] $CollectionName, - [uint32] $ActiveSessionLimitMin, - [boolean] $AuthenticateUsingNLA, - [boolean] $AutomaticReconnectionEnabled, - [string] $BrokenConnectionAction, - [string] $ClientDeviceRedirectionOptions, - [boolean] $ClientPrinterAsDefault, - [boolean] $ClientPrinterRedirected, - [string] $CollectionDescription, - [string] $ConnectionBroker, - [string] $CustomRdpProperty, - [uint32] $DisconnectedSessionLimitMin, - [string] $EncryptionLevel, - [uint32] $IdleSessionLimitMin, - [uint32] $MaxRedirectedMonitors, - [boolean] $RDEasyPrintDriverEnabled, - [string] $SecurityLayer, - [boolean] $TemporaryFoldersDeletedOnExit, - [string] $UserGroup - ) - - Write-Verbose "Testing DSC collection properties" - $collectionName = Get-RDSessionCollection | % {Get-RDSessionHost $_.CollectionName} | ? {$_.SessionHost -ieq $localhost} | % {$_.CollectionName} - $PSBoundParameters.Remove("Verbose") | out-null - $PSBoundParameters.Remove("Debug") | out-null - $PSBoundParameters.Remove("ConnectionBroker") | out-null - $Check = $true - - $Get = Get-TargetResource -CollectionName $CollectionName - $PSBoundParameters.keys | % {if ($PSBoundParameters[$_] -ne $Get[$_]) {$Check = $false} } - $Check -} - -Export-ModuleMember -Function *-TargetResource - +Import-Module -Name "$PSScriptRoot\..\..\xRemoteDesktopSessionHostCommon.psm1" +if (!(Test-xRemoteDesktopSessionHostOsRequirement)) { Throw "The minimum OS requirement was not met."} +Import-Module RemoteDesktop +$localhost = [System.Net.Dns]::GetHostByName((hostname)).HostName + + +####################################################################### +# The Get-TargetResource cmdlet. +####################################################################### +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [parameter(Mandatory)] + [ValidateLength(1,15)] + [string] $CollectionName, + [uint32] $ActiveSessionLimitMin, + [boolean] $AuthenticateUsingNLA, + [boolean] $AutomaticReconnectionEnabled, + [string] $BrokenConnectionAction, + [string] $ClientDeviceRedirectionOptions, + [boolean] $ClientPrinterAsDefault, + [boolean] $ClientPrinterRedirected, + [string] $CollectionDescription, + [string] $ConnectionBroker, + [string] $CustomRdpProperty, + [uint32] $DisconnectedSessionLimitMin, + [string] $EncryptionLevel, + [uint32] $IdleSessionLimitMin, + [uint32] $MaxRedirectedMonitors, + [boolean] $RDEasyPrintDriverEnabled, + [string] $SecurityLayer, + [boolean] $TemporaryFoldersDeletedOnExit, + [string] $UserGroup + ) + Write-Verbose "Getting currently configured RDSH Collection properties" + $collectionName = Get-RDSessionCollection | % {Get-RDSessionHost $_.CollectionName} | ? {$_.SessionHost -ieq $localhost} | % {$_.CollectionName} + + $collectionGeneral = Get-RDSessionCollectionConfiguration -CollectionName $CollectionName + $collectionClient = Get-RDSessionCollectionConfiguration -CollectionName $CollectionName -Client + $collectionConnection = Get-RDSessionCollectionConfiguration -CollectionName $CollectionName -Connection + $collectionSecurity = Get-RDSessionCollectionConfiguration -CollectionName $CollectionName -Security + $collectionUserGroup = Get-RDSessionCollectionConfiguration -CollectionName $CollectionName -UserGroup + @{ + "CollectionName" = $collectionGeneral.CollectionName; + "ActiveSessionLimitMin" = $collectionConnection.ActiveSessionLimitMin; + "AuthenticateUsingNLA" = $collectionSecurity.AuthenticateUsingNLA; + "AutomaticReconnectionEnabled" = $collectionConnection.AutomaticReconnectionEnabled; + "BrokenConnectionAction" = $collectionConnection.BrokenConnectionAction; + "ClientDeviceRedirectionOptions" = $collectionClient.ClientDeviceRedirectionOptions; + "ClientPrinterAsDefault" = $collectionClient.ClientPrinterAsDefault; + "ClientPrinterRedirected" = $collectionClient.ClientPrinterRedirected; + "CollectionDescription" = $collectionGeneral.CollectionDescription; + "CustomRdpProperty" = $collectionGeneral.CustomRdpProperty; + "DisconnectedSessionLimitMin" = $collectionGeneral.DisconnectedSessionLimitMin; + "EncryptionLevel" = $collectionSecurity.EncryptionLevel; + "IdleSessionLimitMin" = $collectionConnection.IdleSessionLimitMin; + "MaxRedirectedMonitors" = $collectionClient.MaxRedirectedMonitors; + "RDEasyPrintDriverEnabled" = $collectionClient.RDEasyPrintDriverEnabled; + "SecurityLayer" = $collectionSecurity.SecurityLayer; + "TemporaryFoldersDeletedOnExit" = $collectionConnection.TemporaryFoldersDeletedOnExit; + "UserGroup" = $collectionUserGroup.UserGroup; + } +} + + +######################################################################## +# The Set-TargetResource cmdlet. +######################################################################## +function Set-TargetResource + +{ + [CmdletBinding()] + param + ( + [parameter(Mandatory)] + [ValidateLength(1,15)] + [string] $CollectionName, + [uint32] $ActiveSessionLimitMin, + [boolean] $AuthenticateUsingNLA, + [boolean] $AutomaticReconnectionEnabled, + [string] $BrokenConnectionAction, + [string] $ClientDeviceRedirectionOptions, + [boolean] $ClientPrinterAsDefault, + [boolean] $ClientPrinterRedirected, + [string] $CollectionDescription, + [string] $ConnectionBroker, + [string] $CustomRdpProperty, + [uint32] $DisconnectedSessionLimitMin, + [string] $EncryptionLevel, + [uint32] $IdleSessionLimitMin, + [uint32] $MaxRedirectedMonitors, + [boolean] $RDEasyPrintDriverEnabled, + [string] $SecurityLayer, + [boolean] $TemporaryFoldersDeletedOnExit, + [string] $UserGroup + ) + Write-Verbose "Setting DSC collection properties" + $discoveredCollectionName = Get-RDSessionCollection | % {Get-RDSessionHost $_.CollectionName} | ? {$_.SessionHost -ieq $localhost} | % {$_.CollectionName} + if ($collectionName -ne $discoveredCollectionName) {$PSBoundParameters.collectionName = $discoveredCollectionName} + Set-RDSessionCollectionConfiguration @PSBoundParameters +} + + +####################################################################### +# The Test-TargetResource cmdlet. +####################################################################### +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [parameter(Mandatory)] + [ValidateLength(1,15)] + [string] $CollectionName, + [uint32] $ActiveSessionLimitMin, + [boolean] $AuthenticateUsingNLA, + [boolean] $AutomaticReconnectionEnabled, + [string] $BrokenConnectionAction, + [string] $ClientDeviceRedirectionOptions, + [boolean] $ClientPrinterAsDefault, + [boolean] $ClientPrinterRedirected, + [string] $CollectionDescription, + [string] $ConnectionBroker, + [string] $CustomRdpProperty, + [uint32] $DisconnectedSessionLimitMin, + [string] $EncryptionLevel, + [uint32] $IdleSessionLimitMin, + [uint32] $MaxRedirectedMonitors, + [boolean] $RDEasyPrintDriverEnabled, + [string] $SecurityLayer, + [boolean] $TemporaryFoldersDeletedOnExit, + [string] $UserGroup + ) + + Write-Verbose "Testing DSC collection properties" + $collectionName = Get-RDSessionCollection | % {Get-RDSessionHost $_.CollectionName} | ? {$_.SessionHost -ieq $localhost} | % {$_.CollectionName} + $PSBoundParameters.Remove("Verbose") | out-null + $PSBoundParameters.Remove("Debug") | out-null + $PSBoundParameters.Remove("ConnectionBroker") | out-null + $Check = $true + + $Get = Get-TargetResource -CollectionName $CollectionName + $PSBoundParameters.keys | % {if ($PSBoundParameters[$_] -ne $Get[$_]) {$Check = $false} } + $Check +} + +Export-ModuleMember -Function *-TargetResource + diff --git a/tests/unit/MSFT_xRDRemoteApp.tests.ps1 b/tests/unit/MSFT_xRDRemoteApp.tests.ps1 new file mode 100644 index 0000000..d201c70 --- /dev/null +++ b/tests/unit/MSFT_xRDRemoteApp.tests.ps1 @@ -0,0 +1,90 @@ +$Global:DSCModuleName = '.\xRemoteDesktopSessionHost' # Example xNetworking +$Global:DSCResourceName = 'MSFT_xRDRemoteApp' # Example MSFT_xFirewall + +#region HEADER +[String] $moduleRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path)) +if ( (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` + (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +{ + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $moduleRoot -ChildPath '\DSCResource.Tests\')) +} +else +{ + & git @('-C',(Join-Path -Path $moduleRoot -ChildPath '\DSCResource.Tests\'),'pull') +} +Import-Module (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $Global:DSCModuleName ` + -DSCResourceName $Global:DSCResourceName ` + -TestType Unit +#endregion + +# Begin Testing + +try +{ + InModuleScope $Global:DSCResourceName { + + #region Pester Test Initialization + # TODO: Optopnal Load Mock for use in Pester tests here... + #endregion + + $testInvalidCollectionName = 'InvalidCollectionName longer than 15' + + Import-Module RemoteDesktop -Force + + #region Function Get-TargetResource + Describe "$($Global:DSCResourceName)\Get-TargetResource" { + Context "Parameter Values,Validations and Errors" { + + It "Should error when CollectionName length is greater than 15" { + {Get-TargetResource ` + -CollectionName = $testInvalidCollectionName ` + -DisplayName = 'name' ` + -FilePath = 'path' ` + -Alias = 'alias' ` + } | should throw + } + } + } + #endregion + + #region Function Set-TargetResource + Describe "$($Global:DSCResourceName)\Set-TargetResource" { + Context "Parameter Values,Validations and Errors" { + + It "Should error when CollectionName length is greater than 15" { + {Set-TargetResource ` + -CollectionName = $testInvalidCollectionName ` + -DisplayName = 'name' ` + -FilePath = 'path' ` + -Alias = 'alias' ` + } | should throw + } + } + } + #endregion + + #region Function Test-TargetResource + Describe "$($Global:DSCResourceName)\Test-TargetResource" { + Context "Parameter Values,Validations and Errors" { + + It "Should error when CollectionName length is greater than 15" { + {Test-TargetResource ` + -CollectionName = $testInvalidCollectionName ` + -DisplayName = 'name' ` + -FilePath = 'path' ` + -Alias = 'alias' ` + } | should throw + } + } + } + #endregion + } +} +finally +{ + #region FOOTER + Restore-TestEnvironment -TestEnvironment $TestEnvironment + #endregion +} diff --git a/tests/unit/MSFT_xRDSessionCollection.tests.ps1 b/tests/unit/MSFT_xRDSessionCollection.tests.ps1 new file mode 100644 index 0000000..9be344c --- /dev/null +++ b/tests/unit/MSFT_xRDSessionCollection.tests.ps1 @@ -0,0 +1,79 @@ +$Global:DSCModuleName = '.\xRemoteDesktopSessionHost' # Example xNetworking +$Global:DSCResourceName = 'MSFT_xRDSessionCollection' # Example MSFT_xFirewall + +#region HEADER +[String] $moduleRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path)) +if ( (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` + (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +{ + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $moduleRoot -ChildPath '\DSCResource.Tests\')) +} +else +{ + & git @('-C',(Join-Path -Path $moduleRoot -ChildPath '\DSCResource.Tests\'),'pull') +} +Import-Module (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $Global:DSCModuleName ` + -DSCResourceName $Global:DSCResourceName ` + -TestType Unit +#endregion + +# Begin Testing + +try +{ + InModuleScope $Global:DSCResourceName { + + #region Pester Test Initialization + # TODO: Optopnal Load Mock for use in Pester tests here... + #endregion + + $testInvalidCollectionName = 'InvalidCollectionName longer than 15' + $testSessionHost = 'localhost' + + Import-Module RemoteDesktop -Force + + #region Function Get-TargetResource + Describe "$($Global:DSCResourceName)\Get-TargetResource" { + Context "Parameter Values,Validations and Errors" { + + It "Should error when CollectionName length is greater than 15" { + {Get-TargetResource -CollectionName $testInvalidCollectionName -SessionHost $testSessionHost} ` + | should throw + } + } + } + #endregion + + #region Function Set-TargetResource + Describe "$($Global:DSCResourceName)\Set-TargetResource" { + Context "Parameter Values,Validations and Errors" { + + It "Should error when CollectionName length is greater than 15" { + {Set-TargetResource -CollectionName $testInvalidCollectionName -SessionHost $testSessionHost} ` + | should throw + } + } + } + #endregion + + #region Function Test-TargetResource + Describe "$($Global:DSCResourceName)\Test-TargetResource" { + Context "Parameter Values,Validations and Errors" { + + It "Should error when CollectionName length is greater than 15" { + {Test-TargetResource -CollectionName $testInvalidCollectionName -SessionHost $testSessionHost} ` + | should throw + } + } + } + #endregion + } +} +finally +{ + #region FOOTER + Restore-TestEnvironment -TestEnvironment $TestEnvironment + #endregion +} diff --git a/tests/unit/MSFT_xRDSessionCollectionConfiguration.tests.ps1 b/tests/unit/MSFT_xRDSessionCollectionConfiguration.tests.ps1 new file mode 100644 index 0000000..46bea81 --- /dev/null +++ b/tests/unit/MSFT_xRDSessionCollectionConfiguration.tests.ps1 @@ -0,0 +1,78 @@ +$Global:DSCModuleName = '.\xRemoteDesktopSessionHost' # Example xNetworking +$Global:DSCResourceName = 'MSFT_xRDSessionCollectionConfiguration' # Example MSFT_xFirewall + +#region HEADER +[String] $moduleRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path)) +if ( (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` + (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +{ + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $moduleRoot -ChildPath '\DSCResource.Tests\')) +} +else +{ + & git @('-C',(Join-Path -Path $moduleRoot -ChildPath '\DSCResource.Tests\'),'pull') +} +Import-Module (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $Global:DSCModuleName ` + -DSCResourceName $Global:DSCResourceName ` + -TestType Unit +#endregion + +# Begin Testing + +try +{ + InModuleScope $Global:DSCResourceName { + + #region Pester Test Initialization + # TODO: Optopnal Load Mock for use in Pester tests here... + #endregion + + $testInvalidCollectionName = 'InvalidCollectionName longer than 15' + + Import-Module RemoteDesktop -Force + + #region Function Get-TargetResource + Describe "$($Global:DSCResourceName)\Get-TargetResource" { + Context "Parameter Values,Validations and Errors" { + + It "Should error when CollectionName length is greater than 15" { + {Get-TargetResource -CollectionName $testInvalidCollectionName} ` + | should throw + } + } + } + #endregion + + #region Function Set-TargetResource + Describe "$($Global:DSCResourceName)\Set-TargetResource" { + Context "Parameter Values,Validations and Errors" { + + It "Should error when CollectionName length is greater than 15" { + {Set-TargetResource -CollectionName $testInvalidCollectionName} ` + | should throw + } + } + } + #endregion + + #region Function Test-TargetResource + Describe "$($Global:DSCResourceName)\Test-TargetResource" { + Context "Parameter Values,Validations and Errors" { + + It "Should error when CollectionName length is greater than 15" { + {Test-TargetResource -CollectionName $testInvalidCollectionName} ` + | should throw + } + } + } + #endregion + } +} +finally +{ + #region FOOTER + Restore-TestEnvironment -TestEnvironment $TestEnvironment + #endregion +} From 047a011646accf5369713d374945b56f32ada31f Mon Sep 17 00:00:00 2001 From: Jim Priestley Date: Fri, 13 Jan 2017 17:59:15 -0500 Subject: [PATCH 2/3] Updated documentation for changes made. --- README.md | 521 +++++++++++++++++++++++++++--------------------------- 1 file changed, 261 insertions(+), 260 deletions(-) diff --git a/README.md b/README.md index 756fcf5..894a354 100644 --- a/README.md +++ b/README.md @@ -1,260 +1,261 @@ -[![Build status](https://ci.appveyor.com/api/projects/status/ly6w6vaavkshrpg8/branch/master?svg=true)](https://ci.appveyor.com/project/PowerShell/xremotedesktopsessionhost/branch/master) - -# xRemoteDesktopSessionHost - -The **xRemoteDesktopSessionHost** module contains the **xRDSessionDeployment**, **xRDSessionCollection**, **xRDSessionCollectionConfiguration**, and **xRDRemoteApp** resources, allowing creation and configuration of a Remote Desktop Session Host (RDSH) instance. - - -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). -For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. - -## Contributing -Please check out common DSC Resources [contributing guidelines](https://github.com/PowerShell/DscResource.Kit/blob/master/CONTRIBUTING.md). - - -## Resources - -* **xRDSessionDeployment** creates and configures a deployment in RDSH. -* **xRDSessionCollection** creates an RDSH collection. -* **xRDSessionCollectionConfiguration** configures an RDSH collection. -* **xRDRemoteApp** publishes applications for your RDSH collection. - -### xRDSessionDeployment - -* **SessionHost**: Specifies the FQDN of a servers to host the RD Session Host role service. -* **ConnectionBroker**: The FQDN of a server to host the RD Connection Broker role service. -* **WebAccessServer**: The FQDN of a server to host the RD Web Access role service. - -### xRDSessionCollection - -* **CollectionName**: Specifies a name for the session collection -* **SessionHost**: Specifies a RD Session Host server to include in the session collection. -* **CollectionDescription**: A description for the collection. -* **ConnectionBroker**: The Remote Desktop Connection Broker (RD Connection Broker) server for a Remote Desktop deployment. - -### xRDSessionCollectionConfiguration - -* **CollectionName**: Specifies the name for the session collection. -* **ActiveSessionLimitMin**: Specifies the maximum time, in minutes, an active session runs. -After this period, the RD Session Host server ends the session. -* **AuthenticateUsingNLA**: Indicates whether to use Network Level Authentication (NLA). -If this value is $True, Remote Desktop uses NLA to authenticate a user before the user sees a logon screen. -* **AutomaticReconnectionEnabled**: Indicates whether the Remote Desktop client attempts to reconnect after a connection interruption. -* **BrokenConnectionAction**: Specifies an action for an RD Session Host server to take after a connection interruption. -* **ClientDeviceRedirectionOptions**: Specifies a type of client device to be redirected to an RD Session Host server in this session collection. -* **ClientPrinterAsDefault**: Indicates whether to use the client printer or server printer as the default printer. -If this value is $True, use the client printer as default. -If this value is $False, use the server as default. -* **ClientPrinterRedirected**: Indicates whether to use client printer redirection, which routes print jobs from the Remote Desktop session to a printer attached to the client computer. -* **CollectionDescription**: Specifies a description of the session collection. -* **ConnectionBroker**: Specifies the Remote Desktop Connection Broker (RD Connection Broker) server for a Remote Desktop deployment. -* **CustomRdpProperty**: Specifies Remote Desktop Protocol (RDP) settings to include in the .rdp files for all Windows Server 2012 RemoteApp programs and remote desktops published in this collection. -* **DisconnectedSessionLimitMin**: Specifies a length of time, in minutes. -After client disconnection from a session for this period, the RD Session Host ends the session. -* **EncryptionLevel**: Specifies the level of data encryption used for a Remote Desktop session. -* **IdleSessionLimitMin**: Specifies the length of time, in minutes, to wait before an RD Session Host logs off or disconnects an idle session. -* The BrokenConnectionAction parameter determines whether to log off or disconnect. -* **MaxRedirectedMonitors**: Specifies the maximum number of client monitors that an RD Session Host server can redirect to a remote session. -The maximum value for this parameter is 16. -* **RDEasyPrintDriverEnabled**: Specifies whether to enable the Remote Desktop Easy Print driver. -* **SecurityLayer**: Specifies which security protocol to use. -* **TemporaryFoldersDeletedOnExit**: Whether to delete temporary folders from the RD Session Host server for a disconnected session. -* **UserGroup**: Specifies a domain group authorized to connect to the RD Session Host servers in a session collection. - -### xRDRemoteApp - -* **Alias**: Specifies an alias for the RemoteApp program. -* **CollectionName**: Specifies the name of the personal virtual desktop collection or session collection. -The cmdlet publishes the RemoteApp program to this collection. -* **DisplayName**: Specifies a name to display to users for the RemoteApp program. -* **FilePath**: Specifies a path for the executable file for the application. -Note: Do not include any environment variables. -* **FileVirtualPath**: Specifies a path for the application executable file. -This path resolves to the same location as the value of the FilePath parameter, but it can include environment variables. -* **FolderName**: Specifies the name of the folder that the RemoteApp program appears in on the Remote Desktop Web Access (RD Web Access) webpage and in the Start menu for subscribed RemoteApp and Desktop Connections. -* **CommandLineSetting**: Specifies whether the RemoteApp program accepts command-line arguments from the client at connection time. -* **RequiredCommandLine**: Specifies a string that contains command-line arguments that the client can use at connection time with the RemoteApp program. -* **IconIndex**: Specifies the index within the icon file (specified by the IconPath parameter) where the RemoteApp program’s icon can be found. -* **IconPath**: Specifies the path to a file containing the icon to display for the RemoteApp program identified by the Alias parameter. -* **UserGroups**: Specifies a domain group that can view the RemoteApp in RD Web Access, and in RemoteApp and Desktop Connections. -To allow all users to see a RemoteApp program, provide a value of Null. -* **ShowInWebAccess**: Specifies whether to show the RemoteApp program in the RD Web Access server, and in RemoteApp and Desktop Connections that the user subscribes to. - -## Versions - -### Unreleased - -### 1.3.0.0 -* Converted appveyor.yml to install Pester from PSGallery instead of from Chocolatey. - -### 1.2.0.0 - -* Fixed an issue with version checks where OS version greater than 9 would fail (Windows 10/Server 2016) - -### 1.1.0.0 - -* Fixed encoding - -### 1.0.1 - -### 1.0.0.0 - -* Initial release with the following resources - * **xRDSessionDeployment** - * **xRDSessionCollection** - * **xRDSessionCollectionConfiguration** - * **xRDRemoteApp** - - - -## Examples - -### End to End - -```powershell -param ( -[string]$brokerFQDN, -[string]$webFQDN, -[string]$collectionName, -[string]$collectionDescription -) - -$localhost = [System.Net.Dns]::GetHostByName((hostname)).HostName - -if (!$collectionName) {$collectionName = "Tenant Jump Box"} -if (!$collectionDescription) {$collectionDescription = "Remote Desktop instance for accessing an isolated network environment."} - -Configuration RemoteDesktopSessionHost -{ - param - ( - - # Connection Broker Name - [Parameter(Mandatory)] - [String]$collectionName, - - # Connection Broker Description - [Parameter(Mandatory)] - [String]$collectionDescription, - - # Connection Broker Node Name - [String]$connectionBroker, - - # Web Access Node Name - [String]$webAccessServer - ) - Import-DscResource -Module xRemoteDesktopSessionHost - if (!$connectionBroker) {$connectionBroker = $localhost} - if (!$connectionWebAccessServer) {$webAccessServer = $localhost} - - Node "localhost" - { - - LocalConfigurationManager - { - RebootNodeIfNeeded = $true - } - - WindowsFeature Remote-Desktop-Services - { - Ensure = "Present" - Name = "Remote-Desktop-Services" - } - - WindowsFeature RDS-RD-Server - { - Ensure = "Present" - Name = "RDS-RD-Server" - } - - WindowsFeature Desktop-Experience - { - Ensure = "Present" - Name = "Desktop-Experience" - } - - WindowsFeature RSAT-RDS-Tools - { - Ensure = "Present" - Name = "RSAT-RDS-Tools" - IncludeAllSubFeature = $true - } - - if ($localhost -eq $connectionBroker) { - WindowsFeature RDS-Connection-Broker - { - Ensure = "Present" - Name = "RDS-Connection-Broker" - } - } - - if ($localhost -eq $webAccessServer) { - WindowsFeature RDS-Web-Access - { - Ensure = "Present" - Name = "RDS-Web-Access" - } - } - - WindowsFeature RDS-Licensing - { - Ensure = "Present" - Name = "RDS-Licensing" - } - - xRDSessionDeployment Deployment - { - SessionHost = $localhost - ConnectionBroker = if ($ConnectionBroker) {$ConnectionBroker} else {$localhost} - WebAccessServer = if ($WebAccessServer) {$WebAccessServer} else {$localhost} - DependsOn = "[WindowsFeature]Remote-Desktop-Services", "[WindowsFeature]RDS-RD-Server" - } - - xRDSessionCollection Collection - { - CollectionName = $collectionName - CollectionDescription = $collectionDescription - SessionHost = $localhost - ConnectionBroker = if ($ConnectionBroker) {$ConnectionBroker} else {$localhost} - DependsOn = "[xRDSessionDeployment]Deployment" - } - xRDSessionCollectionConfiguration CollectionConfiguration - { - CollectionName = $collectionName - CollectionDescription = $collectionDescription - ConnectionBroker = if ($ConnectionBroker) {$ConnectionBroker} else {$localhost} - TemporaryFoldersDeletedOnExit = $false - SecurityLayer = "SSL" - DependsOn = "[xRDSessionCollection]Collection" - } - xRDRemoteApp Calc - { - CollectionName = $collectionName - DisplayName = "Calculator" - FilePath = "C:\Windows\System32\calc.exe" - Alias = "calc" - DependsOn = "[xRDSessionCollection]Collection" - } - xRDRemoteApp Mstsc - { - CollectionName = $collectionName - DisplayName = "Remote Desktop" - FilePath = "C:\Windows\System32\mstsc.exe" - Alias = "mstsc" - DependsOn = "[xRDSessionCollection]Collection" - } - } -} - -write-verbose "Creating configuration with parameter values:" -write-verbose "Collection Name: $collectionName" -write-verbose "Collection Description: $collectionDescription" -write-verbose "Connection Broker: $brokerFQDN" -write-verbose "Web Access Server: $webFQDN" - -RemoteDesktopSessionHost -collectionName $collectionName -collectionDescription $collectionDescription -connectionBroker $brokerFQDN -webAccessServer $webFQDN -OutputPath .\RDSDSC\ - -Set-DscLocalConfigurationManager -verbose -path .\RDSDSC\ - -Start-DscConfiguration -wait -force -verbose -path .\RDSDSC\ -``` +[![Build status](https://ci.appveyor.com/api/projects/status/ly6w6vaavkshrpg8/branch/master?svg=true)](https://ci.appveyor.com/project/PowerShell/xremotedesktopsessionhost/branch/master) + +# xRemoteDesktopSessionHost + +The **xRemoteDesktopSessionHost** module contains the **xRDSessionDeployment**, **xRDSessionCollection**, **xRDSessionCollectionConfiguration**, and **xRDRemoteApp** resources, allowing creation and configuration of a Remote Desktop Session Host (RDSH) instance. + + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). +For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. + +## Contributing +Please check out common DSC Resources [contributing guidelines](https://github.com/PowerShell/DscResource.Kit/blob/master/CONTRIBUTING.md). + + +## Resources + +* **xRDSessionDeployment** creates and configures a deployment in RDSH. +* **xRDSessionCollection** creates an RDSH collection. +* **xRDSessionCollectionConfiguration** configures an RDSH collection. +* **xRDRemoteApp** publishes applications for your RDSH collection. + +### xRDSessionDeployment + +* **SessionHost**: Specifies the FQDN of a servers to host the RD Session Host role service. +* **ConnectionBroker**: The FQDN of a server to host the RD Connection Broker role service. +* **WebAccessServer**: The FQDN of a server to host the RD Web Access role service. + +### xRDSessionCollection + +* **CollectionName**: Specifies a name for the session collection +* **SessionHost**: Specifies a RD Session Host server to include in the session collection. +* **CollectionDescription**: A description for the collection. +* **ConnectionBroker**: The Remote Desktop Connection Broker (RD Connection Broker) server for a Remote Desktop deployment. + +### xRDSessionCollectionConfiguration + +* **CollectionName**: Specifies the name for the session collection. +* **ActiveSessionLimitMin**: Specifies the maximum time, in minutes, an active session runs. +After this period, the RD Session Host server ends the session. +* **AuthenticateUsingNLA**: Indicates whether to use Network Level Authentication (NLA). +If this value is $True, Remote Desktop uses NLA to authenticate a user before the user sees a logon screen. +* **AutomaticReconnectionEnabled**: Indicates whether the Remote Desktop client attempts to reconnect after a connection interruption. +* **BrokenConnectionAction**: Specifies an action for an RD Session Host server to take after a connection interruption. +* **ClientDeviceRedirectionOptions**: Specifies a type of client device to be redirected to an RD Session Host server in this session collection. +* **ClientPrinterAsDefault**: Indicates whether to use the client printer or server printer as the default printer. +If this value is $True, use the client printer as default. +If this value is $False, use the server as default. +* **ClientPrinterRedirected**: Indicates whether to use client printer redirection, which routes print jobs from the Remote Desktop session to a printer attached to the client computer. +* **CollectionDescription**: Specifies a description of the session collection. +* **ConnectionBroker**: Specifies the Remote Desktop Connection Broker (RD Connection Broker) server for a Remote Desktop deployment. +* **CustomRdpProperty**: Specifies Remote Desktop Protocol (RDP) settings to include in the .rdp files for all Windows Server 2012 RemoteApp programs and remote desktops published in this collection. +* **DisconnectedSessionLimitMin**: Specifies a length of time, in minutes. +After client disconnection from a session for this period, the RD Session Host ends the session. +* **EncryptionLevel**: Specifies the level of data encryption used for a Remote Desktop session. +* **IdleSessionLimitMin**: Specifies the length of time, in minutes, to wait before an RD Session Host logs off or disconnects an idle session. +* The BrokenConnectionAction parameter determines whether to log off or disconnect. +* **MaxRedirectedMonitors**: Specifies the maximum number of client monitors that an RD Session Host server can redirect to a remote session. +The maximum value for this parameter is 16. +* **RDEasyPrintDriverEnabled**: Specifies whether to enable the Remote Desktop Easy Print driver. +* **SecurityLayer**: Specifies which security protocol to use. +* **TemporaryFoldersDeletedOnExit**: Whether to delete temporary folders from the RD Session Host server for a disconnected session. +* **UserGroup**: Specifies a domain group authorized to connect to the RD Session Host servers in a session collection. + +### xRDRemoteApp + +* **Alias**: Specifies an alias for the RemoteApp program. +* **CollectionName**: Specifies the name of the personal virtual desktop collection or session collection. +The cmdlet publishes the RemoteApp program to this collection. +* **DisplayName**: Specifies a name to display to users for the RemoteApp program. +* **FilePath**: Specifies a path for the executable file for the application. +Note: Do not include any environment variables. +* **FileVirtualPath**: Specifies a path for the application executable file. +This path resolves to the same location as the value of the FilePath parameter, but it can include environment variables. +* **FolderName**: Specifies the name of the folder that the RemoteApp program appears in on the Remote Desktop Web Access (RD Web Access) webpage and in the Start menu for subscribed RemoteApp and Desktop Connections. +* **CommandLineSetting**: Specifies whether the RemoteApp program accepts command-line arguments from the client at connection time. +* **RequiredCommandLine**: Specifies a string that contains command-line arguments that the client can use at connection time with the RemoteApp program. +* **IconIndex**: Specifies the index within the icon file (specified by the IconPath parameter) where the RemoteApp program's icon can be found. +* **IconPath**: Specifies the path to a file containing the icon to display for the RemoteApp program identified by the Alias parameter. +* **UserGroups**: Specifies a domain group that can view the RemoteApp in RD Web Access, and in RemoteApp and Desktop Connections. +To allow all users to see a RemoteApp program, provide a value of Null. +* **ShowInWebAccess**: Specifies whether to show the RemoteApp program in the RD Web Access server, and in RemoteApp and Desktop Connections that the user subscribes to. + +## Versions + +### Unreleased +* Updated CollectionName parameter to validate length between 1 and 15 characters, and added tests to verify. + +### 1.3.0.0 +* Converted appveyor.yml to install Pester from PSGallery instead of from Chocolatey. + +### 1.2.0.0 + +* Fixed an issue with version checks where OS version greater than 9 would fail (Windows 10/Server 2016) + +### 1.1.0.0 + +* Fixed encoding + +### 1.0.1 + +### 1.0.0.0 + +* Initial release with the following resources + * **xRDSessionDeployment** + * **xRDSessionCollection** + * **xRDSessionCollectionConfiguration** + * **xRDRemoteApp** + + + +## Examples + +### End to End + +```powershell +param ( +[string]$brokerFQDN, +[string]$webFQDN, +[string]$collectionName, +[string]$collectionDescription +) + +$localhost = [System.Net.Dns]::GetHostByName((hostname)).HostName + +if (!$collectionName) {$collectionName = "Tenant Jump Box"} +if (!$collectionDescription) {$collectionDescription = "Remote Desktop instance for accessing an isolated network environment."} + +Configuration RemoteDesktopSessionHost +{ + param + ( + + # Connection Broker Name + [Parameter(Mandatory)] + [String]$collectionName, + + # Connection Broker Description + [Parameter(Mandatory)] + [String]$collectionDescription, + + # Connection Broker Node Name + [String]$connectionBroker, + + # Web Access Node Name + [String]$webAccessServer + ) + Import-DscResource -Module xRemoteDesktopSessionHost + if (!$connectionBroker) {$connectionBroker = $localhost} + if (!$connectionWebAccessServer) {$webAccessServer = $localhost} + + Node "localhost" + { + + LocalConfigurationManager + { + RebootNodeIfNeeded = $true + } + + WindowsFeature Remote-Desktop-Services + { + Ensure = "Present" + Name = "Remote-Desktop-Services" + } + + WindowsFeature RDS-RD-Server + { + Ensure = "Present" + Name = "RDS-RD-Server" + } + + WindowsFeature Desktop-Experience + { + Ensure = "Present" + Name = "Desktop-Experience" + } + + WindowsFeature RSAT-RDS-Tools + { + Ensure = "Present" + Name = "RSAT-RDS-Tools" + IncludeAllSubFeature = $true + } + + if ($localhost -eq $connectionBroker) { + WindowsFeature RDS-Connection-Broker + { + Ensure = "Present" + Name = "RDS-Connection-Broker" + } + } + + if ($localhost -eq $webAccessServer) { + WindowsFeature RDS-Web-Access + { + Ensure = "Present" + Name = "RDS-Web-Access" + } + } + + WindowsFeature RDS-Licensing + { + Ensure = "Present" + Name = "RDS-Licensing" + } + + xRDSessionDeployment Deployment + { + SessionHost = $localhost + ConnectionBroker = if ($ConnectionBroker) {$ConnectionBroker} else {$localhost} + WebAccessServer = if ($WebAccessServer) {$WebAccessServer} else {$localhost} + DependsOn = "[WindowsFeature]Remote-Desktop-Services", "[WindowsFeature]RDS-RD-Server" + } + + xRDSessionCollection Collection + { + CollectionName = $collectionName + CollectionDescription = $collectionDescription + SessionHost = $localhost + ConnectionBroker = if ($ConnectionBroker) {$ConnectionBroker} else {$localhost} + DependsOn = "[xRDSessionDeployment]Deployment" + } + xRDSessionCollectionConfiguration CollectionConfiguration + { + CollectionName = $collectionName + CollectionDescription = $collectionDescription + ConnectionBroker = if ($ConnectionBroker) {$ConnectionBroker} else {$localhost} + TemporaryFoldersDeletedOnExit = $false + SecurityLayer = "SSL" + DependsOn = "[xRDSessionCollection]Collection" + } + xRDRemoteApp Calc + { + CollectionName = $collectionName + DisplayName = "Calculator" + FilePath = "C:\Windows\System32\calc.exe" + Alias = "calc" + DependsOn = "[xRDSessionCollection]Collection" + } + xRDRemoteApp Mstsc + { + CollectionName = $collectionName + DisplayName = "Remote Desktop" + FilePath = "C:\Windows\System32\mstsc.exe" + Alias = "mstsc" + DependsOn = "[xRDSessionCollection]Collection" + } + } +} + +write-verbose "Creating configuration with parameter values:" +write-verbose "Collection Name: $collectionName" +write-verbose "Collection Description: $collectionDescription" +write-verbose "Connection Broker: $brokerFQDN" +write-verbose "Web Access Server: $webFQDN" + +RemoteDesktopSessionHost -collectionName $collectionName -collectionDescription $collectionDescription -connectionBroker $brokerFQDN -webAccessServer $webFQDN -OutputPath .\RDSDSC\ + +Set-DscLocalConfigurationManager -verbose -path .\RDSDSC\ + +Start-DscConfiguration -wait -force -verbose -path .\RDSDSC\ +``` From 0f21cd0a6f4d11c872a99d3483fede050d51765c Mon Sep 17 00:00:00 2001 From: Jim Priestley Date: Fri, 13 Jan 2017 18:02:56 -0500 Subject: [PATCH 3/3] Added required newline to xRemoteDesktopSessionHostCommon.psm1 --- xRemoteDesktopSessionHostCommon.psm1 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/xRemoteDesktopSessionHostCommon.psm1 b/xRemoteDesktopSessionHostCommon.psm1 index b21f557..83aab73 100644 --- a/xRemoteDesktopSessionHostCommon.psm1 +++ b/xRemoteDesktopSessionHostCommon.psm1 @@ -1,12 +1,12 @@ -function Test-xRemoteDesktopSessionHostOsRequirement -{ - return (Get-OsVersion) -ge (new-object 'Version' 6,2,9200,0) -} - -function Get-OsVersion -{ - return [Environment]::OSVersion.Version -} -Export-ModuleMember -Function @( - 'Test-xRemoteDesktopSessionHostOsRequirement' -) \ No newline at end of file +function Test-xRemoteDesktopSessionHostOsRequirement +{ + return (Get-OsVersion) -ge (new-object 'Version' 6,2,9200,0) +} + +function Get-OsVersion +{ + return [Environment]::OSVersion.Version +} +Export-ModuleMember -Function @( + 'Test-xRemoteDesktopSessionHostOsRequirement' +)