Question
compter ligne d'un fichier
- marlone
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
Réduire
Plus d'informations
- Messages : 1
- Remerciements reçus 0
il y a 11 ans 4 mois #18293
par marlone
compter ligne d'un fichier a été créé par marlone
salut j'ai le fichier suivant :
====================================================
Status Name DisplayName
----
Running AdobeARMservice Adobe Acrobat Update Service
Running AMD External Ev... AMD External Events Utility
Running AMD FUEL Service AMD FUEL Service
Running Appinfo Informations d’application
Running Apple Mobile De... Apple Mobile Device
Running AudioEndpointBu... Générateur de points de
Running AudioSrv Audio Windows
Running avast! Antivirus avast! Antivirus
Running WdiServiceHost Service hôte WDIServiceHost
Running WinDefend Windows Defender
Running Winmgmt Infrastructure de gestion
Running Wlansvc Service de configuration
Running wlidsvc Windows Live ID Sign-in A
Running WMPNetworkSvc Service Partage réseau du
Running wscsvc Centre de sécurité
Running WSearch Windows Search
Running wuauserv Windows Update
Status Name DisplayName
----
Stopped W32Time Temps Windows
Stopped WatAdminSvc Service Windows Activation
Stopped wbengine Service de moteur de sauvegarde
Stopped WbioSrvc Service de biométrie Windows
Stopped wcncsvc Windows Connect Now - Registre Stopped WcsPlugInService Système de couleurs Windows
Stopped Wecsvc Collecteur d’événements de
Stopped WerSvc Service de rapport d’erreurs
Stopped WinHttpAutoProx... Service de découverte
Stopped wlcrasvc Windows Live Mesh remote
Stopped WPCSvc Parental Controls
Stopped wudfsvc Windows Driver Foundation -
Stopped WwanSvc Service de configuration
===========================================================
et je souhaite seulement compter les lignes qui commencent par \"Stopped\" et \"Running\". comment faire svp ??
Merci !
====================================================
Status Name DisplayName
----
Running AdobeARMservice Adobe Acrobat Update Service
Running AMD External Ev... AMD External Events Utility
Running AMD FUEL Service AMD FUEL Service
Running Appinfo Informations d’application
Running Apple Mobile De... Apple Mobile Device
Running AudioEndpointBu... Générateur de points de
Running AudioSrv Audio Windows
Running avast! Antivirus avast! Antivirus
Running WdiServiceHost Service hôte WDIServiceHost
Running WinDefend Windows Defender
Running Winmgmt Infrastructure de gestion
Running Wlansvc Service de configuration
Running wlidsvc Windows Live ID Sign-in A
Running WMPNetworkSvc Service Partage réseau du
Running wscsvc Centre de sécurité
Running WSearch Windows Search
Running wuauserv Windows Update
Status Name DisplayName
----
Stopped W32Time Temps Windows
Stopped WatAdminSvc Service Windows Activation
Stopped wbengine Service de moteur de sauvegarde
Stopped WbioSrvc Service de biométrie Windows
Stopped wcncsvc Windows Connect Now - Registre Stopped WcsPlugInService Système de couleurs Windows
Stopped Wecsvc Collecteur d’événements de
Stopped WerSvc Service de rapport d’erreurs
Stopped WinHttpAutoProx... Service de découverte
Stopped wlcrasvc Windows Live Mesh remote
Stopped WPCSvc Parental Controls
Stopped wudfsvc Windows Driver Foundation -
Stopped WwanSvc Service de configuration
===========================================================
et je souhaite seulement compter les lignes qui commencent par \"Stopped\" et \"Running\". comment faire svp ??
Merci !
Connexion ou Créer un compte pour participer à la conversation.
- szwec
- Hors Ligne
- Nouveau membre
-
Réduire
Plus d'informations
- Messages : 11
- Remerciements reçus 0
il y a 11 ans 4 mois #18326
par szwec
Réponse de szwec sur le sujet Re:compter ligne d'un fichier
voila qui peut peut-être t'aider, reste à trouver comment écrire les n° de ligne dans le fichier au lieur de l'écrire ds la console 
$run = Get-Service | Where-Object {$_.Status -eq \"Running\"} | Out-File C:\file.txt -Append
Start-Sleep -Seconds 3
$stop = Get-Service | Where-Object {$_.Status -eq \"Stopped\"} | Out-File C:\file.txt -Append
Start-Sleep -Seconds 3
$EmplacementFichier = \"C:\file.txt\"
$MonFichier = get-content $EmplacementFichier
$i=0
foreach ($ligne in $MonFichier){
Write-host $i $ligne
$i++
}
$run = Get-Service | Where-Object {$_.Status -eq \"Running\"} | Out-File C:\file.txt -Append
Start-Sleep -Seconds 3
$stop = Get-Service | Where-Object {$_.Status -eq \"Stopped\"} | Out-File C:\file.txt -Append
Start-Sleep -Seconds 3
$EmplacementFichier = \"C:\file.txt\"
$MonFichier = get-content $EmplacementFichier
$i=0
foreach ($ligne in $MonFichier){
Write-host $i $ligne
$i++
}
Connexion ou Créer un compte pour participer à la conversation.
- Philippe
- Hors Ligne
- Modérateur
-
Réduire
Plus d'informations
- Messages : 1778
- Remerciements reçus 21
il y a 11 ans 4 mois #18331
par Philippe
Réponse de Philippe sur le sujet Re:compter ligne d'un fichier
bonjour marlone et dtrump
j'ai repris ta reponse dtrump et j'en ai sortie trois techniques possibles :
comptage direct des services :
[code:1]
$(Get-Service | Where-Object {$_.Status -eq \"Running\"}).count
$(Get-Service | Where-Object {$_.Status -eq \"Stopped\"}).count
[/code:1]
comptage via un fichier texte (donner en exemple par marlone) :
[code:1]
Get-Service | Out-File C:\file.txt
$(get-content C:\file.txt | Where-Object {$_ -like \"Running*\"}).count
$(get-content C:\file.txt | Where-Object {$_ -like \"Stopped*\"}).count
[/code:1]
comptage via un fichier csv :
[code:1]
Get-Service | Export-Csv C:\file.csv
$(Import-Csv C:\file.csv | Where-Object {$_.Status -eq \"Running\"}).count
$(Import-Csv C:\file.csv | Where-Object {$_.Status -eq \"Stopped\"}).count
[/code:1]
j'ai repris ta reponse dtrump et j'en ai sortie trois techniques possibles :
comptage direct des services :
[code:1]
$(Get-Service | Where-Object {$_.Status -eq \"Running\"}).count
$(Get-Service | Where-Object {$_.Status -eq \"Stopped\"}).count
[/code:1]
comptage via un fichier texte (donner en exemple par marlone) :
[code:1]
Get-Service | Out-File C:\file.txt
$(get-content C:\file.txt | Where-Object {$_ -like \"Running*\"}).count
$(get-content C:\file.txt | Where-Object {$_ -like \"Stopped*\"}).count
[/code:1]
comptage via un fichier csv :
[code:1]
Get-Service | Export-Csv C:\file.csv
$(Import-Csv C:\file.csv | Where-Object {$_.Status -eq \"Running\"}).count
$(Import-Csv C:\file.csv | Where-Object {$_.Status -eq \"Stopped\"}).count
[/code:1]
Connexion ou Créer un compte pour participer à la conversation.
- Laurent Dardenne
- Hors Ligne
- Modérateur
-
Réduire
Plus d'informations
- Messages : 6311
- Remerciements reçus 68
il y a 11 ans 4 mois #18333
par Laurent Dardenne
Tutoriels PowerShell
Réponse de Laurent Dardenne sur le sujet Re:compter ligne d'un fichier
Salut,
ou le fameux Group-Object :
[code:1]
#Requiert ps v3,cf. opérateur -In
Get-Service|
Where-Object {$_.Status -in 'Running','Stopped'}|
Group-Object -property status
[/code:1]
On peut aussi utiliser le paramètre -AsHashTable.
ou le fameux Group-Object :
[code:1]
#Requiert ps v3,cf. opérateur -In
Get-Service|
Where-Object {$_.Status -in 'Running','Stopped'}|
Group-Object -property status
[/code:1]
On peut aussi utiliser le paramètre -AsHashTable.
Tutoriels PowerShell
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.044 secondes
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Entraide pour les débutants
- compter ligne d'un fichier