XML - convertto-xml - part 1

Publié le par Gaël Marot - GTEK-formation

La cmdlette convertto-xml permet de convertir des données dans un format xml.

  • le premier exemple va récupérer les informations sur les partitions des disques durs et retourner le nom, la taille et l'espace libre et transformer le tout dans un format XML

(gwmi win32_logicalDisk | where DriveType -eq 3 | Select-Object -Property deviceId,Size,freespace | convertTo-xml -NoTypeInformation).save("c:\temp\code.xml")

  • l'option -notypeinformation permet de ne pas stocker dans notre fichier XML le typage des données (comme string, int64...)

Résultat:

<?xml version="1.0"?>
<Objects>
  <Object>
    <Property Name="deviceId">C:</Property>
    <Property Name="Size">37210812416</Property>
    <Property Name="freespace">7776686080</Property>
  </Object>
  <Object>
    <Property Name="deviceId">D:</Property>
    <Property Name="Size">371056439296</Property>
    <Property Name="freespace">38467657728</Property>
  </Object>
  <Object>
    <Property Name="deviceId">G:</Property>
    <Property Name="Size">63653801984</Property>
    <Property Name="freespace">7707312128</Property>
  </Object>
  <Object>
    <Property Name="deviceId">H:</Property>
    <Property Name="Size">209715195904</Property>
    <Property Name="freespace">98475024384</Property>
  </Object>
  <Object>
    <Property Name="deviceId">I:</Property>
    <Property Name="Size">314570698752</Property>
    <Property Name="freespace">223521226752</Property>
  </Object>
  <Object>
    <Property Name="deviceId">M:</Property>
    <Property Name="Size">250057060352</Property>
    <Property Name="freespace">78553522176</Property>
  </Object>
</Objects>

Publié dans Powershell-xml

Pour être informé des derniers articles, inscrivez vous :
Commenter cet article