Link to home
Create AccountLog in
Powershell

Powershell

--

Questions

--

Followers

Top Experts

Avatar of jonathanbyers
jonathanbyers🇺🇸

Get-WinEvent Powershell Export To txt File
I want to output the Message column from the latest event log in the Microsoft-Windows-Backup event log.  I see the log when running Get-WinEvent Microsoft-Windows-Backup but don't know how to output ONLY the latest message to a text file.

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of NavdeepNavdeep🇸🇬

Hi
Try this

get-winevent microsoft-windows-backup | Select-Object Messages -First 100

Avatar of jonathanbyersjonathanbyers🇺🇸

ASKER

Nope.  I have

get-winevent Microsoft-Windows-Backup -MaxEvents 1

which returns the last event, but I'm trying to get each column into its own text file so a monitoring application can check each output for criteria.

Avatar of FDiskWizardFDiskWizard🇺🇸

That could be a problem I think. On my workstation for example I ran:
Get-WinEvent Microsoft-Windows-Backup

I got 3 entries (from a while back):
2:35:53 PM  Completed
2:35:53 PM  Cancelled
2:31:29 PM  Started

So if you just view the last one, it just shows it finished, but not the outcome.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of jonathanbyersjonathanbyers🇺🇸

ASKER

What OS are you running.  I am testing on Windows 7 x64 and Windows 2008 R2.  Both have the same output.
Output.jpg

Avatar of FDiskWizardFDiskWizard🇺🇸

Windows 7. I was just pasting the basic info.

Yours looks about the same, but it is cutting off the Completed, Failed, Started part...
I would think you would have to look for the success/failed/cancelled parts. Cancelled could be by user, or say for instance the backup device dies.

From mine:

Id Message
-- -------
14 The backup operation has completed.
 8 The backup operation was canceled.
 1 The backup operation has started.

Avatar of NavdeepNavdeep🇸🇬

Hi,

I ran the same command which i gave you and following are the results
 User generated image
you can then pipe the results to csv file using Export-CSV -noTypeInformation

Alternatively you can use the following code however you need to add where-object to select specified results for example show event from 12/01/2012 14:00

Get-EventLog Application | %{write-host $_.Message}

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of jonathanbyersjonathanbyers🇺🇸

ASKER

OK Get-WinEvent Microsoft-Windows-Backup | %{write-host $_.Message} is working!, but is there anyway to limit it to only display events from the current day?

ASKER CERTIFIED SOLUTION
Avatar of jonathanbyersjonathanbyers🇺🇸

ASKER

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of jonathanbyersjonathanbyers🇺🇸

ASKER

This returns the message field for the current day only.
Powershell

Powershell

--

Questions

--

Followers

Top Experts

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.