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.
To import data using this method, two files are required, as follows:
.csv
extension..xml
extension, and the authors recommend that you match the first part of the XML filename to the first part of the CSV filename.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:
On the first row create the following headers:
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 |
ComputerCIs.csv
.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.
Microsoft.Windows.Computer
class.Microsoft.Windows.Computer
class. You can either use the Authoring tool to locate the class and view the properties or you can use PowerShell.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 |
<CSVImportFormat>
and ends with a similar closing line: </CSVImportFormat>
Microsoft.Windows.Computer
class:<Class Type="Microsoft.Windows.Computer">
This again requires a closing tag after the properties:
</Class>
<Property ID="PrincipalName" /> <Property ID="PhysicalProcessors" /> <Property ID="LogicalProcessors" /> <Property ID="IPAddress" />
<CSVImportFormat> <Class Type="Microsoft.Windows.Computer"> <Property ID="PrincipalName" /> <Property ID="PhysicalProcessors" /> <Property ID="LogicalProcessors" /> <Property ID="IPAddress" /> </Class> </CSVImportFormat>
ComputerCIs.xml
.Finally, these two files can now be used to import data into Service Manager by following these next steps:
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.
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.
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).
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.
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>