Reset Terminal license on Windows using PowerShell

Reset Terminal license on Windows using PowerShell

NOTA IMPORTANTE: Este método aun no ha sido probado por ningún miembro del equipo operativo de NephosIT por lo cual se recomienda usarla solo que la otra solución no funcione o en dado caso de que no se encuentren mas alternativas a la primer solución.

Reset Terminal Server (RDS) Grace Period using PowerShell

The PowerShell script can be used to query and reset terminal server grace period to default 120 days if it is nearing to the end.

We often need to deploy Terminal Server (Remote Desktop Session Host in 2012) for testing purposes in development environments allowing more than 2 concurrent Remote Desktop Sessions on it. When it is installed, by default if no RDS or TS Licensing server is specified via either GPO or Registry, it is in default Grace period which is 120 days and it works fine untill then.

Once Grace period expires, the server does not allow even a single Remote Desktop session via RDP and all we are left with is to logon to the Console of machine using Physical/Virtual console depending on Physical or Virtual machines or try to get in using mstsc /admin or mstsc /console, then remove the role completely and restart the terminal server (RDS Server) and post that it starts accepting default two RDP sessions.

We sometimes find ourselves in situation when any such server deployed for testing pruposes is nearing to the end of grace period and we don’t have a TS Licensing server in place and we need the default grace period to be reset/extended to next 120 days.

I have created a Script which can be used to query the remaining days of grace period and extend/reset it to next 120 days in case needed.

Note: You will have to restart following services for the reset to come into effect. 

   * Remote Desktop Configuration Properties
   * Remote Desktop Services

As soon as these services are restarted all the active sessions will be disconnected (Not logged off), Wait for two minutes and reconnect again.

PowerShell

## This Script is intended to be used for Querying remaining time and resetting Terminal Server (RDS) Grace Licensing Period to Default 120 Days. 

## Developed by Prakash Kumar (prakash82x@gmail.com) May 28th 2016 

## www.adminthing.blogspot.com 

## Disclaimer: Please test this script in your test environment before executing on any production server. 

## Author will not be responsible for any misuse/damage caused by using it. 

 

Clear-Host 

$ErrorActionPreference"SilentlyContinue" 

 

## Display current Status of remaining days from Grace period. 

$GracePeriod = (Invoke-WmiMethod -PATH (gwmi -namespace root\cimv2\terminalservices -class win32_terminalservicesetting).__PATH -name GetGracePeriodDays).daysleft 

Write-Host -fore Green ====================================================== 

Write-Host -fore Green 'Terminal Server (RDS) grace period Days remaining are'$GracePeriod 

Write-Host -fore Green ======================================================   

Write-Host 

$ResponseRead-Host "Do you want to reset Terminal Server (RDS) Grace period to Default 120 Days ? (Y/N)" 

 

if ($Response -eq "Y") { 

## Reset Terminal Services Grace period to 120 Days 

 

$definition = @" 

using System; 

using System.Runtime.InteropServices;  

namespace Win32Api 


   public class NtDll 

   { 

       [DllImport("ntdll.dll", EntryPoint="RtlAdjustPrivilege")] 

       public static extern int RtlAdjustPrivilege(ulong Privilege, bool Enable, bool CurrentThread, ref bool Enabled); 

   } 


"@  

 

Add-Type -TypeDefinition $definition -PassThru 

 

$bEnabled$false 

 

## Enable SeTakeOwnershipPrivilege 

$res = [Win32Api.NtDll]::RtlAdjustPrivilege(9, $true$false, [ref]$bEnabled

 

## Take Ownership on the Key 

$key = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Control\Terminal Server\RCM\GracePeriod", [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,[System.Security.AccessControl.RegistryRights]::takeownership) 

$acl$key.GetAccessControl() 

$acl.SetOwner([System.Security.Principal.NTAccount]"Administrators"

$key.SetAccessControl($acl

 

## Assign Full Controll permissions to Administrators on the key. 

$ruleNew-Object System.Security.AccessControl.RegistryAccessRule ("Administrators","FullControl","Allow"

$acl.SetAccessRule($rule

$key.SetAccessControl($acl

 

## Finally Delete the key which resets the Grace Period counter to 120 Days. 

Remove-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\RCM\GracePeriod' 

 

write-host 

Write-host -ForegroundColor Red 'Resetting, Please Wait....' 

Start-Sleep -Seconds 10  

 

 } 

 

Else  

   { 

Write-Host 

Write-Host -ForegroundColor Yellow '**You Chose not to reset Grace period of Terminal Server (RDS) Licensing' 

 } 

 

## Display Remaining Days again as final status 

tlsbln.exe 

$GracePost = (Invoke-WmiMethod -PATH (gwmi -namespace root\cimv2\terminalservices -class win32_terminalservicesetting).__PATH -name GetGracePeriodDays).daysleft 

Write-Host 

Write-Host -fore Yellow ===================================================== 

Write-Host -fore Yellow 'Terminal Server (RDS) grace period Days remaining are'$GracePost 

Write-Host -fore Yellow ===================================================== 

 

## Cleanup of Variables 

Remove-Variable * -ErrorAction SilentlyContinue




    • Related Articles

    • Reset Terminal license on Windows 2008

      While Windows installed with Terminal Server role it does work without License for 120 Days on trail license, where within 120 days if the License server is not Connected the server will stop accepting connection with below error and event ID ...
    • Procedimiento para Terminal Services

      Procedimiento para Terminar Services Paso 1 Lo primero que tenemos que hacer es agregar la opción de Terminal Services para eso abriremos el Server Manager de ahí daremos clic en la opción de Manage y Add Roles and Features Paso 2 Después de darle ...
    • Instalación de los roles de Remote Desktop Services en Windows 2008 Server

      En primer lugar, accederemos a la herramienta, Server Manager, del servidor que tenemos destinado a albergar los Servicios de Escritorio Remoto, y procederemos a instalar los roles necesarios. Buscaremos en el menú lateral izquierdo de la ventana y ...
    • Code 80243004 Error Windows Update Fix

      Code 80243004 – Windows Update encountered an unknown error. 86 Replies When trying to install Windows Updates, you receive the following error: Code 80243004 – Windows Update encountered an unknown error. This is a documented issue by Microsoft and ...
    • Soluciones Error de Activación en Windows 7:8 0x80072F8F

      FIX: 0x80072F8F Windows Activation Error. The Windows activation error code 0x80072F8F may occurred while trying to activate Windows 7 or Windows Vista. As Microsoft says the error 0x80072F8F is faced because a security error is occurred when you try ...