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. !!!!
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. !!!!
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. :(
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It worked Qlemo :) Thanks a lot.
ASKER
It worked Qlemo :) Thanks a lot.
ASKER
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?
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)
using the correct path and filename
ASKER
Thanks Qlemo :)
Open in new window