1

Thanks a lot for your time in reading this. I would really appreciate if you can show me some lights on how to achieve this.

the idea to build a PS script to revoke\release few license based on few conditions from an command line output

sample license status can be fetched through a command line below

--------------------------------------------------------------------
Trust Flags       = FULLY TRUSTED
Fulfillment Type: TRIAL
Status: ENABLED
Fulfillment ID: LOCAL_TRIAL_FID_586
Entitlement ID: SC_LVJ1BYNH8ZF6H57OSCBZTFWPVR7PCR8
Product ID: NAME=Tableau Desktop TS;VERSION=4.0
Suite ID: NONE
Expiration date: 23-oct-2020
Feature line(s):


INCREMENT TableauDesktop tableau 2021.1108 permanent 1 \
        VENDOR_STRING=EntitlementID=;EDITION=Professional;CAP=REG:STANDARD,WARN:14,NOGRACE;DC_STD=default;DC_CAP=;TRIALVER=2019.1;FulfillmentID=;ActivationID=;OEMNAME=;GRACE=;MAP_STD=default;MAP_CAP=;OFFLINE= \
        ISSUER="Tableau Software" ISSUED=9-nov-2018 START=8-nov-2018 \
        TS_OK SIGN="042D 811B 5D78 81EA E6E7 28BD 607A F3D3 028E DC82 \
        E310 A6BC C1D5 0913 5CBC 18B5 8671 7C7D C0B7 3C46 D1E7 A16C \
        6C84 3694 BB4C DB73 4B59 C419 D820 58E0"

--------------------------------------------------------------------

Trust Flags       = FULLY TRUSTED
Fulfillment Type: TRIAL
Status: ENABLED
Fulfillment ID: LOCAL_TRIAL_FID_590
Entitlement ID: SC_LVJ1BYNH8ZF6H57OSCBZTFWPVR7PTR2
Product ID: NAME=Tableau Desktop TS;VERSION=4.0
Suite ID: NONE
Expiration date: 23-oct-2020
Feature line(s):


INCREMENT TableauDesktop tableau 2021.1108 permanent 1 \
        VENDOR_STRING=EntitlementID=;EDITION=Professional;CAP=REG:STANDARD,WARN:14,NOGRACE;DC_STD=default;DC_CAP=;TRIALVER=2019.1;FulfillmentID=;ActivationID=;OEMNAME=;GRACE=;MAP_STD=default;MAP_CAP=;OFFLINE= \
        ISSUER="Tableau Software" ISSUED=9-nov-2018 START=8-nov-2018 \
        TS_OK SIGN="042D 811B 5D78 81EA E6E7 28BD 607A F3D3 028E DC82 \
        E310 A6BC C1D5 0913 5CBC 18B5 8671 7C7D C0B7 3C46 D1E7 A16C \
        6C84 3694 BB4C DB73 4B59 C419 D820 58E0"

--------------------------------------------------------------------

we need to parse the "Trust Flags", "status" and "Entitlement ID" from both the entries in to an hash-table so that we can perform logical operations.

your directions will be much helpful!! My sincere thanks again

0

2 Answers 2

1

You can use a switch statement with the -Regex switch to perform regular expression-based line-by-line processing:

# Initialize the (ordered) output hash table.
$hashTable = [ordered] @{}

# Process the input file line by line and populate the hash table.
switch -file input.txt -regex {
  '^(Trust Flags|status|Entitlement ID):? +(?:= +)?(.*)' {
    $hashTable[$Matches.1] = $Matches.2
  }
}

# Output the resulting hash tabe.
$hashTable

The above yields:

Name                           Value
----                           -----
Trust Flags                    FULLY TRUSTED
Status                         ENABLED
Entitlement ID                 SC_LVJ1BYNH8ZF6H57OSCBZTFWPVR7PTR2
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your valuable time on working this out. Since the input file may have 2 or 3 set of data, Can you please help me how to work that out. probably an array of hash
@karockiad: This answers addresses your question as asked, which hopefully makes it also helpful to future readers, so please accept it (unless you see a problem with it). If you need further assistance, please ask a new question (which can build on this one).
@karockiad: In the simplest case: $hashTables = foreach ($file in $files) { <code from this answer with $file as the input to the switch statement> }. This will store an array of hashtables in $hashTables.
1

I would first check if the command utility offers you a way to control the output. Many command line utilities do provide options for creating structured output such as csv or xml. If you are indeed limited to just text, then this is a perfect scenario to utilize ConvertFrom-String

Now depending on how much the data varies, you may need to adjust the "sample" data used in the template. I've found the key is to provide just enough training data and not too much. See the example below.

First create a template. I'm not sure what other possible values you may face but I did change the second example in the template just to provide a wider net. You could adjust these to actual possible values for better results.

$template = @'
Trust Flags       = {TrustFlags*:FULLY TRUSTED}
Fulfillment Type: TRIAL
Status: {Status:ENABLED}
Fulfillment ID: LOCAL_TRIAL_FID_586
Entitlement ID: {EntitlementID:SC_LVJ1BYNH8ZF6H57OSCBZTFWPVR7PCR8}

Trust Flags       = {TrustFlags*:not trusted}
Fulfillment Type: TRIAL
Status: {Status:Disabled}
Fulfillment ID: LOCAL_TRIAL_FID_590
Entitlement ID: {EntitlementID:AB_12345678ABCDEF}

'@

Now apply the template to the text

$text = @'
--------------------------------------------------------------------
Trust Flags       = FULLY TRUSTED
Fulfillment Type: TRIAL
Status: ENABLED
Fulfillment ID: LOCAL_TRIAL_FID_586
Entitlement ID: SC_LVJ1BYNH8ZF6H57OSCBZTFWPVR7PCR8
Product ID: NAME=Tableau Desktop TS;VERSION=4.0
Suite ID: NONE
Expiration date: 23-oct-2020
Feature line(s):


INCREMENT TableauDesktop tableau 2021.1108 permanent 1 \
        VENDOR_STRING=EntitlementID=;EDITION=Professional;CAP=REG:STANDARD,WARN:14,NOGRACE;DC_STD=default;DC_CAP=;TRIALVER=2019.1;FulfillmentID=;ActivationID=;OEMNAME=;GRACE=;MAP_STD=default;MAP_CAP=;OFFLINE= \
        ISSUER="Tableau Software" ISSUED=9-nov-2018 START=8-nov-2018 \
        TS_OK SIGN="042D 811B 5D78 81EA E6E7 28BD 607A F3D3 028E DC82 \
        E310 A6BC C1D5 0913 5CBC 18B5 8671 7C7D C0B7 3C46 D1E7 A16C \
        6C84 3694 BB4C DB73 4B59 C419 D820 58E0"

--------------------------------------------------------------------

Trust Flags       = FULLY TRUSTED
Fulfillment Type: TRIAL
Status: ENABLED
Fulfillment ID: LOCAL_TRIAL_FID_590
Entitlement ID: SC_LVJ1BYNH8ZF6H57OSCBZTFWPVR7PTR2
Product ID: NAME=Tableau Desktop TS;VERSION=4.0
Suite ID: NONE
Expiration date: 23-oct-2020
Feature line(s):


INCREMENT TableauDesktop tableau 2021.1108 permanent 1 \
        VENDOR_STRING=EntitlementID=;EDITION=Professional;CAP=REG:STANDARD,WARN:14,NOGRACE;DC_STD=default;DC_CAP=;TRIALVER=2019.1;FulfillmentID=;ActivationID=;OEMNAME=;GRACE=;MAP_STD=default;MAP_CAP=;OFFLINE= \
        ISSUER="Tableau Software" ISSUED=9-nov-2018 START=8-nov-2018 \
        TS_OK SIGN="042D 811B 5D78 81EA E6E7 28BD 607A F3D3 028E DC82 \
        E310 A6BC C1D5 0913 5CBC 18B5 8671 7C7D C0B7 3C46 D1E7 A16C \
        6C84 3694 BB4C DB73 4B59 C419 D820 58E0"

--------------------------------------------------------------------
'@

$text | ConvertFrom-String -TemplateContent $template -OutVariable results

TrustFlags    Status  EntitlementID                     
----------    ------  -------------                     
FULLY TRUSTED ENABLED SC_LVJ1BYNH8ZF6H57OSCBZTFWPVR7PCR8
FULLY TRUSTED ENABLED SC_LVJ1BYNH8ZF6H57OSCBZTFWPVR7PTR2

For the demonstration I used Out-Variable so we could see the output as well as capture to a variable. This obviously could be changed to just $variable = instead. The $results variable is a PSCustomObject which you can use like any other.

$results | where trustflags -eq 'Fully Trusted'

TrustFlags    Status  EntitlementID                     
----------    ------  -------------                     
FULLY TRUSTED ENABLED SC_LVJ1BYNH8ZF6H57OSCBZTFWPVR7PCR8
FULLY TRUSTED ENABLED SC_LVJ1BYNH8ZF6H57OSCBZTFWPVR7PTR2

$results.entitlementid

SC_LVJ1BYNH8ZF6H57OSCBZTFWPVR7PCR8
SC_LVJ1BYNH8ZF6H57OSCBZTFWPVR7PTR2

To use it against a file it's probably best to use Get-Content -Raw depending on just how large those files are.

Get-Content $textfile -Raw | ConvertFrom-String -TemplateContent $template -OutVariable results

2 Comments

ConvertFrom-String provides separator-based parsing as well as heuristics-based parsing based on templates containing example values. The separator-based parsing applies automatic type conversions you cannot control, and the template language is poorly documented, with the exact behavior hard to predict - it's best to avoid this cmdlet altogether. Also note that it's not available in PowerShell Core (v6+).
Thanks a ton for working this out for me! I would appreciate if you can point me a guide to properly configure a template content.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.