WMIC Improve *CVS* Pattern

Discussion in 'Scripting' started by Dark Dinosaur, Jan 8, 2024.

  1. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    4,189
    6,018
    150
    #1 Dark Dinosaur, Jan 8, 2024
    Last edited: Jan 8, 2024
    this pattern -
    will return results like this

    Code:
    ,16010101000000.000000-000,0,ce5ffcaf-75da-4362-a9cb-00d2689918aa,Office21Professional2021R_Grace,5,DGRYH
    ,16010101000000.000000-000,259147,fbdb3e18-a8ef-4fb3-9183-dffd60bd0984,Office21ProPlus2021VL_KMS_Client_AE,1,6F7TH
    
    Regular /format:csv output.
    Code:
    Node,EvaluationEndDate,GracePeriodRemaining,ID,LicenseFamily,LicenseStatus,PartialProductKey
    DESKTOP-KADAI3B,16010101000000.000000-000,0,ce5ffcaf-75da-4362-a9cb-00d2689918aa,Office21Professional2021R_Grace,5,DGRYH
    DESKTOP-KADAI3B,16010101000000.000000-000,259144,fbdb3e18-a8ef-4fb3-9183-dffd60bd0984,Office21ProPlus2021VL_KMS_Client_AE,1,6F7TH
    
    how to use it?
    add `/format:"Location X Y Z\csv.xsl"`
    must use "" for location !!!
    Code:
    wmic path SoftwareLicensingProduct where (Name like '%office%' and PartialProductKey is not NULL) get EvaluationEndDate,GracePeriodRemaining,ID,LicenseFamily,LicenseStatus,PartialProductKey /format:"Location\csv.xsl"
    
    Code
    save as `csv.xsl`
    Code:
    <?xml version="1.0"?>
    <!-- Copyright (c) Microsoft Corporation.  All rights reserved. -->
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output encoding="utf-16" omit-xml-declaration="yes"/>
    <xsl:param name="norefcomma"/>
    <!-- *MAIN* -->
    <xsl:template match="/">
    <xsl:for-each select="COMMAND/RESULTS[1]/CIM/INSTANCE[1]"><xsl:value-of select="@NAME"/><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each><xsl:apply-templates select="COMMAND/RESULTS"/></xsl:template>
    <!-- *PATTERN* -->
    <xsl:template match="INSTANCE" xml:space="preserve">
    ,<xsl:for-each select="PROPERTY|PROPERTY.ARRAY|PROPERTY.REFERENCE"><xsl:apply-templates select="."/><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each></xsl:template>
    <!-- *MISC* -->
    <xsl:template match="VALUE" xml:space="preserve"><xsl:value-of select="."/></xsl:template>
    <xsl:template match="VALUE.ARRAY" xml:space="preserve">{<xsl:for-each select="VALUE"><xsl:apply-templates select="."/><xsl:if test="position()!=last()">;</xsl:if></xsl:for-each>}</xsl:template>
    <xsl:template match="VALUE.REFERENCE">"<xsl:apply-templates select="INSTANCEPATH/NAMESPACEPATH"/><xsl:apply-templates select="INSTANCEPATH/INSTANCENAME|INSTANCENAME"/>"</xsl:template>
    <xsl:template match="PROPERTY"><xsl:apply-templates select="VALUE"/></xsl:template>
    <xsl:template match="PROPERTY.ARRAY"><xsl:for-each select="VALUE.ARRAY"><xsl:apply-templates select="."/></xsl:for-each></xsl:template>
    <xsl:template match="PROPERTY.REFERENCE" xml:space="preserve"><xsl:apply-templates select="VALUE.REFERENCE"></xsl:apply-templates></xsl:template>
    <xsl:template match="RESULTS" xml:space="preserve"><xsl:apply-templates select="CIM/INSTANCE"/></xsl:template>
    <xsl:template match="INSTANCENAME"><xsl:value-of select="@CLASSNAME"/><xsl:for-each select="KEYBINDING"><xsl:if test="position()=1">.</xsl:if><xsl:value-of select="@NAME"/>="<xsl:value-of select="KEYVALUE/text()"/>"<xsl:if test="position()!=last()"></xsl:if><xsl:if test="not($norefcomma=&quot;true&quot;)">,</xsl:if><xsl:if test="$norefcomma=&quot;true&quot;"><xsl:text> </xsl:text></xsl:if></xsl:for-each></xsl:template>
    <xsl:template match="NAMESPACEPATH">\\<xsl:value-of select="HOST/text()"/><xsl:for-each select="LOCALNAMESPACEPATH/NAMESPACE">\<xsl:value-of select="@NAME"/></xsl:for-each>:</xsl:template>
    </xsl:stylesheet>
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    4,189
    6,018
    150
    Command
    Code:
    wmic path SoftwareLicensingProduct get Name,ID /format:"%cd%\csv.xsl"
    
    Output
    Code:
    0724cb7d-3437-4cb7-93cb-830375d0079d,Windows(R), EnterpriseSN edition
    2c060131-0e43-4e01-adc1-cf5ad1100da8,Windows(R), EnterpriseSN edition
    30a42c86-b7a0-4a34-8c90-ff177cb2acb7,Windows(R), EnterpriseSN edition
    49cad824-f064-4f4c-bb38-025651fd3e44,Office 21, Office21Professional2021R_Trial edition
    60b3ec1b-9545-4921-821f-311b129dd6f6,Windows(R), EnterpriseSN edition
    6986e2e2-307d-422b-90e6-17b466ba629b,Office 21, Office21Professional2021R_OEM_Perp edition
    7103a333-b8c8-49cc-93ce-d37c09687f92,Windows(R), EnterpriseSN edition
    711e48a6-1a79-4b00-af10-73f4ca3aaac4,Office 21, Office21Professional2021R_Retail edition
    7a802526-4c94-4bd1-ba14-835a1aca2120,Windows(R), EnterpriseSN edition
    8fdb1f1e-663f-4f2e-8fdb-7c35aee7d5ea,Office 24, Office24ProPlus2024PreviewVL_MAK_AE edition
    90da7373-1c51-430b-bf26-c97e9c5cdc31,Windows(R), EnterpriseSN edition
    ce5ffcaf-75da-4362-a9cb-00d2689918aa,Office 21, Office21Professional2021R_Grace edition
    d552befb-48cc-4327-8f39-47d2d94f987c,Windows(R), EnterpriseSN edition
    e64697e4-0ab5-45fe-ab1a-0fd557e11b34,Office 21, Office21Professional2021DemoR_BypassTrial180 edition
    fceda083-1203-402a-8ec4-3d7ed9f3648c,Office 24, Office24ProPlus2024PreviewVL_KMS_Client_AE edition
    
    Lite pattern
    Code:
    <!-- Copyright (c) Microsoft Corporation.  All rights reserved. -->
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output encoding="utf-16" omit-xml-declaration="yes"/>
    <!-- *MAIN* -->
    <xsl:template match="/">
      <xsl:for-each select="COMMAND/RESULTS[1]/CIM/INSTANCE[1]"><xsl:value-of select="@NAME"/><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each><xsl:apply-templates select="COMMAND/RESULTS"/>
    </xsl:template>
    <!-- *PATTERN* -->
    <xsl:template match="INSTANCE" xml:space="preserve">
    <xsl:for-each select="PROPERTY|PROPERTY.ARRAY|PROPERTY.REFERENCE"><xsl:apply-templates select="."/><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each></xsl:template>
    </xsl:stylesheet>
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    4,189
    6,018
    150
    Command
    Code:
    wmic path SoftwareLicensingProduct get Name,ID,ApplicationID /format:"%cd%\csv.xsl"
    
    Output
    Code:
    55c92734-d682-4d71-983e-d6ec3f16059f,0724cb7d-3437-4cb7-93cb-830375d0079d,Windows(R), EnterpriseSN edition
    55c92734-d682-4d71-983e-d6ec3f16059f,2c060131-0e43-4e01-adc1-cf5ad1100da8,Windows(R), EnterpriseSN edition
    55c92734-d682-4d71-983e-d6ec3f16059f,30a42c86-b7a0-4a34-8c90-ff177cb2acb7,Windows(R), EnterpriseSN edition
    0ff1ce15-a989-479d-af46-f275c6370663,49cad824-f064-4f4c-bb38-025651fd3e44,Office 21, Office21Professional2021R_Trial edition
    55c92734-d682-4d71-983e-d6ec3f16059f,60b3ec1b-9545-4921-821f-311b129dd6f6,Windows(R), EnterpriseSN edition
    0ff1ce15-a989-479d-af46-f275c6370663,6986e2e2-307d-422b-90e6-17b466ba629b,Office 21, Office21Professional2021R_OEM_Perp edition
    55c92734-d682-4d71-983e-d6ec3f16059f,7103a333-b8c8-49cc-93ce-d37c09687f92,Windows(R), EnterpriseSN edition
    0ff1ce15-a989-479d-af46-f275c6370663,711e48a6-1a79-4b00-af10-73f4ca3aaac4,Office 21, Office21Professional2021R_Retail edition
    55c92734-d682-4d71-983e-d6ec3f16059f,7a802526-4c94-4bd1-ba14-835a1aca2120,Windows(R), EnterpriseSN edition
    0ff1ce15-a989-479d-af46-f275c6370663,8fdb1f1e-663f-4f2e-8fdb-7c35aee7d5ea,Office 24, Office24ProPlus2024PreviewVL_MAK_AE edition
    55c92734-d682-4d71-983e-d6ec3f16059f,90da7373-1c51-430b-bf26-c97e9c5cdc31,Windows(R), EnterpriseSN edition
    0ff1ce15-a989-479d-af46-f275c6370663,ce5ffcaf-75da-4362-a9cb-00d2689918aa,Office 21, Office21Professional2021R_Grace edition
    55c92734-d682-4d71-983e-d6ec3f16059f,d552befb-48cc-4327-8f39-47d2d94f987c,Windows(R), EnterpriseSN edition
    0ff1ce15-a989-479d-af46-f275c6370663,e64697e4-0ab5-45fe-ab1a-0fd557e11b34,Office 21, Office21Professional2021DemoR_BypassTrial180 edition
    0ff1ce15-a989-479d-af46-f275c6370663,fceda083-1203-402a-8ec4-3d7ed9f3648c,Office 24, Office24ProPlus2024PreviewVL_KMS_Client_AE edition
    
    Bare minimum pattern
    Code:
    <!-- Copyright (c) Microsoft Corporation.  All rights reserved. -->
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output omit-xml-declaration="yes"/>
    <!-- *MAIN* -->
    <xsl:template match="/">
      <xsl:for-each select="COMMAND/RESULTS[1]/CIM/INSTANCE[1]"><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each><xsl:apply-templates select="COMMAND/RESULTS"/>
    </xsl:template> 
    <!-- *PATTERN* -->
    <xsl:template match="INSTANCE" xml:space="preserve">
    <xsl:for-each select="PROPERTY|PROPERTY.ARRAY|PROPERTY.REFERENCE"><xsl:apply-templates select="."/><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each></xsl:template> 
    </xsl:stylesheet>
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    4,189
    6,018
    150
    You can also save CSV files in well-known locations like
    c:\windows

    and use this command
    /format:csv.xsl

    list of well known locations. etc.
    c:\windows;
    c:\windows\system32;
    c:\windows\system32\wbem
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...