Solved

Powershell append hostname and timestamp to txt output

Posted on 2016-08-03
1
91 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 85

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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

695 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