Getting String from KMS Analysis

I created a fixlet and analysis to get the KMS DNS server. The relevance is not giving me results for every server, which is why I am doing this.

My fixlet creates a kms.txt file with the following. Note, I did cut out some of the customer information, but that is irrelevant for this.

Microsoft ® Windows Script Host Version 5.8
Copyright © Microsoft Corporation. All rights reserved.

Name: Windows Server®, ServerStandard edition
Description: Windows Operating System - Windows Server®, VOLUME_KMSCLIENT channel
Partial Product Key: R7VHC
License Status: Licensed
Volume activation expiration: 256440 minute(s) (178 day(s))

Key Management Service client information
Client Machine ID (CMID):
KMS machine name from DNS:
KMS machine extended PID:
Activation interval: 120 minutes
Renewal interval: 10080 minutes
KMS host caching is enabled

I tried editing an analysis I used in the past and it doesn’t get the results, false

(if (it as string as lowercase starts with “kms machine name from dns:”) then (it) else (substrings before “)” of (substrings after “(” of it))) of lines whose ((it as string as lowercase starts with “kms machine name from dns:”) OR (it as string as lowercase contains “kms machine name from dns:”)) of file “C:@oneneck\kms.txt”

So I tried to simplify it and still false
(it as string as lowercase contains “kms machine name from dns:”) of file “C:@oneneck\kms.txt”

This will get me t: and a random number
(it as string as lowercase contains “kms”) of file “C:@oneneck\kms.txt”

But this goes back to false
(it as string as lowercase contains “kms*”) of file “C:@oneneck\kms.txt”

What is the best way to get the string following "KMS machine name from DNS: "

Try something like this analysis. Windows KMS Licensing Information.bes (3.3 KB)

Agree, use the WMI-based analysis instead.

But to illustrate, the root problem of your queries is that you are iterating over <file> when I think you intend lines of <file>

(it as string as lowercase contains “kms*”) of file “C:@oneneck\kms.txt

…is checking ‘file’, the default property of ‘file’ will give the file name, version, and a couple of metadata properties, so what you need is ‘lines of’ the file.

That analysis has everything I don’t want. I just want to know the server that it’s getting KMS from.

I tried this one earlier but it’s not working
string value of select “DiscoveredKeyManagementServiceMachineName from SoftwareLicensingProduct WHERE (PartialProductKey is not null) and (Name LIKE ‘Windows®%25’ or Name LIKE ‘Windows Server®%25’) and not (Name LIKE ‘%25ESU%25’)” of wmi

The fixlet exports what I want. I just need the analysis to pull the string for me.

This is failing. I don’t know why. You can see it doesn’t like the wildcard though. So I need it to work with a wildcard and I want the string not a true/false.
image

Just went and read again. So I changed to lines of file and get this. How to I go from a boolean return to the string?

image

I can’t copy/paste from screenshots, but the start of it will be

lines whose (it as string as lowercase contains "something") of file "something.txt"

And then probably

following texts of firsts ":" of lines whose (it as string as lowercase contains "something") of files "something.txt"

Perfect. Thank you sir!
image

One more question. How do I get rid of the “KMS machine name from DNS” in the text and just return the results after? Guessing something with substring after?

Got it
substring after ": " of lines whose (it as string as lowercase contains “kms machine name from dns:”) of file “C:@oneneck\kms.txt”

1 Like

OK, hopefully the last one I got. Microsoft changed the output of slmgr by OS. I need to make this if the first line exist then return that else do the next one.

So if this is true, return value
substring after ": " of lines whose (it as string as lowercase contains “kms machine name from dns:”) of file “C:@oneneck\kms.txt”

Else, return this one.
substring after ": " of lines whose (it as string as lowercase contains “registered kms machine name”) of file “C:@oneneck\kms.txt”

How do I accomplish this?

Ignore last one. Found one of Jason’s other post and copied. I was definitely over complicating it.
substring after ": " of lines whose (it as string as lowercase contains “kms machine name from dns:” OR it as string as lowercase contains “registered kms machine name” ) of file “C:@oneneck\kms.txt”

2 Likes

You could also add this as WMI query to whatever analysis you’re building.

unique values of string values of selects "DiscoveredKeyManagementServiceMachineName from SoftwareLicensingProduct WHERE (PartialProductKey is not null)" of wmi

That doesn’t work with all operating systems. This was one of the first things I tried but half the servers came up blank.