AnsweredAssumed Answered

Snow XML import

Question asked by Dheemant on Dec 26, 2017
Latest reply on Apr 12, 2018 by iwan.van.den.hoek

I am trying to import devices into snow using snow XML import. But the output that i get from the script shows only 1 device in the xml. 

Here is the template & script that i have:

 

 

 

Host;Domain;CompType;CompManufacturer;User;OS;SWManufacturer;SWName;Version
COMP0001;AU;Notebook;HP;user1;User1;MS;MS Visio 2010;2010


## Check for correct input parameters
if($args.Count -ne 3)
{
Write-Output "" "csv2snow.ps1" "" "Syntax:" ".\csv2snow.ps1 <path to input.csv> <output-path> <sitename>" "" "Example:" ".\csv2snow.ps1 D:\snowtemplate.csv D:\Device XML" ""
return
}
else
{
$report=$args[0]
$outputdir=$args[1]
$sitename=$args[2]

## Check that the input file exists, otherwise exit
if (!(test-path($report))) { write-host "Input file not found.";return }

## Check that the output directory exists, otherwise create it
if (test-path($outputdir)) { } else { mkdir $outputdir > $Null }

## Import the report
write-host (get-date) "Importing file.."
$myinput = import-csv $report -Delimiter ";"
$totalrows = $myinput.Length
write-host "$totalrows rows found"
$current = 0
$currhost = $myinput[$current].host
write-host $currhost
$prods = @()
$now = get-date

## Go through all rows of the CSV
while ($current -lt $totalrows) {

$h = $myinput[$current].host

if($h -ne $currhost) {

#process the old host, then start with the new data
write-host (get-date) "Processing host $currhost"

## Start writing the SnowXML for the host
$output_file = $outputdir + "\" + $currhost +'.xml'

$XmlWriter = New-Object System.XMl.XmlTextWriter($output_file,$Null)
$xmlWriter.Formatting = [System.Xml.Formatting]::Indented
$xmlWriter.WriteStartDocument()

$lastupdate = $now.ToString("yyyy-MM-ddThh:mm:ss")

$xmlWriter.WriteStartElement("client")
$xmlWriter.WriteElementString('isdmisupported',"false")
$xmlWriter.WriteElementString('isapmsupported',"false")
$xmlWriter.WriteElementString('isplugandplay',"false")
$xmlWriter.WriteElementString('primarybustype',"false")
$xmlWriter.WriteElementString('secondarybustype',"false")
$xmlWriter.WriteElementString('hasusb',"false")
$xmlWriter.WriteElementString('biosreleasedate','1900-01-01T01:00:00')
$xmlWriter.WriteElementString('biosmanufacturer','(n/a)')
$xmlWriter.WriteElementString('biosserialnumber','(n/a)')
$xmlWriter.WriteElementString('biosversion','(n/a)')
$xmlWriter.WriteElementString('company',"false")
$xmlWriter.WriteElementString('dmiversion',"false")
$xmlWriter.WriteElementString('hasflashbios',"false")
$xmlWriter.WriteElementString('hostname',$currhost)
$xmlWriter.WriteElementString('isportable','false')
$xmlWriter.WriteElementString('lastupdate',$lastupdate)
$xmlWriter.WriteElementString('numberofprocessors','1')
$xmlWriter.WriteElementString('manufacturer','(n/a)')
$xmlWriter.WriteElementString('model','(n/a)')
$xmlWriter.WriteElementString('username','(n/a)')
$xmlWriter.WriteElementString('installdate',"1900-01-01T01:00:00")
$xmlWriter.WriteElementString('sitename',$sitename)
$xmlWriter.WriteElementString('clientidentifier',$currhost)
$xmlWriter.WriteElementString('clienttype',0)
$xmlWriter.WriteElementString('isvdi',"false")

$xmlWriter.WriteStartElement("memory")
$xmlWriter.WriteElementString('freeslots',"0")
$xmlWriter.WriteElementString('freeswap',"0")
$xmlWriter.WriteElementString('maxphysical',"0")
$xmlWriter.WriteElementString('totalslots',"0")
$xmlWriter.WriteElementString('totalphysical',"0")
$xmlWriter.WriteElementString('totalvirtual',"0")
$xmlWriter.WriteElementString('freevirtual',"0")
$xmlWriter.WriteElementString('freephysical',"0")
$xmlWriter.WriteElementString('totalswap',"0")
$xmlWriter.WriteEndElement()

## Process the software for the host
foreach ($prod in $prods) {

$xmlWriter.WriteStartElement("application")
$xmlWriter.WriteElementString('binarytype',"0")
$xmlWriter.WriteElementString('format',"0")
$xmlWriter.WriteElementString('installdate',"1900-01-01T12:00:00")
$xmlWriter.WriteElementString('name',$prod.SWName)
$xmlWriter.WriteElementString('islocal',"true")
$xmlWriter.WriteElementString('ismsi',"true")
$xmlWriter.WriteElementString('isshortcut',"false")
$xmlWriter.WriteElementString('processortype',"0")
$xmlWriter.WriteElementString('uninstallstring',"0")
$xmlWriter.WriteElementString('filename',"(n/a)")
$xmlWriter.WriteElementString('filepath',"(n/a)")
$xmlWriter.WriteElementString('filedatetime',"1900-01-01T12:00:00")
$xmlWriter.WriteElementString('filesize',0)
$xmlWriter.WriteElementString('version',"SNOWXML-" + $prod.SWVersion)
$xmlWriter.WriteElementString('manufacturer',"(n/a)")
$xmlWriter.WriteElementString('language',"Language Neutral")
$xmlWriter.WriteElementString('fullcappeakdate',"1900-01-01T12:00:00")
$xmlWriter.WriteElementString('isrecognized',"1")
$xmlWriter.WriteElementString('coresublimit',"0")
$xmlWriter.WriteElementString('issubcapacity',"false")
$xmlWriter.WriteElementString('subcappeakdate',"1900-01-01T12:00:00")
$xmlWriter.WriteElementString('pvusubcap',"0")
$xmlWriter.WriteElementString('ispvu',"false")
$xmlWriter.WriteElementString('coresubcap',"0")
$xmlWriter.WriteElementString('pvusublimit',"0")
$xmlWriter.WriteEndElement()
}

$xmlWriter.WriteStartElement("networkadapter")
$xmlWriter.WriteElementString('dnsserver',"0")
$xmlWriter.WriteElementString('macaddress',"0")
$xmlWriter.WriteElementString('productname',"0")
$xmlWriter.WriteElementString('defaultipgateway',"0")
$xmlWriter.WriteElementString('dhcpenabled',"true")
$xmlWriter.WriteElementString('ipaddress',"0.0.0.0")
$xmlWriter.WriteElementString('ipsubnet',"0")
$xmlWriter.WriteElementString('dhcpserver',"0")
$xmlWriter.WriteEndElement()

$xmlWriter.WriteStartElement("operatingsystem")
$xmlWriter.WriteElementString('activedesktop',"0")
$xmlWriter.WriteElementString('cdkey',"0")
$xmlWriter.WriteElementString('defaultbrowser',"0")
$xmlWriter.WriteElementString('tempdirectory',"0")
$xmlWriter.WriteElementString('username',"0")
$xmlWriter.WriteElementString('useruilanguage',"0")
$xmlWriter.WriteElementString('buildnumber',"0")
$xmlWriter.WriteElementString('buildtype',"0")
$xmlWriter.WriteElementString('codeset',"0")
$xmlWriter.WriteElementString('computername',"0")
$xmlWriter.WriteElementString('countrycode',"0")
$xmlWriter.WriteElementString('currenttimezonecode',"0")
$xmlWriter.WriteElementString('domainname',"0")
$xmlWriter.WriteElementString('localecode',"0")
$xmlWriter.WriteElementString('manufacturer',"(n/a)")
$xmlWriter.WriteElementString('name',$prods[0].OS)
$xmlWriter.WriteElementString('organization',"0")
$xmlWriter.WriteElementString('registereduser',"0")
$xmlWriter.WriteElementString('serialnumber',"0")
$xmlWriter.WriteElementString('systemdirectory',"0")
$xmlWriter.WriteElementString('systemuilanguagecode',"0")
$xmlWriter.WriteElementString('version',"0")
$xmlWriter.WriteElementString('versioninfo',"(n/a)")
$xmlWriter.WriteElementString('windowsdirectory',"0")
$xmlWriter.WriteEndElement()

$xmlWriter.WriteStartElement("processor")
$xmlWriter.WriteElementString('hyperthreading',"1")
$xmlWriter.WriteElementString('mathcoprocessor',"1")
$xmlWriter.WriteElementString('mmx',"1")
$xmlWriter.WriteElementString('numberofcores',"0")
$xmlWriter.WriteElementString('voltage',"4")
$xmlWriter.WriteElementString('currentclockspeed',"0")
$xmlWriter.WriteElementString('manufacturer',"(n/a)")
$xmlWriter.WriteElementString('maxclockspeed',"0")
$xmlWriter.WriteElementString('name',"(n/a)")
$xmlWriter.WriteElementString('processorid',"0")
$xmlWriter.WriteElementString('model',"(n/a)")
$xmlWriter.WriteElementString('numberofprocessors',"0")
$xmlWriter.WriteEndElement()

$xmlWriter.WriteEndElement > $Null
$xmlWriter.Finalize
$xmlWriter.Flush > $Null
$xmlWriter.Close()

$prods = @()
$currhost = $h
}

if($h -eq $currhost) {
## Create a new object with the details from current row of the CSV
$item = New-Object PSObject
$item | Add-Member -type NoteProperty -Name 'HostName' -Value $myinput[$current].Host
$item | Add-Member -type NoteProperty -Name 'OS' -Value $myinput[$current].OS
$item | Add-Member -type NoteProperty -Name 'SWName' -Value $myinput[$current].Type
$item | Add-Member -type NoteProperty -Name 'SWVersion' -Value $myinput[$current].Version
## Fill the array $prods with all items
$prods += $item
$currhost = $h
}

$current++
}
}

Outcomes