Function/Tool/Set-RDPStatus.ps1
function Set-RDPStatus { <# .DESCRIPTION The function Set-RDPStatus can enable or disable RDP remotely .PARAMETER ComputerName Specifies the ComputerName .EXAMPLE PS C:\> Set-RDPStatus -Action Enable -ComputerName "SRV-01" .EXAMPLE PS C:\> Set-RDPStatus -Action Enable -ComputerName "SRV-01","SRV-02","SRV-03" #> Param ( [Parameter(Mandatory=$true)] [ValidateSet('Enable','Disable')] [String]$Action, [Parameter(Mandatory=$false)] [String[]]$ComputerName = $env:COMPUTERNAME ) Process{ Foreach ($Computer in $ComputerName) { Try { IF (Test-Connection -ComputerName $Computer -Count 1 -Quiet) { if($Action -eq 'Disable'){ $regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $Computer) $regKey = $regKey.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Terminal Server", $True) $regkey.SetValue("fDenyTSConnections", 1) $regKey.flush() $regKey.Close() } else { $regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $Computer) $regKey = $regKey.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Terminal Server", $True) $regkey.SetValue("fDenyTSConnections", 0) $regKey.flush() $regKey.Close() } } else { write-error "Unable to connect to $Computer : $($_.Exception.Message)" } } Catch { write-error "Unable to set value : $($_.Exception.Message)" } #Catch } #Foreach } #Process } #Function |