Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,11 @@ private void ProcessListLog()
||
(wildLogPattern.IsMatch(logName)))
{
EventLogConfiguration logObj;
EventLogInformation logInfoObj;
try
{
EventLogConfiguration logObj = new(logName, eventLogSession);
logObj = new EventLogConfiguration(logName, eventLogSession);

//
// Skip direct channels matching the wildcard unless -Force is present.
Expand All @@ -533,19 +535,25 @@ private void ProcessListLog()
continue;
}

EventLogInformation logInfoObj = eventLogSession.GetLogInformation(logName, PathType.LogName);

PSObject outputObj = new(logObj);
bMatchFound = true;
logInfoObj = eventLogSession.GetLogInformation(logName, PathType.LogName);
}
catch (UnauthorizedAccessException exc)
{

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certain log types are skipped so this cannot be moved to an earlier point.

string exceptionMsg = string.Format(CultureInfo.InvariantCulture, GetEventResources.LogInfoNoAccess, logName);
var newExc = new UnauthorizedAccessException(exceptionMsg, exc);

outputObj.Properties.Add(new PSNoteProperty("FileSize", logInfoObj.FileSize));
outputObj.Properties.Add(new PSNoteProperty("IsLogFull", logInfoObj.IsLogFull));
outputObj.Properties.Add(new PSNoteProperty("LastAccessTime", logInfoObj.LastAccessTime));
outputObj.Properties.Add(new PSNoteProperty("LastWriteTime", logInfoObj.LastWriteTime));
outputObj.Properties.Add(new PSNoteProperty("OldestRecordNumber", logInfoObj.OldestRecordNumber));
outputObj.Properties.Add(new PSNoteProperty("RecordCount", logInfoObj.RecordCount));
string recommendationMsg = GetEventResources.SuggestElevation;
var eRecord = new ErrorRecord(newExc, "LogInfoNoAccess", ErrorCategory.PermissionDenied, logName)
{
ErrorDetails = new ErrorDetails(string.Empty)
{
RecommendedAction = recommendationMsg
}
};

WriteObject(outputObj);
bMatchFound = true;
WriteError(eRecord);
continue;
}
catch (Exception exc)
{
Expand All @@ -556,6 +564,16 @@ private void ProcessListLog()
WriteError(new ErrorRecord(outerExc, "LogInfoUnavailable", ErrorCategory.NotSpecified, null));
continue;
}

PSObject outputObj = new(logObj);
outputObj.Properties.Add(new PSNoteProperty("FileSize", logInfoObj.FileSize));
outputObj.Properties.Add(new PSNoteProperty("IsLogFull", logInfoObj.IsLogFull));
outputObj.Properties.Add(new PSNoteProperty("LastAccessTime", logInfoObj.LastAccessTime));
outputObj.Properties.Add(new PSNoteProperty("LastWriteTime", logInfoObj.LastWriteTime));
outputObj.Properties.Add(new PSNoteProperty("OldestRecordNumber", logInfoObj.OldestRecordNumber));
outputObj.Properties.Add(new PSNoteProperty("RecordCount", logInfoObj.RecordCount));

WriteObject(outputObj);
Comment on lines +574 to +576
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ The defined template is following:
<data name="LogInfoUnavailable" xml:space="preserve">
<value>To access the '{0}' log start PowerShell with elevated user rights. Error: {1}</value>
</data>
<data name="LogInfoNoAccess" xml:space="preserve">
<value>Access denied for log: '{0}'.</value>
</data>
<data name="SuggestElevation" xml:space="preserve">
<value>Launch PowerShell with elevated user rights.</value>
Comment on lines +258 to +262

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But what is the text file used for?

</data>
<data name="NoEventMessage" xml:space="preserve">
<value>Cannot retrieve event message text.</value>
</data>
Expand Down
Loading