У меня есть этот код для настройки диспетчера подключений RDP, но он нужен пользователю MSTSC для нескольких пользователей, которые различаются на разных компьютерах. Я пытался использовать% userprofile%\desktop\Desktop.rdp, но он не работает правильно. Это код, который я использовал

########################################################################### 
# 
# NAME: New-MSTSCFile.ps1 
# 
# AUTHOR: Markus Lassfolk 
# EMAIL: markus.lassfolk@truesec.se 
#
# Original AUTHOR: Jan Egil Ring 
# EMAIL: jer@powershell.no 
# 
# COMMENT: Script to create an txt-file for use with Microsoft Remote Desktop Connection Manager 
#          For more details, see the following blog-post: http://blog.powershell.no/2010/06/02/dynamic-remote-desktop-connection-manager-connection-list 
# 
# You have a royalty-free right to use, modify, reproduce, and 
# distribute this script file in any way you find useful, provided that 
# you agree that the creator, owner above has no warranty, obligations, 
# or liability for such use. 
# 
# VERSION HISTORY: 
# 2.1 19/08/2015 - Creating a Default Profile based on your UserName and Domain 
#                - Assume RDGW Address is  rdgw.your.domain.fqdn  if incorrect, set it manually. 
#
# 2.0 15/07/2015 - Updated for MSTSC 2.7 
#                - Only including ComputerObjects (no ClusterNames etc) 
#                - Only including Enabled Computer objects 
#                - Adds Computer Description as Comment
#                - Not using a Group. Felt no need for that as there is just one environment in each RDG File 
#                - Support for Providing a RDGateway Address 
#                - Changed file name to reflect FQDN of Domain (we have several customers with the same Netbios name) 
#                - Sort servers alphabetically in the list. 
#                
# 1.0 02.06.2010 - Initial release 
# 
########################################################################### 

#Importing Microsoft`s PowerShell-module for administering Active Directory 
Import-Module ActiveDirectory 

#Initial variables 
$EnableRDGW = $true                  # set to: $false if RDGW should not be used 
$RDGW = "rdgw.cmrinc.com"    # Enter External RDGW Address if this is incorrect. 


#$domain = $env:userdomain 
$OutputFile = "$home\desktop\CMR_Desktop.rdg" 


#Create a template txt 
$template = @' 
screen mode id:i:2
use multimon:i:0
desktopwidth:i:1920
desktopheight:i:1080
session bpp:i:24
winposstr:s:0,3,0,0,800,600
compression:i:1
keyboardhook:i:2
audiocapturemode:i:1
videoplaybackmode:i:1
connection type:i:2
networkautodetect:i:0
bandwidthautodetect:i:1
displayconnectionbar:i:1
enableworkspacereconnect:i:0
disable wallpaper:i:1
allow font smoothing:i:0
allow desktop composition:i:0
disable full window drag:i:1
disable menu anims:i:1
disable themes:i:0
disable cursor setting:i:0
bitmapcachepersistenable:i:1
full address:s:rdshost.cmrinc.com
audiomode:i:0
redirectprinters:i:0
redirectcomports:i:0
redirectsmartcards:i:0
redirectclipboard:i:1
redirectposdevices:i:0
autoreconnection enabled:i:1
authentication level:i:0
prompt for credentials:i:0
negotiate security layer:i:1
remoteapplicationmode:i:0
alternate shell:s:
shell working directory:s:
gatewayhostname:s:rdsgw.cmrinc.com
gatewayusagemethod:i:1
gatewaycredentialssource:i:4
gatewayprofileusagemethod:i:1
promptcredentialonce:i:1
gatewaybrokeringtype:i:0
use redirection server name:i:0
rdgiskdcproxy:i:0
kdcproxyname:s:
drivestoredirect:s:
set audioqualitymode:1:2
span monitors:i:0
use multimon:i:0
session bpp:i:24
'@ 

#Output template to txt-file 
$template | Out-File $home\CMR_Desktop.rdp l

#Load template into txt object 
$txt = New-Object text 
$txt.Load("$home\CMR_Desktop.rdp") 

#Set file properties 
$file = (@($txt.MSTSC.file.properties)[0]).Clone() 
$file.name = "CMR_Desktop.rdp" 
$txt.MSTSC.file.properties | Where-Object { $_.Name -eq "" } | ForEach-Object  { [void]$txt.MSTSC.file.ReplaceChild($file,$_) } 

# Set RDGW Server Address 

if ($EnableRDGW -eq $true) {
    $txt.MSTSC.file.gatewaySettings.hostName = $RDGW
    $txt.MSTSC.file.gatewaySettings.enabled = "True"
    }

# Create a Profile with your current username and domain 
$txt.MSTSC.file.credentialsProfiles.credentialsProfile.profileName.'#text' = "CMR_Desktop.r"
$txt.MSTSC.file.credentialsProfiles.credentialsProfile.userName = "InfinityText"
$txt.MSTSC.file.credentialsProfiles.credentialsProfile.domain = "CMRINC.com"
$txt.MSTSC.file.logonCredentials.profileName.'#text' = "InfinityTest"
$txt.MSTSC.file.gatewaySettings.profileName.'#text' = "InfinityTest"




#Use template to add servers from Active Directory to txt  
$server = (@($txt.MSTSC.file.server)[0]).Clone() 
#get-adcomputer -LDAPFilter "(&(objectCategory=computer)(operatingSystem=Windows Server*)(!serviceprincipalname=*MSClusterVirtualServer*)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))" -Property name,dnshostname,description | sort-object Name | select name,dnshostname,description | 
ForEach-Object { 
$server = $server.clone()     
$server.DisplayName = $_.Name     
$server.Name = $_.DNSHostName 
if ($_.Description -ne $Null) { 
    $server.comment = $_.Description 
    } 
else { 
  $server.comment = "" 
  } 
#
$txt.MSTSC.file.AppendChild($server) > $null} 
#Remove template server 
#`$txt.MSTSC.file.server | Where-Object { $_.Name -eq "" } | ForEach-Object  { [void]$txt.MSTSC.file.RemoveChild($_) } 


#Save txt to file 
$txt.Save($OutputFile) 

#Remove template txt-file 
Remove-Item $home\MSTSC-template.txt -Force

Write-Output "$OutputFile Created" 

В нем есть все настройки для моего сеанса RDP.

1 ответ1

0

Первый скрипт Powershell должен создать файл RDP

#Create RDP

New-Item -Path ~\desktop\ -Name 'CMR Desktop.rdp' -ItemType file


#Config RDP Settings
#invoke-expression -Command .\Config_RDP_Settings.ps1
& .\Config_RDP_Settings.ps1

#Pauses the process
Pause

Затем настройте файл с параметрами, которые я хотел, так как созданный файл был пустым файлом

#Add setting to CMR Desktop.rdp file
ls "~\desktop\CMR Desktop.rdp" | %{ "screen mode id:i:2" | Out-File $_.FullName - 
append -encoding ASCII}
ls "~\desktop\CMR Desktop.rdp" | %{ "session bpp:i:24" | Out-File $_.FullName -append 
-encoding ASCII}
ls "~\desktop\CMR Desktop.rdp" | %{ "winposstr:s:0,3,0,0,800,600" | Out-File 
$_.FullName -append -encoding ASCII}
ls "~\desktop\CMR Desktop.rdp" | %{ "compression:i:1" | Out-File $_.FullName -append 
-encoding ASCII}
ls "~\desktop\CMR Desktop.rdp" | %{ "keyboardhook:i:2" | Out-File $_.FullName -append 
-encoding ASCII}

Я должен был сделать это для каждой из настроек, которые я хотел в файле для сеанса RDP

Всё ещё ищете ответ? Посмотрите другие вопросы с метками .