Question Lire un fichier ligne par ligne

Plus d'informations
il y a 13 ans 7 mois #12824 par COTTIN
Bonjour,

J'ai un fichier avec une liste de serveur.

J'aimerais lire le fichier ligne par ligne.

Je m'explique.

J'ai un script qui fait un check up de l'hardware des serveur tout les matin.

J'ai un fichier texte qui répertorie tout les nom de serveur. (en exécutant 1 par 1 c'est bon)

Mais j’aimerais que le script s’exécute tout les matin automatiquement.

Donc lecture de la première ligne du fichier --> exécution du script
lecture de la deuxième ligne du serveur --> exécution du script.
etc etc etc

Merci de votre futur aide.

pour vous aider voici mon script :

[code:1]#cr?ation de la form
[system.reflection.assembly]::LoadWithPartialName('System.Windows.Forms')
$form = New-Object Windows.Forms.Form
$textbox= New-Object System.Windows.Forms.textBox
$button_accepter = New-Object System.Windows.Forms.Button

#initialisation des variables
cd \"D:\Script\pageweb\"

$filepath = \"D:\Script\pageweb\"

#### HTML Output Formatting #######

$a = \"<!--mce:0-->\"

######Initialisation du credential#############
$chaine_chiffree = Get-Content D:\Script\pageweb\joind_dom.txt
$cle = Get-Content D:\Script\pageweb\cle.txt

$password = convertTo-SecureString -key $cle -String $chaine_chiffree
$user = \"*********\"

$credential = New-Object -typename System.Management.Automation.PsCredential -ArgumentList $user, $password


$name = Get-Content test.txt ##fichier a lire##

ConvertTo-Html -Head $a -Title \"Hardware Information for $name\" -Body \"<h1> Computer Name : $name </h1>\" > \"$filepath\$name.html\"

# MotherBoard: Win32_BaseBoard # You can Also select Tag,Weight,Width
Get-WmiObject -ComputerName $name Win32_BaseBoard -Credential $credential| Select Name,Manufacturer,Product,SerialNumber,Status | ConvertTo-html -Body \"<H2> MotherBoard Information</H2>\" >> \"$filepath\$name.html\"

# Battery
Get-WmiObject Win32_Battery -ComputerName $name -Credential $credential | Select Caption,Name,DesignVoltage,DeviceID,EstimatedChargeRemaining,EstimatedRunTime | ConvertTo-html -Body \"<H2> Battery Information</H2>\" >> \"$filepath\$name.html\"

# BIOS
Get-WmiObject win32_bios -ComputerName $name -Credential $credential | Select Manufacturer,Name,BIOSVersion,ListOfLanguages,PrimaryBIOS,ReleaseDate,SMBIOSBIOSVersion,SMBIOSMajorVersion,SMBIOSMinorVersion | ConvertTo-html -Body \"<H2> BIOS Information </H2>\" >> \"$filepath\$name.html\"

# CD ROM Drive
Get-WmiObject Win32_CDROMDrive -ComputerName $name -Credential $credential | select Name,Drive,MediaLoaded,MediaType,MfrAssignedRevisionLevel | ConvertTo-html -Body \"<H2> CD ROM Information</H2>\" >> \"$filepath\$name.html\"

# System Info
Get-WmiObject Win32_ComputerSystemProduct -ComputerName $name -Credential $credential | Select Vendor,Version,Name,IdentifyingNumber,UUID | ConvertTo-html -Body \"<H2> System Information </H2>\" >> \"$filepath\$name.html\"

# Hard-Disk
Get-WmiObject win32_diskDrive -ComputerName $name -Credential $credential | select Model,SerialNumber,InterfaceType,Size,Partitions,StatusInfo | ConvertTo-html -Body \"<H2> Harddisk Information </H2>\" >> \"$filepath\$name.html\"

# NetWord Adapters -ComputerName $name
Get-WmiObject win32_networkadapter -ComputerName $name -Credential $credential | Select Name,Manufacturer,Description ,AdapterType,Speed,MACAddress,NetConnectionID | ConvertTo-html -Body \"<H2> Nerwork Card Information</H2>\" >> \"$filepath\$name.html\"

# Memory
Get-WmiObject Win32_PhysicalMemory -ComputerName $name -Credential $credential | select BankLabel,DeviceLocator,Capacity,Manufacturer,PartNumber,SerialNumber,Speed | ConvertTo-html -Body \"<H2> Physical Memory Information</H2>\" >> \"$filepath\$name.html\"

# Processor
Get-WmiObject Win32_Processor -ComputerName $name -Credential $credential | Select Name,Manufacturer,Caption,DeviceID,CurrentClockSpeed,CurrentVoltage,DataWidth,L2CacheSize,L3CacheSize,NumberOfCores,NumberOfLogicalProcessors,Status | ConvertTo-html -Body \"<H2> CPU Information</H2>\" >> \"$filepath\$name.html\"

## System enclosure

Get-WmiObject Win32_SystemEnclosure -ComputerName $name -Credential $credential | Select Tag,AudibleAlarm,ChassisTypes,HeatGeneration,HotSwappable,InstallDate,LockPresent,PoweredOn,PartNumber,SerialNumber | ConvertTo-html -Body \"<H2> System Enclosure Information </H2>\" >> \"$filepath\$name.html\"

## Invoke Expressons

invoke-Expression \"$filepath\$name.html\"
[/code:1]<br><br>Message édité par: tcottin, à: 19/11/12 18:38

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 13 ans 7 mois #12825 par xyz
Réponse de xyz sur le sujet Re:Lire un fichier ligne par ligne
Salut,
[code:1]
help about_For
help about_Foreach
[/code:1]
:)

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 13 ans 7 mois #12836 par SiSMik

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.038 secondes
Propulsé par Kunena