-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenRDP.ps1
More file actions
48 lines (39 loc) · 1.48 KB
/
GenRDP.ps1
File metadata and controls
48 lines (39 loc) · 1.48 KB
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
<#
Written by MJ Lema - Jan 2024
Version 3.0
Generate RDP Files based on OU
#>
# Prompt user for the Active Directory OU
$ou = Read-Host "Enter the Active Directory OU in FQDN format"
# Define the folder path to save RDP files
$folderPath = "C:\RDPFiles\$ou"
# Create the folder if it doesn't exist
if (-not (Test-Path -Path $folderPath)) {
New-Item -ItemType Directory -Path $folderPath -Force
}
# Get the computers from the specified OU and its child OUs
$computers = Get-ADComputer -Filter * -SearchBase $ou -SearchScope Subtree
# Loop through each computer and create RDP config file
foreach ($computer in $computers) {
$computerName = $computer.Name
$ipAddress = [System.Net.Dns]::GetHostAddresses($computerName) | Where-Object { $_.AddressFamily -eq 'InterNetwork' } | Select-Object -ExpandProperty IPAddressToString
# Generate RDP configuration file, add values here to adjust settings
$rdpContent = @"
full address:s:$computerName.arusd.org
prompt for credentials:i:1
gatewayhostname:s:
gatewayusagemethod:i:4
gatewaycredentialssource:i:4
negotiate security layer:i:1
disable connection sharing:i:0
enablecredsspsupport:i:1
authentication level:i:2
promptcredentialonce:i:0
drivestoredirect:s:
username:s:
"@
# Save RDP configuration to a file
$rdpFilePath = Join-Path -Path $folderPath -ChildPath "$computerName.rdp"
Set-Content -Path $rdpFilePath -Value $rdpContent
Write-Host "RDP configuration file created for $computerName at $rdpFilePath"
}