Disable Clipboard Redirection Multiple Servers PowerShell

Clipboard Redirection Applies to Server 2008 R2, 2012, 2012 R2, 2016, and 2019.

RDP Properties Clipboard redirection
RDP Properties

Clipboard redirection is the sharing of clipboard contents between a remote computer and client computer during a Remote Desktop session. You can use this setting to prevent users from redirecting Clipboard data to and from the remote computer and the local computer. By default, Remote Desktop Services allows Clipboard redirection. As a Windows Admin, you may get a request from your application team or your leadership to disable it on the server and you can do that by just enabling the “Do not allow Clipboard redirection” settings.

But wait.. what if you need to do it on multiple servers lets say 100 servers or 200 servers or more, it would be a very tedious task for you. Hence today we are back with a very useful PowerShell script to accomplish this task on multiple servers in less than a minute. Let’s Get Started.

PowerShell is the new way of Administering Windows Server OS nowadays. Here is the short PowerShell recipe to enable the Do not allow Clipboard redirection on multiple servers in no time.

Code:

$servers = Get-Content .\server.txt

foreach($server in $servers)
{
     REG ADD "\\$server\HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\Winstations\RDP-Tcp" /v fDisableClip /t REG_DWORD /d 1 /f
}

Explanation:

$servers = Get-Content .\server.txt

The PowerShell cmdlet Get-Content read the server names from server.txt file and store these in $servers variable as an array of strings.

foreach($server in $servers)

foreach is the for loop like in any programming language while $server is the variable that stores the server names from $servers one by one to accomplish the commands within the foreach loop.

REG ADD "\\$server\HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\Winstations\RDP-Tcp" /v fDisableClip /t REG_DWORD /d 1 /f

Here comes the main section which does the main task. Here we have made use of popular Windows command-line utility “REG ADD” followed by the full registry path including the server name, then /v devotes the Value which is fDisableClip, /t is the type of Value which is REG_DWORD and /d is Data to be assigned to the given value which is being set to 1, /f is used to apply these setting forcefully.

Check out our other sections:

See you in the next topic. Good Bye!

Leave a Comment