Using a CSV file to import items into the CMDB

Sometimes you may want to bulk import configuration items into the CMDB. One way to do this is to import them using a Comma-Separated Value (CSV) file containing the CIs that relate to any class type or projection type already existing within Service Manager.

Getting ready

To import data using this method, two files are required, as follows:

  • A file containing the CIs to be imported; structured in a comma-delimited method and saved with a .csv extension.
  • A file that defines the class types or projection types used by all items in the CSV file. Also, this file defines the order in which the data appears as columns. The file must end with an .xml extension, and the authors recommend that you match the first part of the XML filename to the first part of the CSV filename.

How to do it...

First we need to create the data file. In this recipe, we will create a CSV file that will allow us to import some computer/server configuration items into Service Manager:

  1. Open Microsoft Excel or a similar spreadsheet application.

    On the first row create the following headers:

    • Computer Name
    • Number of Physical Processors
    • Number of Logical Processors
    • IP Address
  2. Then provide data, as shown in the following table:

    Computer Name

    Number of Physical Processors

    Number of Logical Processors

    IP Address

    WKST01

    1

    2

    172.16.1.50

    WKST02

    1

    4

    172.16.1.52

    WKST03

    1

    2

    172.16.1.57

    WKST04

    1

    2

    172.16.1.60

    WKST05

    1

    6

    172.16.1.68

    Server01

    2

    4

    172.16.1.200

    Server02

    2

    8

    172.16.1.201

    Server03

    4

    16

    172.16.1.202

    Server04

    4

    24

    172.16.1.203

    Server05

    1

    1

    172.16.1.204  

  3. Remove the first row with the column headings and then save the data as a CSV file called ComputerCIs.csv.
  4. The resulting CSV file contents should look like the following:
          WKST01,1,2,172.16.1.50
          WKST02,1,4,172.16.1.52
          WKST03,1,2,172.16.1.57
          WKST04,1,2,172.16.1.60
          WKST05,1,6,172.16.1.68
          Server01,2,4,172.16.1.200
          Server02,2,8,172.16.1.201
          Server03,4,16,172.16.1.202
          Server04,4,24,172.16.1.203
          Server05,1,1,172.16.1.204

    Next we need to create the XML file that defines the format and structure.

  5. The information stored in the data file is aimed at creating/updating CIs of the class Windows Computer, which is defined within Service Manager as a Microsoft.Windows.Computer class.
  6. We also have four columns of data that need mapping to the appropriate properties of the Microsoft.Windows.Computer class. You can either use the Authoring tool to locate the class and view the properties or you can use PowerShell.
  7. Use an XML editor to create the required XML file (for example, Notepad.exe). The following table shows the appropriate properties for our data that we need to map the columns to:

    Property

    Property name

    Computer Name

    PrincipalName

    Number of Physical Processors

    PhysicalProcessors

    Number of Logical Processors

    LogicalProcessors

    IP Address

    IPAddress

  8. Every XML definition file for CSV import starts with the following line:

    <CSVImportFormat> and ends with a similar closing line: </CSVImportFormat>

  9. The next line defines the class type to be imported. For this recipe, that needs to be the Microsoft.Windows.Computer class:
           <Class Type="Microsoft.Windows.Computer"> 
    

    This again requires a closing tag after the properties:

            </Class> 
    
  10. For each column of data within the data file, we need to specify the property of the class it requires mapping to and in the order in which they are listed within the CSV file:
          <Property ID="PrincipalName" /> 
          <Property ID="PhysicalProcessors" /> 
          <Property ID="LogicalProcessors" /> 
          <Property ID="IPAddress" /> 
    
  11. This will give a completed XML definition file that looks like this:
          <CSVImportFormat> 
          <Class Type="Microsoft.Windows.Computer"> 
          <Property ID="PrincipalName" /> 
          <Property ID="PhysicalProcessors" /> 
          <Property ID="LogicalProcessors" /> 
          <Property ID="IPAddress" /> 
          </Class> 
          </CSVImportFormat> 
    
  12. Save this XML file as ComputerCIs.xml.

Finally, these two files can now be used to import data into Service Manager by following these next steps:

  1. In the Service Manager console, navigate to the Administration workspace.
  2. Expand Administration and then click on Connectors.
  3. In the tasks pane on the right-hand side, click on Import from CSV File.
  4. On the Import Instances from CSV File screen that opens, use the Browse buttons to locate and open the XML and CSV files that were previously created.

    How to do it...

  5. Click on Import.
  6. The Importing Instances screen will now open and give you a progress bar for the import. If importing a large number of objects, this could take a considerable amount of time.

How it works...

By mapping the columns of data to the properties of the class you define within the XML file, it's possible to bulk import lots of data and have Service Manager match the data to the classes and properties so it can create the configuration items for you.

There's more...

The previous recipe shows the steps required to import data using a CSV file and the CSV connector, but in the following section there are some additional tips.

Using PowerShell to find the properties

Rather than having to open the Authoring tool and create a temporary management pack to view the different classes and their properties, PowerShell can be used to quickly look these up using the SCSM PowerShell Cmdlets available from CodePlex here: http://smlets.codeplex.com/.

For this recipe, we needed the properties for the Windows Computer class.

Open a PowerShell session and type the following:

Import-Module SMLets
$CI = Get-SCSMClass -Name Microsoft.Windows.Computer$
$CI.PropertyCollection

This will list all the properties directly used by the class (but not relationships).

Is CSV import just for configuration items?

No, CSV import is not just for configuration items. The CSV import method can also be used to create work items such as incidents by targeting the data at the System.WorkItem.Incident class by using the XML definition file and defining the properties for the data such as Title, Description, Impact, and Urgency.

This can be very useful especially for scenarios such as migrating Service Desk tools.

Complex CI importing

Sometimes you will want to import data that isn't held by just a single class, but maybe spans multiple classes and in particular class relationships.

For example, you may want to import a new computer CI, but specify the Asset Custodian for that device.

This can be achieved through the use of Type Projection and defining these in the XML definition file rather than just a single class type.

Apart from using the previous recipe and creating a new computer CI based on the information such as Computer Name, Number of Physical Processors, Number of Logical Processors, and IP Address, we also now need to specify the user details for the custodian.

The original XML definition file started with the following code:

<CSVImportFormat> 
<Class Type="Microsoft.Windows.Computer"> 

This time the Type Projection needs to be specified first:

<CSVImportFormat> <Projection Type="Microsoft.Windows.Computer.ProjectionType"> 
<Seed> 
<Class Type="Microsoft.Windows.Computer"> 

Specify the properties as before, close the class section with the </Class> tag, and then ensure that the seed section is also closed with a </Seed> tag.

Next, the additional class information for the Custodian can be added by starting a new section with a <Component Alias> tag:

<Component Alias="Custodian"> 
<Seed> 
<Class Type="System.Domain.User"> 
<Property ID="Domain"/> 
<Property ID="UserName"/> 
</Class> 
</Seed> 
</Component> 

This allows the data to be added to the data file in the format of the Domain Name in the column after IP Address and then the username of the Custodian that should be assigned.

Finally, the </Projection> tag must be placed towards the bottom to close the Type Projection definition.

The final XML would look like the following:

<CSVImportFormat> 
<Projection Type="Microsoft.Windows.Computer.ProjectionType"> 
<Seed> 
<Class Type="Microsoft.Windows.Computer"> 
<Property ID="PrincipalName"/> 
<Property ID="PhysicalProcessors"/> 
<Property ID="LogicalProcessors"/> 
<Property ID="IPAddress"/> 
</Class> 
</Seed> 
<Component Alias="Custodian"> 
<Seed> 
<Class Type="System.Domain.User"> 
<Property ID="Domain"/> 
<Property ID="UserName"/> 
</Class> 
</Seed> 
</Component> 
</Projection> 
</CSVImportFormat> 

See also

  • There are third-party tools that make CSV import and data mapping easier. See Appendix A, Community Extensions and Third-Party Commercial SCSM Solutions for information about Cireson's Asset Import tools and Provance's Data Management Pack.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset