Member_2_6492660_1
asked on
PowerShell Script Help needed
I have a PowerShell script that requires two inputs
I have it working sort of just need some fine tuning from an expert.
I am passing the Event Id error number and then selecting which event log system or application
When the script presents the results I am returned to the beginning of the script
My problem is it does not go back to the beginning it goes to the second question
How can I incorporate the Read-Host and the MainMenu section?
I need to be able to enter the Event ID Error again
Here is my script
I have gathered different code from searches I have found to get this complete
I hope I am not to far off
Feel free to modify this
Thanks in advance
Tom
I have it working sort of just need some fine tuning from an expert.
I am passing the Event Id error number and then selecting which event log system or application
When the script presents the results I am returned to the beginning of the script
My problem is it does not go back to the beginning it goes to the second question
How can I incorporate the Read-Host and the MainMenu section?
I need to be able to enter the Event ID Error again
Here is my script
Clear-Host
$in = Read-host “Enter the Event Error”
function mainMenu()
{
Clear-Host;
Write-Host "====================";
Write-Host "= Select Event Log =";
Write-Host "====================";
Write-Host "1. Press '1' for System Log";
Write-Host "2. Press '2' for Application Log";
}
function returnMenu($option)
{
Clear-Host;
Get-WinEvent -FilterHashtable @{ LogName = "$ev"; id = $in} -maxevents 1 | FL *
Write-Host "Press any key to return to the main menu.";
$host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown");
}
do
{
mainMenu;
$input = Read-Host "Enter a number for an option or type `"quit`" to finish."
switch ($input)
{
"1"
{
$ev = "System";
returnMenu $input;
}
"2"
{
$ev = "Application";
returnMenu $input;
}
"quit"
{
# nothing
}
default
{
Clear-Host;
Write-Host "Invalid input. Please enter a valid option. Press any key to continue.";
$host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown");
}
}
} until ($input -eq "quit");
Clear-Host;
I have gathered different code from searches I have found to get this complete
I hope I am not to far off
Feel free to modify this
Thanks in advance
Tom
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help
ASKER
Thanks
I had to change this line to get it to work
Get-WinEvent -LogName $ev | Where-Object {$_.Id -eq $id} | fl
to
Get-WinEvent -FilterHashtable @{ LogName = "$ev"; id = $in} -maxevents 1 | FL *
Now it works as I need.
Thanks again