30 April 2018

Activate Windows Server offline

When installing Windows Server 2016 without internet access and in a environment without Key Management Service (KMS).

Open PowerShell or Windows Shell (cmd.exe) as administrator.

Enter license key:
c:\> slmgr.vbs /ipk xxxxx-xxxxx-xxxxx-xxxxx-xxxxx
where the x's are replaced with your license key.

Start Windows Activation Client:
c:\> slui.exe 4

Activate Windows:
Select you country.
Call the phone number.
Listen to the robot and select numbers for Windows Server activation.
Enter the Confirmation ID from slui in the phone as guided by the robot.
Wait a few seconds for acceptance.
Enter the activation code on the computer. Or in a editor as the activation code can be reused with the same License Key on the same product, e.g. Windows Server 2016 Standard Edition.

Verify that Windows is activated. This can be done by opening the System window. If you have the window open from before the activation a refresh will not show the true activation status. Close the System window and open it again.

The process is very much the same as described in this post by Kanijude Kajendra: "How to Activate Windows 2012 R2 Server offline".

18 April 2018

Remove TFS Code Search

When you install Microsoft Team Foundation Server (TFS) it will by default put TFS Code Search on the same server as TFS Application Tier.

PowerShell 5 does not have the CmdLet Remove-Service. Then any service must be removed using WMI.
It can be done with a PowerShell script like this:

'Stop TFS Code Search service (ElasticSearch)...'
$CodeSearchSvc = Get-WmiObject -Class Win32_Service -Filter "Name='$((Get-Service "elastic*").Name)'"
$Return = $CodeSearchSvc.StopService()
if ($Return.ReturnValue -eq 0)
{ '  Service stopped.' }
else
{ throw "Could not stop TFS Code Search service. Return value = '$($Return.ReturnValue)'. Check documentation on StopService method of the WMI Win32_Service class." }

'Delete TFS Code Search service...'
$Return = $CodeSearchSvc.Delete()
if ($Return.ReturnValue -eq 16)
{ '  The service is being removed from the system.' }
else
{ throw "Could not delete TFS Code Search service. Return value = '$($Return.ReturnValue)'. Check documentation on Delete method of the WMI Win32_Service class." }

'Delete files for TFS Code Search...'
Remove-Item -Path 'C:\TfsData\Search' -Recurse -Force


The folder holding the TFS Code Search files are in the default position in the script above. If you have placed the TFS Code Search files in another position then just alter the script.

Then the Java installation must be removed. Also remember to clean up in Windows environment variables like JAVA_HOME. This task is more individual and this is why it is not in the script above.