Wie erstelle ich eine RDP-Sitzung oder -Datei für mehrere Benutzer mit% userprofile%?


0

Ich habe diesen Code, um einen RDP-Verbindungsmanager einzurichten, aber er muss verwendet werden, um MSTSC für mehrere Benutzer zu verwenden, die von Computer zu Computer unterschiedlich sind. Ich habe versucht,% userprofile% \ desktop \ Desktop.rdp zu verwenden, aber es funktioniert nicht richtig. Dies ist der Code, den ich verwendet habe

########################################################################### 
# 
# 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" 

Es hat alle Einstellungen für meine RDP-Sitzung.


Egal, ich habe es herausgefunden.
James

Antworten:


0

Das erste Powershell-Skript ist das Erstellen der RDP-Datei

#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

Konfigurieren Sie dann die Datei mit den gewünschten Parametern, da es sich bei der erstellten Datei um eine leere Datei handelt

#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}

Ich musste dies für jede der Einstellungen tun, die ich in der Datei für die RDP-Sitzung haben wollte

Durch die Nutzung unserer Website bestätigen Sie, dass Sie unsere Cookie-Richtlinie und Datenschutzrichtlinie gelesen und verstanden haben.
Licensed under cc by-sa 3.0 with attribution required.