Question
Formater une liste en tableau
- Frigoult
- Auteur du sujet
- Hors Ligne
- Nouveau membre
- Messages : 8
- Remerciements reçus 0
Je souhaitais formater une liste en tableau.
La solution proposée par Laurent me donnait ceci.
\"Name\",\"Node\",\"Version\",\"User\"
\"HD2\",\"Puls4790\",\"DY03USS\",\"micsyl\"
\"MD2\",\"houenez\",\"DY03URJ\",\"volmar\"
\"MD2\",\"houenez\",\"DY03URJ\",\"volmar\"
\"ST1\",\"illie\",\"R1\",\"masrol\"
J'ai étoffé le programme et j’obtiens maintenant ceci.
@{Name=HD2; Node=Puls479; User=micsyl; Version=DY03USS; NbLicModTot=1; NbLicModInUse=1; Time=07/06/2011 09:03:43}
@{Name=KT1; Node=; User=; Version=R1; NbLicModTot=1; NbLicModInUse=0; Time=07/06/2011 09:03:43}
@{Name=LicensePower/iFOR Test Product; Node=; User=; Version=1.0; NbLicModTot=20000; NbLicModInUse=0; Time=07/06/2011 09:03:43}
@{Name=MD2; Node=Trevarec; User=quecha; Version=DY03URJ; NbLicModTot=2; NbLicModInUse=2; Time=07/06/2011 09:03:43}
@{Name=MD2; Node=houenez; User=volmar; Version=DY03URJ; NbLicModTot=2; NbLicModInUse=2; Time=07/06/2011 09:03:43}
@{Name=ST1; Node=illie:; User=masrol; Version=R1; NbLicModTot=1; NbLicModInUse=1; Time=07/06/2011 09:03:43}
@{Name=TC-qcheckerV5; Node=; User=; Version=1; NbLicModTot=1; NbLicModInUse=0; Time=07/06/2011 09:03:43}
Que s'est il passé?
Voici mon programme:
[code:1]$FolderDest = \"C:\Documents and Settings\frichr\Personnel\My Dropbox\Script-PowerShell\LUM\"
$FileResult = \"Result\"
$FileLogLUM = \"C:\Documents and Settings\frichr\Personnel\My Dropbox\Script-PowerShell\LUM\listlum.txt\"
$NbLicModEC = 0
$NbLigneSep = 2
$DateLog = Get-Date -DisplayHint Date -Format \"yyMMdd\"
## commande d'intérogation du serveur LUM avec redirection vers un fichier texte
$CdeLum =\"c:\IFOR\WIN\BIN\i4blt -s -lc > $FileLogLUM\"
## !intérogation du LUM
invoke-expression $cdelum
$ProductTemp= New-Object psobject -property @{
\"Name\"=$null;
\"Version\"=$null;
\"NbLicModTot\"=$null;
\"NbLicModInUse\"=$null;
\"User\"=$null;
\"Node\"=$null
}
$Liste=gc $FileLogLUM|
Foreach {
Write-Debug \"Ligne courante : $_ \"
switch -regex ($_)
{
#Code licence (MD2, ZAD etc..)
'Product Name:«»(?<Name>.*)' {$ProductTemp.Name=$matches.Name.Trim()}
#N° de licence (JE24DF3Z)
'Product Version:«»(?<Version>.*)' {$ProductTemp.Version=$matches.Version.Trim()}
#Nombre de licence (concurent user) et du nombre d'utilisateurs en cours de la licence
'^\s*(?<NbLicModTot>\d+)\s+(?<NbLicModInUse>\d+)' {$productTemp.NbLicModTot=[int]$matches.NbLicModTot;
$NbLicModEC=$productTemp.NbLicModTot;
$productTemp.NbLicModInUse=[int]$matches.NbLicModInUse}
#Login AD de l'utilisateur de la licence
'User:«»(?<User>.*)' {$ProductTemp.User=$matches.User.Trim();$NbLicModEC=$NbLicModEC-1}
#Nom de la station
'Node:«»(?<Node>.*)' {$ProductTemp.Node=$matches.Node.Trim();if($NbLicModEC -gt 0){
$Product= New-Object psobject -property @{
\"Time\"=Get-Date -displayhint time
\"Name\"=$ProductTemp.Name;
\"Version\"=$ProductTemp.Version;
\"NbLicModTot\"=$productTemp.NbLicModTot;
\"NbLicModInUse\"=$productTemp.NbLicModInUse;
\"User\"=$ProductTemp.User;
\"Node\"=$ProductTemp.Node
}
;$product
}}
## Séparateur, passage a la license suivante
'={75}' {if (-not($NbLigneSep -eq 0)){$NbLigneSep = $NbLigneSep -1} else {
$Product= New-Object psobject -property @{
\"Time\"=Get-Date -displayhint time
\"Name\"=$ProductTemp.Name;
\"Version\"=$ProductTemp.Version;
\"NbLicModTot\"=$productTemp.NbLicModTot;
\"NbLicModInUse\"=$productTemp.NbLicModInUse;
\"User\"=$ProductTemp.User;
\"Node\"=$ProductTemp.Node
}
;$product;
$ProductTemp.Name=$null;
$ProductTemp.Version=$null
$ProductTemp.NbLicModTot=$null;
$ProductTemp.NbLicModInUse=$null;
$ProductTemp.User=$null;
$Producttemp.Node=$null
}}
}
}
$FileResult = $FolderDest + \"\\" + $FileResult + $DateLog + \".txt\"
## $Liste | export-csv $FileResult -NoTypeInformation
$Liste | Add-Content -Path $FileResult[/code:1]<br><br>Message édité par: Docserta, à: 7/06/11 09:59
Connexion ou Créer un compte pour participer à la conversation.
- Laurent Dardenne
- Hors Ligne
- Modérateur
- Messages : 6302
- Remerciements reçus 68
Effectivement, qu'est-ce qui se passe ?Que s'est il passé?
N'ayant pas les données pour tester, je pense que l'ajout d'objet personnalisé, via le cmdlet Add-Content, le transforme en une string :
[code:1]
$o=New-Object PSObject -Property @{un=3;deux=2;trois=\"un\"}
$o
$o.ToString()
#ras
\"$o\"
#@{deux=2; un=3; trois=un}
$o -as [string]
#@{deux=2; un=3; trois=un}
[/code:1]
#help Add-content -full
SORTIES
Aucun ou System.String Lorsque vous utilisez le paramètre PassThru, Add-Content génère un objet System.String qui représente le conten
u. Sinon, cette applet de commande ne génère aucune sortie.
Tutoriels PowerShell
Connexion ou Créer un compte pour participer à la conversation.
- Vous êtes ici :
- Accueil
- forum
- PowerShell
- Entraide pour les débutants
- Formater une liste en tableau