Solved

Powershell append hostname and timestamp to txt output

Posted on 2016-08-03
1
69 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:OAC Technology
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 84

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This article will help you understand what HashTables are and how to use them in PowerShell.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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