Solved

Powershell append hostname and timestamp to txt output

Posted on 2016-08-03
1
27 Views
Last Modified: 2016-08-03
get-winevent -FilterHashTable @{logname="Application"; id="1001"}| ?{$_.providername –match "wininit"} | fl timecreated, message | out-file C:\temp\logs\+$env:computername+$(get-date -f dd-MM-yyyy)+_CHKDSKResults.txt

Open in new window


I would like to run this script on multiple computers in my office and output the results as HOSTNAME_TIME_CHKDSKResults.txt, but the script above outputs as +HOSTNAME+TIME+_CHKDSKResults.txt. What do I need to do to eliminate the "+" from the output filename?

Bonus points: How to I output this file to \\fileserver\c$\logs instead of C:\temp\logs?
0
Comment
Question by:DataDudes
1 Comment
 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
ID: 41740823
get-winevent -FilterHashTable @{logname="Application"; id="1001"}| ?{$_.providername –match "wininit"} | fl timecreated, message | out-file "C:\temp\logs\${env:computername}_$(get-date -f dd-MM-yyyy)_CHKDSKResults.txt"

Open in new window


And to use an actual '$' character in an regular string, you need to escape it with a backtick: `
get-winevent -FilterHashTable @{logname="Application"; id="1001"}| ?{$_.providername –match "wininit"} | fl timecreated, message | out-file "\\fileserver\c`$\logs\${env:computername}_$(get-date -f dd-MM-yyyy)_CHKDSKResults.txt"

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
A procedure for exporting installed hotfix details of remote computers using powershell
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now