Last active
July 17, 2024 06:51
-
-
Save ufukcam/70ebc525ff1a1879fab571042b00b8d1 to your computer and use it in GitHub Desktop.
Terminal Server 120 Gün Resetleme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bu Betik, kalan süreyi sorgulamak ve Terminal Server (RDS) Grace Lisanslama Süresini Varsayılan 120 Güne sıfırlamak için kullanılmak üzere tasarlanmıştır. | |
## theblow tarafından geliştirildi. | |
## Yasal Uyarı: Lütfen bu betiği herhangi bir üretim sunucusunda çalıştırmadan önce test ortamınızda test edin. | |
## Yazar, kullanımdan kaynaklanan herhangi bir yanlış kullanımdan / hasardan sorumlu olmayacaktır. | |
Param( | |
[Parameter(Mandatory=$false)] [Switch]$Force | |
) | |
Clear-Host | |
$ErrorActionPreference = "SilentlyContinue" | |
## PowerShell Konsolunun Yönetici Olarak Başlatılıp Başlatılmadığını Kontrol Edin | |
if (([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { | |
## Ödemesiz dönemden kalan günlerin geçerli Durumunu görüntüleyin. | |
$GracePeriod = (Invoke-CimMethod -InputObject (Get-CimInstance -Namespace root/CIMV2/TerminalServices -ClassName Win32_TerminalServiceSetting) -MethodName GetGracePeriodDays).DaysLeft | |
Write-Host -fore Green ====================================================== | |
Write-Host -fore Green 'Terminal Server (RDS) lisans sureniz' : $GracePeriod | |
Write-Host -fore Green ====================================================== | |
Write-Host | |
## -Force Parametresinin kullanılıp kullanılmadığını kontrol edin, Eğer kullanılmışsa, komut dosyası yürütülürken Y/N istemeyecek ve sadece Grace Period'u sıfırlayacaktır. | |
If (-not $Force) | |
{ | |
$Response = Read-Host "Terminal Sunucusu (RDS) Odemesiz doneminiz varsaliyan 120 gune sifirlamak istiyor musunuz? (Y/N)" | |
} | |
if ($Response -eq "Y" -or $Force) { | |
## Terminal Hizmetleri Ödemesiz Dönemini 120 Güne Sıfırla | |
$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 | |
## Etkinleştir 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) | |
## Anahtar üzerinde Yöneticilere Tam Kontrol izinleri atama. | |
$rule = New-Object System.Security.AccessControl.RegistryAccessRule ("Administrators","FullControl","Allow") | |
$acl.SetAccessRule($rule) | |
$key.SetAccessControl($acl) | |
## Sonunda 120 günümüz daha var. | |
Remove-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\RCM\GracePeriod' | |
write-host | |
Write-host -ForegroundColor Red 'Sifirlaniyor, Lütfen Bekleyin....' | |
Start-Sleep -Seconds 10 | |
} | |
Else | |
{ | |
Write-Host | |
Write-Host -ForegroundColor Yellow '**Lisanslama süresini sifirlamayi sectiniz...' | |
} | |
## Ekranda süreyi göster. | |
tlsbln.exe | |
$GracePost = (Invoke-CimMethod -InputObject (Get-CimInstance -Namespace root/CIMV2/TerminalServices -ClassName Win32_TerminalServiceSetting) -MethodName GetGracePeriodDays).DaysLeft | |
Write-Host | |
Write-Host -fore Yellow ===================================================== | |
Write-Host -fore Yellow 'Terminal Sunucusu (RDS) odemesiz donem icin kalan gun sayısı' : $GracePost | |
Write-Host -fore Yellow ===================================================== | |
if ($Response -eq "Y" -or $Force) | |
{ | |
Write-Host -Fore Cyan `n "ONEMLI: Bu sifirlamayi gecerli kilmak icin lutfen asagidaki hizmetleri manuel olarak yeniden baslattiginizdan emin olun:`n* Uzak Masaustu Yapilandirma Ozellikleri `n* Uzak Masaustu Hizmetleri" | |
} | |
} | |
Else | |
{ | |
Write-Host -fore RED ===================================================== | |
Write-host -ForegroundColor RED *`0`0`0`0 Please Launch PowerShell as Administrator `0`0`0`0* | |
Write-Host -fore RED ===================================================== | |
} | |
## Cleanup of Variables | |
Remove-Variable * -ErrorAction SilentlyContinue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment