Activate a Remote Desktop License Server without GUI

licensingremote-desktop-serviceswindows-server-2012-r2

Trying to automate Windows Server 2012 R2 installation of services and configuration.

I was able to install the RDS License Server Windows Feature via Powershell Add-WindowsFeature RDS-Licensing, Add-WindowsFeature RDS-Licensing-UI however the Server then needs to be Activated with Microsoft but the only way I've been able to Activate the Server is using the Active Server Wizard:
enter image description here

Is anyone aware of a way to Activate the Server by Powershell or registry settings and also then Install the Licenses I have without using the Wizard?

Best Answer

This code should handle the activate the license server by PowerShell part of your question and may give you ideas for the rest.

# ----------------------------------------------------------------------------------------------------------------
function log-info($data)
{
    #$data = "$([DateTime]::Now):$($data)"
    write-host ($data | out-string)

}

function main()
{

    $licenseServer='localhost'
    $companyInformation = @{}
    $companyInformation.FirstName="Suzy"
    $companyInformation.LastName="Sample"
    $companyInformation.Company="Independent Consolidators"
    $companyInformation.CountryRegion="United States"

    activate-licenseServer $licenseServer $companyInformation
}

# ----------------------------------------------------------------------------------------------------------------
function activate-licenseServer($licServer, $companyInfo)
{

    $licServerResult = @{}
    $licServerResult.LicenseServerActivated = $Null

    $wmiClass = ([wmiclass]"\\$($licServer)\root\cimv2:Win32_TSLicenseServer")

    $wmiTSLicenseObject = Get-WMIObject Win32_TSLicenseServer -computername $licServer
    $wmiTSLicenseObject.FirstName=$companyInfo.FirstName
    $wmiTSLicenseObject.LastName=$companyInfo.LastName
    $wmiTSLicenseObject.Company=$companyInfo.Company
    $wmiTSLicenseObject.CountryRegion=$companyInfo.CountryRegion
    $wmiTSLicenseObject.Put()

    $wmiClass.ActivateServerAutomatic()

    $licServerResult.LicenseServerActivated = $wmiClass.GetActivationStatus().ActivationStatus
    log-info "activation status: $($licServerResult.LicenseServerActivated) (0 = activated, 1 = not activated)"
}


# ----------------------------------------------------------------------------------------------------------------
function deactivate-licenseServer($licServer)
{

     $wmiClass = ([wmiclass]"\\$($licServer)\root\cimv2:Win32_TSLicenseServer")
     $wmiClass.DeactivateServerAutomatic()

}


# ----------------------------------------------------------------------------------------------------------------
main
Related Topic