In this post we will see how to install Remote Desktop Services, how to configure session collection, how to set the configuration parameters and to publish the application. All using powershell

As there is a restart required while installing the RDS roles, it is better we fire the commandlets from outside the VM.

#Server Variables
 $vmName = "RDSServerName"
 $hostname = "RDSServerName_FQDN"
 $licenseServerName = "RDSLicenseServerName_FQDN"
 $collectionName = "MyCollection"

 #Fetching the domain user credentials which has admin privilege to the RDS server
 $cred = Get-Credential domainName\userName

 #Installing RDS Roles
 Invoke-command -scriptblock {
 Install-WindowsFeature -Name RDS-Connection-Broker, RDS-RD-Server, RDS-Web-Access -IncludeManagementTools -IncludeAllSubFeature -Restart
 } -ComputerName $hostname -Credential $cred
 
 #Sleep for 1 minute while the VM restarts
 Start-Sleep -Seconds 60

 #RDS Configuration
 Invoke-command -scriptblock {
     #Adding session deployment
     New-RDSessionDeployment -ConnectionBroker $Using:$hostname -SessionHost $Using:$hostname -WebAccessServer $Using:hostname
     
    #setting license server and license mode  
    Set-RDLicenseConfiguration -Mode PerDevice -ConnectionBroker $Using:hostname -LicenseServer $licenseServerName -Force  

    New-RDSessionCollection -CollectionName $collectionName -SessionHost $Using:hostname -ConnectionBroker $Using:hostname  

    #Creating new collection and setting profile folder  
    New-Item -Path C:\ -Name UserProfileDisk -ItemType Directory  

    Set-RDSessionCollectionConfiguration -CollectionName $collectionName -DisconnectedSessionLimitMin 30 -IdleSessionLimitMin 30 -AuthenticateUsingNLA $false -EncryptionLevel ClientCompatible  -SecurityLayer Negotiate -TemporaryFoldersDeletedOnExit $true  

    Set-RDSessionCollectionConfiguration -CollectionName $collectionName   -EnableUserProfileDisk -MaxUserProfileDiskSizeGB 5 -DiskPath C:\UserProfileDisk  

    #Publishing the installed application to the collection  
    New-RDRemoteApp -CollectionName $collectionName -DisplayName Calculator -FilePath "C:\Windows\System32\notepad.exe" -UserGroups groupname
 } -ComputerName $vmName -Credential $cred

Your RDS server is ready and you have successfully published your application – notepad

Thank you for reading my post. Hope this is helpful to you.