Video Screencast Help

Convert this NS6 custom inventory to NS7

Created: 17 Apr 2013 • Updated: 03 May 2013 | 15 comments
This issue has been solved. See solution.

Need some help guys..

I have converted most of our custom inventories over as they were simple re reads and the sort.. this one has me stumped though.

any help greatly appreciated

Old inventory...

'==========================================================================
' COMMENT: This script obtains all accounts and groups, along with
'   listing what types those are (user or group), that are members 
'   any local group on the machine it is run on.
'   It outputs the data to an Altiris inventory file format (.nsi).
'
'==========================================================================
strClassName = "Aex OS Local Groups"
strFileName = "C:\Program Files\Altiris\eXpress\Inventory\LocalGroups.nsi"
Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objTextFile = objFSO.OpenTextFile(strFileName, 2, True)
 
set filesys=CreateObject("Scripting.FileSystemObject") 
If filesys.FileExists("C:\Program Files\Altiris\eXpress\Inventory\LocalGroups.bak") Then
filesys.DeleteFile "C:\Program Files\Altiris\eXpress\Inventory\LocalGroups.bak"
End If
 
 
objTextFile.WriteLine("<InventoryClasses>")
objTextFile.WriteLine("  <InventoryClass name='" + strClassName + "' manufacturer='Altiris' description='' version='' platform='Win32' mifClass='Altiris|LOCALGROUPS|1.0'>")
objTextFile.WriteLine("    <xml xmlns:s=""uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"" xmlns:dt=""uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"" xmlns:rs=""urn:schemas-microsoft-com:rowset"" xmlns:z=""#RowsetSchema"">")
objTextFile.WriteLine("      <s:Schema id=""RowsetSchema"">")
objTextFile.WriteLine("        <s:ElementType name=""row"" content=""eltOnly"" rs:updatable=""true"">")
objTextFile.WriteLine("          <s:AttributeType name=""c0"" rs:name=""GroupName"" rs:number=""1"" rs:keycolumn=""false"" mifAttrId='1'>")
objTextFile.WriteLine("            <s:datatype dt:type=""string"" dt:maxLength=""255""/>")
objTextFile.WriteLine("          </s:AttributeType>")
objTextFile.WriteLine("          <s:AttributeType name=""c1"" rs:name=""Class"" rs:number=""2"" rs:keycolumn=""false"" mifAttrId='2'>")
objTextFile.WriteLine("            <s:datatype dt:type=""string"" dt:maxLength=""255""/>")
objTextFile.WriteLine("          </s:AttributeType>")
objTextFile.WriteLine("          <s:AttributeType name=""c2"" rs:name=""Domain"" rs:number=""3"" rs:keycolumn=""false"" mifAttrId='3'>")
objTextFile.WriteLine("            <s:datatype dt:type=""string"" dt:maxLength=""255""/>")
objTextFile.WriteLine("          </s:AttributeType>")
objTextFile.WriteLine("          <s:AttributeType name=""c3"" rs:name=""Account"" rs:number=""4"" rs:keycolumn=""false"" mifAttrId='4'>")
objTextFile.WriteLine("            <s:datatype dt:type=""string"" dt:maxLength=""255""/>")
objTextFile.WriteLine("          </s:AttributeType>")
objTextFile.WriteLine("        </s:ElementType>")
objTextFile.WriteLine("      </s:Schema>")
objTextFile.WriteLine("      <rs:data>")
 
strComputer = "."
Set wmi = GetObject("winmgmts:\\.\root\cimv2")
Set Groups = wmi.ExecQuery("Select * from Win32_Group  Where LocalAccount = True")
 
For Each group in Groups
Set colGroups = GetObject("WinNT://" & strComputer & "/" & group.Name)
  For Each objUser In colGroups.Members
       sUserName = objUser.Name
       sUserType = objUser.Class
       sDomain = Mid(objUser.AdsPath, 9)
       If InStr(1, sDomain, "/") > 0 then
sDomain = Mid(sDomain, 1, InStr(1, sDomain, "/")-1)
End If
  strOut =    "<z:row c0='" & ToXMLString(group.Name)& "'"
       strOut = strOut & " c1='" & ToXMLString(sUserType)& "'"
       strOut = strOut & " c2='" & ToXMLString(sDomain)& "'"
       strOut = strOut & " c3='" & ToXMLString(sUserName)& "'/>"
 
objTextFile.WriteLine(strOut)
  Next
Next
 
Function ToXMLString (strInput)
  Dim strOutput
  If (isNull(strInput)) Then
     ToXMLString = strInput
  Else
     strOutput = Replace(strInput, "&", "&amp;")
     strOutput = Replace(strOutput, """", "&quot;")
     strOutput = Replace(strOutput, "<", "&lt;")
     strOutput = Replace(strOutput, ">", "&gt;")
     ToXMLString = Replace(strOutput, "'", "&#39;")
  End If
End Function
 
objTextFile.WriteLine("      </rs:data>")
objTextFile.WriteLine("    </xml>")
objTextFile.WriteLine("  </InventoryClass>")
objTextFile.WriteLine("</InventoryClasses>")
objTextFile.close
 

Comments 15 CommentsJump to latest comment

TeleFragger's picture

guess no one?

Did we help you? Please Mark As Solution those posts which resolve your problem,

jason.f's picture

What data do you need to collect? Does it need to be in VBScript or can you use powershell?

jason.f's picture

Ok I think I have what you need in vbscript. When you build your data class there should be 3 columns, User Name, User Type, and domain in that order. Just plugin your GUID and you should be ready to go. If you need it in powershell let me know, I have a template for inventory.

 

'===================================================================================================================
'      On Error Resume Next
strComputer = "."
Set wmi = GetObject("winmgmts:\\.\root\cimv2")
Set Groups = wmi.ExecQuery("Select * from Win32_Group  Where LocalAccount = True")
 
'===================================================================================================================

'Create instance of Altiris NSE component
dim nse
set nse = WScript.CreateObject ("Altiris.AeXNSEvent")

' Set the header data of the NSE
' Please don't modify this GUID
nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"
nse.Priority = 1

'Create Inventory data block. Here assumption is that the data class with below guid is already configured on server
dim objDCInstance
set objDCInstance = nse.AddDataClass ("{a5683a9b-04fc-42a9-ad16-65a4962e7ebe}")

dim objDataClass
set objDataClass = nse.AddDataBlock (objDCInstance)

'Add a new row
dim objDataRow

For Each group in Groups
    Set colGroups = GetObject("WinNT://" & strComputer & "/" & group.Name)
    set objDataRow = objDataClass.AddRow

    For Each objUser In colGroups.Members
       sUserName = objUser.Name
       sUserType = objUser.Class
       sDomain = Mid(objUser.AdsPath, 9)
        If InStr(1, sDomain, "/") > 0 then
            sDomain = Mid(sDomain, 1, InStr(1, sDomain, "/")-1)
        End If
    objDataRow.SetField 0, sUSername
    objDataRow.SetField 1, sUSerType
    objDataRow.SetField 2, sDomain

    wscript.echo "User name: " & sUSername
    wscript.echo "User Type: " & sUSerType
    wscript.echo "Domain: " & sDomain
    wscript.echo "-------------------------------------------------"

    Next
Next

nse.SendQueued

 

 

Jason

TeleFragger's picture

thanks ran into some major issues so will be some time before i try this.

I was on the route of just using the ole fashioned NS6 way in ns7 following

http://www.symantec.com/business/support/index?page=content&id=HOWTO10489

 

Did we help you? Please Mark As Solution those posts which resolve your problem,

TeleFragger's picture

appreciate your help jason... it didnt work.. had some blanks and the sort...

i followed the howto i found and it works.. well creates the .nsi but fails to import the data.

I get a 

Failed to load inventory. The resource start tag on line 21 oes not match the end tag of rs:data line 23 position 9

attached is my nsi (edited some bit of course just account names)

 

 

AttachmentSize
LocalGroups.nsi_.txt 2.04 KB

Did we help you? Please Mark As Solution those posts which resolve your problem,

jason.f's picture

You shouldn't have to worry about the nsi file in 7.1. Did you create your custom data class under Settings/All Settings/Discovery and Inventory/Manage custom data classes? Once you do that and get the GUID of the data class you should only have to plug that into the script and nothing else. I use a very similar versions of that script all the time without issue.

TeleFragger's picture

yes i did that... will try it again...

 

Did we help you? Please Mark As Solution those posts which resolve your problem,

TeleFragger's picture

did some toying and still couldnt get it to go..

now in yours (turned on logging to c:\temp) and i found not all the same information as mine pulls..

i put a partial screenshot of each for you to see the difference...

yours has some blank fields.. mine has more... and a bit different. So mine is working..

what the problem i am having is this... on the upload it is giving me the erro about the :rs line...

 

vbs.jpg nse.jpg

Did we help you? Please Mark As Solution those posts which resolve your problem,

TeleFragger's picture

oh and slightly ediited of course.. shopped some of our admin groups up

Did we help you? Please Mark As Solution those posts which resolve your problem,

jason.f's picture

Ok I just built a custom data class w/ the 3 attributes and checked the box for "Allow multiple rows from a single computer resource" and plugged that GUID into the script from above and ran it and my data showed up in the DB. I do have a few null lines, i'm not sure what those are from yet but at least I can see that the data did get inserted.

Output from script (edited):

User name: Administrator
User Type: User
Domain: Computer
-------------------------------------------------
User name: Administrator
User Type: User
Domain: Computer
-------------------------------------------------
User name: Domain Admins
User Type: Group
Domain: Domain
-------------------------------------------------
User name: Workstation-Admins
User Type: Group
Domain: Domain
-------------------------------------------------
User name: user name
User Type: User
Domain: Domain
-------------------------------------------------
User name: user name
User Type: User
Domain: Domain
-------------------------------------------------
User name: Server-Admins
User Type: Group
Domain: Domain
-------------------------------------------------
User name: Guest
User Type: User
Domain: local computer
-------------------------------------------------
User name: user name
User Type: User
Domain: domain
-------------------------------------------------
User name: testjason
User Type: User
Domain: domain
-------------------------------------------------
User name: user name
User Type: User
Domain: domain
-------------------------------------------------
User name: INTERACTIVE
User Type: Group
Domain: NT AUTHORITY
-------------------------------------------------
User name: Authenticated Users
User Type: Group
Domain: NT AUTHORITY
-------------------------------------------------
User name: SQLBrowser
User Type: Group
Domain: NT SERVICE
-------------------------------------------------
User name: NETWORK SERVICE
User Type: Group
Domain: NT AUTHORITY
-------------------------------------------------
User name: SYSTEM
User Type: Group
Domain: NT AUTHORITY
-------------------------------------------------
User name: MSSQL$SQLEXPRESS
User Type: Group
Domain: NT SERVICE
-------------------------------------------------
User name: SQLAgent$SQLEXPRESS
User Type: Group
Domain: NT SERVICE
-------------------------------------------------

This is what I'm showing in the DB (edited):

User_Name    User_Type    Domain
Server-Admins    Group    WHS
NULL    NULL    NULL
NULL    NULL    NULL
NULL    NULL    NULL
NULL    NULL    NULL
Guest    User    computer
NULL    NULL    NULL
NULL    NULL    NULL
NULL    NULL    NULL
NULL    NULL    NULL
NULL    NULL    NULL
username    User    domain
NULL    NULL    NULL
Authenticated Users    Group    NT AUTHORITY
SQLBrowser    Group    NT SERVICE
SYSTEM    Group    NT AUTHORITY
MSSQL$SQLEXPRESS    Group    NT SERVICE
SQLAgent$SQLEXPRESS    Group    NT SERVICE
NULL    NULL    NULL

TeleFragger's picture

cool... yeah i had blanks in my file thus would have had nulls.. but mine didnt populate.. weird...

also if you look at my nse you can see the 4 fields and how I am trying to get it to function...

 

side note.. i see your domain is WHS... is that windows home server by chance? if so im running that at home and love it!!!!  /side note

Did we help you? Please Mark As Solution those posts which resolve your problem,

jason.f's picture

Ok, I realized my stupid mistake that was giving us the blank rows. Duty called so I didn't have much time to work on this recently but once I started playing with it in powershell I saw what I did. We need to move the new row line into the inner loop as shown below.

No, WHS isn't Windows Home Server it's our actual domain here at work. I'm more of a linux home server kind of guy :)

For Each group in Groups
    Set colGroups = GetObject("WinNT://" & strComputer & "/" & group.Name)
    set objDataRow = objDataClass.AddRow REMOVE THIS LINE

    For Each objUser In colGroups.Members

set objDataRow = objDataClass.AddRow AND ADD IT HERE
       sUserName = objUser.Name
       sUserType = objUser.Class
       sDomain = Mid(objUser.AdsPath, 9)
        If InStr(1, sDomain, "/") > 0 then
            sDomain = Mid(sDomain, 1, InStr(1, sDomain, "/")-1)
        End If

SOLUTION
TeleFragger's picture

wow that worked like a charm!!!!

 

talked to a bud of mine... and he got the 4th column in for me that I wanted!!!!

 

had to add 

 

 

For Each group in Groups
    Set colGroups = GetObject("WinNT://" & strComputer & "/" & group.Name)
    For Each objUser In colGroups.Members
      set objDataRow = objDataClass.AddRow
       sUserName = objUser.Name
       sUserType = objUser.Class
'added
  sGroupName = Group.Name
 
       sDomain = Mid(objUser.AdsPath, 9)
        If InStr(1, sDomain, "/") > 0 then
            sDomain = Mid(sDomain, 1, InStr(1, sDomain, "/")-1)
        End If
    objDataRow.SetField 0, sUSername
    objDataRow.SetField 1, sUSerType
    objDataRow.SetField 2, sDomain
'added
 
    objDataRow.SetField 3, sGroupName
 
    Next
 

Did we help you? Please Mark As Solution those posts which resolve your problem,

jason.f's picture

Awesome, glad it's working for you now. Can you mark one of my posts as a solution.

Thanks,

Jason

TeleFragger's picture

yes was getting ready to do that for you!!!! really appreciate all this.

 

guess lesson learned is that the new inventories create the nse, tmp or whatever you want to call it... automatically as in ns6 we had to manually write the lines to those files... 

thanks again!

 

Did we help you? Please Mark As Solution those posts which resolve your problem,