$Folder = "C:\Users\hubert.cornet\Downloads\Rules\"

clear

$Mag       = $Null
$FinalData = $Null
$RANK      = 100

For ($Num = 1 ;$Num -le 243 ; $Num++) {
    $RANK       = 10
    $RANK       = $RANK + $Num

    $measureNum = $Num | Measure-Object -Character

    If ($measureNum.Characters -eq 1 ) {
        $Mag = "00"+$Num
    }
    ElseIf ($measureNum.Characters -eq 2 ) {
        $Mag = "0"+$Num
    }
    ElseIf ($measureNum.Characters -eq 3 ) {
        $Mag = $Num
    }
    Else {

    }

    $DataTexte = "<?xml version='1.0'?>
<rules>
  <rule>
    <entities_id>Saint-Maclou</entities_id>
	<sub_type>RuleTicket</sub_type>
	<ranking>$RANK</ranking>
	<name>MAG$Mag</name>
	<description></description>
	<match>AND</match>
	<is_active>1</is_active>
	<comment></comment>
	<is_recursive>0</is_recursive>
	<uuid>500717c8-2bd6e957-53a12b5fd37f94.10365$Mag</uuid>
	<condition>3</condition>
	<date_creation></date_creation>
	<rulecriteria>
	  <criteria>_locations_id_of_requester</criteria>
	  <condition>0</condition>
	  <pattern>Magasins &amp;#62; MAG$Mag</pattern>
	</rulecriteria>
	<ruleaction>
	  <action_type>assign</action_type>
	  <field>locations_id</field>
	  <value>Magasins &amp;#62; MAG$Mag</value>
	</ruleaction>
  </rule>
</rules>"

    $File = $Folder+"\rules-$Mag.xml"
    Add-Content $File $DataTexte
}

