Hello,
I am currently on a project that involves testing the connectivity of posts in a company by sending a ping request.
More precisely, from a POSTES.TXT file containing all the information, the script must receive as argument the name of a room to be tested and the number of tests to be carried out. It then generates a time-stamped text file containing the resulting information. Knowing that if all rooms are tested, the script receives the argument ALL instead of the name of the room. We can use the names and rooms we want but the structure of the file is as follows:
(Room, list of the post of the room [, room, list of the positions of the room, …]).
(Examples: “Script ALL 2” allows to test all the rooms, so ALL the posts, 2 times, or “Script Bât01-Eta00-B01 1” allows to test ONLY the posts present in the room Bât01-Eta00- B01, 1 time)
Here is the POSTES.TXT file:
Salle Bât01-Eta00-B01 172.16.100.20 172.16.100.21 Salle Bât01-Eta01-B11 172.16.100.22 Salle Bât02-Eta00-B01 172.16.100.23 172.16.100.24
Here is what I realized:
Param( [Parameter(Mandatory=$True)] [string]$testSalle,[Parameter(Mandatory=$True)]
[int]$test
)#Création des variables
$date = Get-Date -Format “yyyyMMdd-HHmmss”
$Salle = Get-Content -Path C:\users\louni\Desktop\POSTES.txt | Select-String -Pattern “salle”
$nomSalle = $Salle -replace “salle”,“”
$nomPoste = Get-Content -Path C:\Users\louni\Desktop\POSTES.txt | Select-String -Pattern “salle” -NotMatch
$ping = ping -n “$test” $nomPoste#Si $testSalle = ALL alors ping $nomPoste n fois sinon fait le reste
#Séparation des postes par salles
ForEach(
$element in get-content -path C:\users\louni\Desktop\POSTES.txt )
{
# If $testSalle is present in $element ??? Then retrieve the following lines and put it in -> $namePoste
# Ping $nomPoste as soon as you cross the word salle stop itping -n 1 $nomPoste | Out-File -FilePath C:\users\louni\Desktop\"$date"-"$testSalle".txt -Append }</blockquote>
As you can see the most complex is the separation of posts by rooms and I blocked on … I do not necessarily try the answer but a track of response will be very appreciable :))
For more, I also encountered another error that I did not have: the variable $ namePost contains the name of all the posts but when I run ping $ namePost I get: Invalid parameter 172.16.10.20, of course, the Ping command 172.16.10.20 out of the script works.
I practice powershell for a very short time, I really appreciate your help anyway.
Thanks you,ps : i’m french sorry for bad english.