Solved

Powershell append hostname and timestamp to txt output

Posted on 2016-08-03
1
35 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
1 Comment
 
LVL 83

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

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 explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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