Script:
#Convert CSV FILES TO XML
#Test if directory has and csv files, if yes then proceed
if((test-path c:\temp\csv\*csv) -eq 1){
$csvpath= get-childitem c:\temp\csv\*.csv| foreach-object { $_.FullName }
$csv=Import-Csv $csvpath
$xml=[xml]'<csvobjects/>'
$p=$csv|gm -MemberType NoteProperty|%{$_.Name}
$csv|%{
$row=$xml.CreateElement('row')
$r=$_;
$p|%{
$el=$xml.CreateElement($_)
$el.InnerText=$r.($_)
[void]$row.appendChild($el)
}
[void]$xml.DocumentElement.AppendChild($row)
}
$currdate=get-date -f MM_dd_yyyy_hh
$f= "c:\temp\xml\$($currdate).xml"
$xml.Save($f)
#if the directory does not have any .csv files then break
else {
break
}