Link to home
Start Free TrialLog in
Avatar of Pavan Joshi
Pavan Joshi

asked on

PowerShell; Get specific Line from a .log file

Hello,

From the below command I got the output what I require, but I need to do this for multiple servers and also I need the server name in the output.

Get-Content \\AP0000345\F$\maint.log | Select-String 'Application Server Maintenance'

Current Output:

PS C:\Temp\MaintStage1> Get-Content \\APISEM501\F$\maint.log | Select-String 'Maintenance is Completed'

Maintenance is completed and the Server will re-boot now !...

Below we see only the text "Maintenance is completed and the Server will re-boot now !..." with out a server name, however if I run this for multiple servers I must have the server name to validate if the maintenance has been completed on that server or not.

Please help. !!!!
Avatar of Qlemo
Qlemo
Flag of Germany image

The log file is located on each of those servers on F:? And I'll assume there is only a single line with that text.
foreach ($server in 'AP0000345', 'AP1234567', 'AP7654321')
{ "$serverˋ: " + (Get-Content "\\$server\F$\maint.log" | Select-String 'Application Server Maintenance') }

Open in new window

Avatar of Pavan Joshi
Pavan Joshi

ASKER

PS C:\Temp> & '.\Test - Copy.ps1'
AS000000213PApplication Server maintenance is completed !
USNBKM501

Above is what I am getting and its not what I want.

All I require is Server name (Space) Result and the same for all servers

Example:

AS000000213P - Application Server maintenance is completed !
AS000000214P - Application Server maintenance is completed !

Please help. :(
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It worked Qlemo :) Thanks a lot.
It worked Qlemo :) Thanks a lot.
Hello, Instead of below script to put so many servers in one line,

foreach ($server in 'AP0000345', 'AP1234567', 'AP7654321')
{ $server + ": - " + (Get-Content "\\$server\F$\Int.log" | Select-String 'Application Server Maintenance') }

Cant we have it on a text file as content?
Of course, all you need to do is replace the first line with
foreach ($server in Get-Content C:\Temp\EE\Serverlist.txt)

Open in new window

using the correct path and filename
Thanks Qlemo :)