Create output file named using date and time???

N

numismatic

I've done this before, but can't recall or find how it's done (it's
been a few years).

I want to run a command (psservice) and redirect output to a file
using the current date and time.

for example:

psservice query ms >> "%UserProfile%\Desktop\msservices - %date%.txt"

I know I've done this before fairly simply. Any ideas?
 
N

numismatic

I've done this before, but can't recall or find how it's done (it's
been a few years).

I want to run a command (psservice) and redirect output to a file
using the current date and time.

for example:

psservice query ms >> "%UserProfile%\Desktop\msservices - %date%.txt"

I know I've done this before fairly simply. Any ideas?

or:

psservice query ms >> "%UserProfile%\Desktop\msservices - "%date
%".txt"

returns a file named "msservices - Tue"...no .txt or the full date.
 
P

Pegasus \(MVP\)

numismatic said:
I've done this before, but can't recall or find how it's done (it's
been a few years).

I want to run a command (psservice) and redirect output to a file
using the current date and time.

for example:

psservice query ms >> "%UserProfile%\Desktop\msservices - %date%.txt"

I know I've done this before fairly simply. Any ideas?

The variable %date% resolves to something like
Tue 05/06/2008
which contains forward slashes. None of the MS operating
systems ever released allowed any kind of slash in its file names.
You must get rid of them, eg. like so:
@echo off
set MyDate=%date:/=-%
psservice query ms >> "%UserProfile%\Desktop\msservices - %MyDate%.txt"

I don't run psservice.exe on my machine, hence I cannot tell if
the syntax for this command is correct.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top