I have a little script to filter out error log for application and system for remote PC in past 7 days.
Write-Host "Creating Error Log of Remote PC ......."
[System.Threading.Thread]::CurrentThread.CurrentCulture = New-Object "System.Globalization.CultureInfo" "en-US"
$date = get-date
$range = $date.adddays(-7)
$pcname = Read-Host -Prompt "Please Enter PC name"
Get-WinEvent -ComputerName $pcname -FilterHashtable @{LogName="system","application"; Level=1,2; starttime=$range} |
Select-Object @{label="PC"; expression={"$pcname"}},LogName,levelDisplayName,ProviderName,ID,TimeCreated,message |
Sort-Object logname |
Format-Table -AutoSize |
Out-File C:\Eventlog.txt -width 214748
C:\Eventlog.txt
When it runs,I will get a prompt to enter PC name, The thing is that when the script finished, powershell prompt will return to
PS c:\windows\system32\windowspowershell\v1.0>
If i want to check the logs on another PC i have to close the current PS window and run my script again.
How can I do a loop that it will show my [Enter PC name] prompt again after the first run finished?