Files
Scripts_Powershell/ajt_creator/ajt2.ps1
2020-05-25 10:34:53 +02:00

81 lines
1.9 KiB
PowerShell

# On efface / backup tous les fichiers MGPT*.dat existants
$fileToCheck = "$env:USERPROFILE\Desktop\MGPT*.dat"
$archivePath = "$env:USERPROFILE\Desktop\MGPT_Ajt_Archives"
if (Test-Path $fileToCheck -PathType leaf) { # leaf: file, container: folder, any: tous
Write-host $fileToCheck
#Remove-Item $fileToCheck
if (!(Test-Path $archivePath -PathType container)) {
mkdir $archivePath
}
Move-Item -Path $fileToCheck -Destination $archivePath -Force
}
# On importe le .csv selon $header
$header = "planche", "d_deb", "X", "h_deb", "h_fin", "J", "d_fin", "lieu", "VC", "gare", "zep", "encadrant", "rptx", "ncp", "get"
$A = import-csv -Path "$env:USERPROFILE\Desktop\xls\essai ve 15-05.csv" -Delimiter ";" -Header $header
# On sélectionne uniquement les lignes commençant par AK ou BF
$planches = $A | Where-Object planche -Match "^AK*|^BF*"
# Pour chaque opération
ForEach ($operation in $planches){
# Operation
$ope = $($operation.planche).Split(" ")[1]
#$ope
# ZEP/Groupement
#CCTT 8948 "ZEP DJ20948" (702+712+714+720+722+724+726+728)
$zep = $($operation.zep).Split(" ")[1]
#$zep
# Debut
$dd = $($operation.d_deb)
$y = $($dd.Split("/")[2])
$m = $($dd.Split("/")[1])
$d = $($dd.Split("/")[0])
$dd = "$($y)$($m)$($d)"
$hd = $($operation.h_deb).Replace(":", "")
$debut = "$($dd)$($hd)"
#$debut
# Fin
$df = $($operation.d_fin)
$y = $($df.Split("/")[2])
$m = $($df.Split("/")[1])
$d = $($df.Split("/")[0])
$df = "$($y)$($m)$($d)"
$hf = $($operation.h_fin).Replace(":", "")
$fin = "$($df)$($hf)"
#$fin
# Voie
$voie = ""
# Rptx
$rptx = $($operation.rptx).Split(":")[1]
#$rptx
# N° CP
$cp = $($operation.ncp)
#$cp
# Tel
$tel = "0000000000"
#$tel
# Terminaison
$term = "||||||||||||||||||||||||||"
$ligne = "$($ope)|1|$($zep)|$($voie)|$($debut)|$($fin)|$($rptx)|$($cp)|$($tel)$term"
Write-host $ligne
# Chaque opération est écrite dans le fichier MGPT_<date-du-jour>.dat
echo $ligne >> $env:USERPROFILE/Desktop/MGPT_$dd.dat
}