Last active
October 4, 2024 13:44
-
-
Save awakecoding/52bde805b3c3f17a17b3b4504d95fae0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| $ErrorActionPreference = "Stop" | |
| function Test-RDMGroup | |
| { | |
| [CmdletBinding()] | |
| param( | |
| [Parameter(Mandatory=$true,Position=0)] | |
| [string] $Name | |
| ) | |
| [bool] $(Get-RDMSession -GroupName $Name -ErrorAction SilentlyContinue) | |
| } | |
| function New-RdmTestDataSource | |
| { | |
| [CmdletBinding()] | |
| param( | |
| [Parameter(Mandatory=$true,Position=0)] | |
| [string] $DataSourceName, | |
| [string] $LabPrefix = "IT-HELP", | |
| [string] $UserName = "Administrator", | |
| [string] $Password = "DevoLabs123!", | |
| [bool] $Refresh = $True | |
| ) | |
| $LabName = "$LabPrefix-LAB" | |
| $VMAliases = @("DC", "CA", "DVLS", "GW", "WAC") | |
| $LabDnsTld = ".ninja" | |
| $LabCompanyName = "IT Help Ninja" | |
| $LabName = $LabPrefix.ToLower() + $LabDnsTld | |
| $DomainName = "ad.$LabName" | |
| $DnsZoneName = $DomainName | |
| $DomainDnsName = $DomainName | |
| $DomainAdminUPN = "Administrator@$DomainDnsName" | |
| $DomainPassword = $Password | |
| $DataSourceName = $DataSourceName | |
| if (-Not (Get-RDMDataSource | Select-Object -ExpandProperty Name).Contains($DataSourceName)) { | |
| $DBFileName = ($DataSourceName -Replace ' ', '') + ".db" | |
| $DBFilePath = "$Env:LocalAppData\Devolutions\RemoteDesktopManager\$DBFileName" | |
| Remove-Item -Path $DBFilePath -ErrorAction SilentlyContinue | Out-Null | |
| $Params = @{ | |
| Name = $DataSourceName; | |
| SQLite = $true; | |
| Database = $DBFilePath; | |
| } | |
| $DataSource = New-RDMDataSource @Params | |
| Set-RDMDataSource -DataSource $DataSource | |
| } | |
| $LabDataSource = Get-RDMDataSource -Name $DataSourceName | |
| Set-RDMDataSource -DataSource $LabDataSource | |
| Set-RDMCurrentDataSource -DataSource $LabDataSource | |
| # Lab Folder | |
| $LabFolderName = $LabCompanyName | |
| $LabGroupName = $LabFolderName | |
| if (-Not (Test-RDMGroup $LabGroupName)) { | |
| $LabFolder = New-RDMSession -Type "Group" -Name $LabFolderName | |
| $LabFolder.Group = $LabGroupName | |
| Set-RDMSession -Session $LabFolder -Refresh:$Refresh | |
| } | |
| # Active Directory Folder | |
| $ADFolderName = "Active Directory" | |
| $ADGroupName = "$LabFolderName\$ADFolderName" | |
| if (-Not (Test-RDMGroup $ADGroupName)) { | |
| $ADFolder = New-RDMSession -Type "Group" -Name $ADFolderName | |
| $ADFolder.Group = $ADGroupName | |
| Set-RDMSession -Session $ADFolder -Refresh:$Refresh | |
| } | |
| # Local Network Folder | |
| $LANFolderName = "Local Network" | |
| $LANGroupName = "$LabFolderName\$LANFolderName" | |
| if (-Not (Test-RDMGroup $LANGroupName)) { | |
| $LANFolder = New-RDMSession -Type "Group" -Name $LANFolderName | |
| $LANFolder.Group = $LANGroupName | |
| Set-RDMSession -Session $LANFolder -Refresh:$Refresh | |
| } | |
| # RD Gateway Folder | |
| $RDGFolderName = "RD Gateway" | |
| $RDGGroupName = "$LabFolderName\$RDGFolderName" | |
| if (-Not (Test-RDMGroup $RDGGroupName)) { | |
| $RDGFolder = New-RDMSession -Type "Group" -Name $RDGFolderName | |
| $RDGFolder.Group = $RDGGroupName | |
| Set-RDMSession -Session $RDGFolder -Refresh:$Refresh | |
| } | |
| # Devolutions Gateway Folder | |
| $DGWFolderName = "Devolutions Gateway" | |
| $DGWGroupName = "$LabFolderName\$DGWFolderName" | |
| if (-Not (Test-RDMGroup $DGWGroupName)) { | |
| $DGWFolder = New-RDMSession -Type "Group" -Name $DGWFolderName | |
| $DGWFolder.Group = $DGWGroupName | |
| Set-RDMSession -Session $DGWFolder -Refresh:$Refresh | |
| } | |
| # Hyper-V Folder | |
| $HVFolderName = "Hyper-V Host" | |
| $HVGroupName = "$LabFolderName\$HVFolderName" | |
| if (-Not (Test-RDMGroup $HVGroupName)) { | |
| $HVFolder = New-RDMSession -Type "Group" -Name $HVFolderName | |
| $HVFolder.Group = $HVGroupName | |
| Set-RDMSession -Session $HVFolder -Refresh:$Refresh | |
| } | |
| # WAC Folder | |
| $WACFolderName = "Windows Admin Center" | |
| $WACGroupName = "$LabFolderName\$WACFolderName" | |
| if (-Not (Test-RDMGroup $WACGroupName)) { | |
| $WACFolder = New-RDMSession -Type "Group" -Name $WACFolderName | |
| $WACFolder.Group = $WACGroupName | |
| Set-RDMSession -Session $WACFolder -Refresh:$Refresh | |
| } | |
| # Domain Administrator | |
| $Params = @{ | |
| Name = $DomainAdminUPN | |
| Type = "Credential"; | |
| } | |
| $Session = New-RDMSession @Params | |
| $Session.Group = $ADGroupName | |
| $Session.MetaInformation.UPN = $DomainAdminUPN | |
| Set-RDMSession -Session $Session -Refresh:$true | |
| Set-RDMSessionUsername -ID $Session.ID "Administrator" | |
| Set-RDMSessionDomain -ID $Session.ID $DomainDnsName | |
| $SecurePassword = ConvertTo-SecureString $DomainPassword -AsPlainText -Force | |
| Set-RDMSessionPassword -ID $Session.ID -Password $SecurePassword | |
| $DomainAdminEntry = Get-RDMSession -GroupName $ADGroupName -Name $DomainAdminUPN | |
| $DomainAdminId = $DomainAdminEntry.ID | |
| # RD Gateway | |
| $RDGatewayFQDN = "rdg.$DnsZoneName" | |
| $Params = @{ | |
| Name = $RDGatewayFQDN | |
| Host = $RDGatewayFQDN | |
| Type = "Gateway"; | |
| } | |
| $Session = New-RDMSession @Params | |
| $Session.Group = $RDGGroupName | |
| $Session.CredentialConnectionID = $DomainAdminId | |
| $Session.RDP.GatewayCredentialsSource = "UserPassword" | |
| $Session.RDP.GatewayProfileUsageMethod = "Explicit" | |
| $Session.RDP.GatewaySelection = "SpecificGateway" | |
| $Session.RDP.GatewayUsageMethod = "ModeDirect" | |
| Set-RDMSession -Session $Session -Refresh:$true | |
| $RDGatewayEntry = Get-RDMSession -GroupName $RDGGroupName -Name $RDGatewayFQDN | Select-Object -First 1 | |
| # Windows Admin Center | |
| $WacFQDN = "wac.$DnsZoneName" | |
| $WacURL = "https://$WacFQDN`:6516" | |
| $Params = @{ | |
| Name = $WacFQDN | |
| Host = $WacURL | |
| Type = "WebBrowser"; | |
| } | |
| $Session = New-RDMSession @Params | |
| $Session.Group = $WACGroupName | |
| $Session.WebBrowserURL = $WacURL | |
| $Session.OpenEmbedded = $false | |
| $Session.Web.AutoFillLogin = $false | |
| $Session.Web.AutoSubmit = $false | |
| Set-RDMSession -Session $Session -Refresh:$Refresh | |
| # RDP (Regular) | |
| $VMAliases | ForEach-Object { | |
| $VMAlias = $_ | |
| $VMName = $LabPrefix, $VMAlias -Join "-" | |
| $MachineName = $VMName | |
| $MachineFQDN = "$MachineName.$DnsZoneName" | |
| $Params = @{ | |
| Name = "$MachineName"; | |
| Host = $MachineFQDN; | |
| Type = "RDPConfigured"; | |
| } | |
| $Session = New-RDMSession @Params | |
| $Session.Group = "$LabFolderName\$LANFolderName" | |
| $Session.CredentialConnectionID = $DomainAdminId | |
| Set-RDMSession -Session $Session -Refresh:$Refresh | |
| } | |
| # RDP (RD Gateway) | |
| $VMAliases | ForEach-Object { | |
| $VMAlias = $_ | |
| $VMName = $LabPrefix, $VMAlias -Join "-" | |
| $MachineName = $VMName | |
| $MachineFQDN = "$MachineName.$DnsZoneName" | |
| $Params = @{ | |
| Name = "$MachineName"; | |
| Host = $MachineFQDN; | |
| Type = "RDPConfigured"; | |
| } | |
| $Session = New-RDMSession @Params | |
| $Session.Group = $RDGGroupName | |
| $Session.CredentialConnectionID = $DomainAdminId | |
| $Session.VPN.Application = "Gateway" | |
| $Session.VPN.Enabled = $true | |
| $Session.VPN.Mode = "AlwaysConnect" | |
| $Session.VPN.ExistingGatewayID = $RDGatewayEntry.ID | |
| Set-RDMSession -Session $Session -Refresh:$Refresh | |
| } | |
| # RDP (Devolutions Gateway) | |
| $VMAliases | ForEach-Object { | |
| $VMAlias = $_ | |
| $VMName = $LabPrefix, $VMAlias -Join "-" | |
| $MachineName = $VMName | |
| $MachineFQDN = "$MachineName.$DnsZoneName" | |
| $Params = @{ | |
| Name = "$MachineName"; | |
| Host = $MachineFQDN; | |
| Type = "RDPConfigured"; | |
| } | |
| $Session = New-RDMSession @Params | |
| $Session.Group = $DGWGroupName | |
| $Session.CredentialConnectionID = $DomainAdminId | |
| Set-RDMSession -Session $Session -Refresh:$Refresh | |
| } | |
| # PowerShell (Hyper-V) | |
| $VMAliases | ForEach-Object { | |
| $VMAlias = $_ | |
| $VMName = $LabPrefix, $VMAlias -Join "-" | |
| $Params = @{ | |
| Name = "$VMName"; | |
| Host = $VMName; | |
| Type = "PowerShellRemoteConsole"; | |
| } | |
| $Session = New-RDMSession @Params | |
| $Session.Group = $HVGroupName | |
| $Session.CredentialConnectionID = $DomainAdminId | |
| $Session.PowerShell.Host = $Params.Host | |
| $Session.PowerShell.RemoteConsoleConnectionMode = "VMName" | |
| Set-RDMSession -Session $Session -Refresh:$Refresh | |
| } | |
| # PowerShell (WinRM) | |
| $VMAliases | ForEach-Object { | |
| $VMAlias = $_ | |
| $VMName = $LabPrefix, $VMAlias -Join "-" | |
| $MachineName = $VMName | |
| $MachineFQDN = "$MachineName.$DnsZoneName" | |
| $Params = @{ | |
| Name = "$MachineName"; | |
| Host = $MachineFQDN; | |
| Type = "PowerShellRemoteConsole"; | |
| } | |
| $Session = New-RDMSession @Params | |
| $Session.Group = $LANGroupName | |
| $Session.CredentialConnectionID = $DomainAdminId | |
| $Session.PowerShell.Host = $Params.Host | |
| $Session.PowerShell.RemoteConsoleConnectionMode = "ComputerName" | |
| Set-RDMSession -Session $Session -Refresh:$Refresh | |
| } | |
| } | |
| New-RdmTestDataSource @args |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment