As mentioned in a previous blog post, it is possible to use PowerShell and Google Translate free public endpoint to perform translations on text.
The reason I started the previous blog post and this whole investigation is because of the slmgr.vbs utility which comes with Windows. The slmgr utility is used to find out volume activation information on a certain machine, which might be useful if you are working in an enterprise environment and want to find out what is happening with licenses in it.
As a simple command, you can open up cmd and type the following command:
slmgr.vbs /dlv
This will open a small popup which contains all the necessary information in regards of the activation of your Windows installation:
To save this information with PowerShell is quite easy, all you have to do is save the output in a text file:
Set-Location -Path “$env:windir\System32”
$command = “cscript.exe slmgr.vbs /dlv > C:\temp\activation.txt”
Invoke-Expression $command
From here is quite easy, you can read the text file to see if the “License Status” states “Licensed” and make a repository with all your machines, and so on.
However, a problem appears when a machine is not in English. If we were to run the same command on a machine which is installed with an OS in German, this will be following output:
And here is where the problems begin. If you make your script to detect “License Status” in the file, it will fail because on German, the specified field starts with “Lizenzstatus”. And of course, the actual status and other information is in German.
You might think “well let’s modify slmgr.vbs” to output only English. My answer will be “you can try, but are you going to deploy it to all your machines?”
I made it much easier by using Google Translate endpoint that I mentioned in my previous post. The script for this is:
Set-Location -Path “$env:windir\System32”
$command = “cscript.exe slmgr.vbs /dlv > C:\temp\activation.txt”
Invoke-Expression $command
$Text3 = Get-Content -Path “C:\temp\Activation.txt” -raw
$TargetLanguage = “en”
$Uri = “https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=$($TargetLanguage)&dt=t&q=$Text3”
$Response = Invoke-RestMethod -Uri $Uri -Method Get
$Response[0].SyncRoot | foreach { $_[0] } > “c:\temp\activationtranslated.txt”
$Translation = Get-Content -Path “C:\temp\activationtranslated.txt”
$licensestatus = $Translation | Select-String -Pattern “License Status:” | Out-String
$licensestatus = $licensestatus.Trim().Replace(“`n”,””).Replace(“`r”,””).Replace(“License Status:”,””)
write-host $licensestatus
So what we are doing is the following:
1. Run the slmgr command to output the license status in “activation.txt”
2. Get the raw text from “Activation.txt” and send it to Google for translation. We must invoke a RestMethod and use GET
3. Filter the result and send it to another text file called “ActivationTranslated.txt”
4. Parse the “ActivationTranslated.txt” for the desired field. In this case “License Status:”
The end result should look like this:
As you can see, the activation information was correctly translated from German to English. I cannot guarantee 100% success rate, but I figured there are simple words that Google can handle in terms of translations. Either way, in most cases you are really interested in the “License Status” of a particular machine, and not the other information present.
I know extra new blank lines are added in the translated file, but I am not bothered, as we are using a pattern to select the desired information.