Examples/ExampleConfiguration-RemoteDesktopAdminWithUnEncryptedPassword.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# The configuration data section specifies to allow using a plain text stored password
$ConfigData = @{
    AllNodes = @(
        @{
            NodeName="DSCnode1";
            PSDscAllowPlainTextPassword = $true
            
         }

)}

Configuration AllowRemoteDesktopAdminConnections
{
    $password = ConvertTo-SecureString "YourPasswordHere" -AsPlainText -Force
    $Credential = New-Object System.Management.Automation.PSCredential ("Contoso\RDP_User", $password)
    
    Import-DscResource -Module xRemoteDesktopAdmin, xNetworking

    node ('DSCnode1')
    {        
        xRemoteDesktopAdmin RemoteDesktopSettings
        {
           Ensure = 'Present'
           UserAuthentication = 'Secure'
        }

        xFirewall AllowRDP
        {
            Name = 'DSC - Remote Desktop Admin Connections'
            DisplayGroup = "Remote Desktop"
            Ensure = 'Present'
            State = 'Enabled'
            Access = 'Allow'
            Profile = 'Domain'
        }

        Group RDPGroup
        {
           Ensure = 'Present'
           GroupName = "Remote Desktop Users"
           Members = 'Contoso\RDP_User'
           Credential = $Credential
           
        }
         
    }
}

# Set your working directory for the output of the MOF file
$workingdir = 'C:\RDP\MOF'

# Create MOF with configuration data
AllowRemoteDesktopAdminConnections -ConfigurationData $ConfigData -OutputPath $workingdir

# Apply the configuration
Start-DscConfiguration -ComputerName 'DSCnode1' -wait -force -verbose -path $workingdir