Discussion Locked

Name a txt file with output of command

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hello,
I am trying to name a txt file with the output of this command:

wmic csproduct get identifyingnumber >> c:\users\%username%\desktop\(S.T.#Here).txt

which displays the Service tag number of machines and writes the service tag number into this text file. I have been beating my head in on this one, please help me.

2 replies

by charliespencer

Troubleshoot it in steps:

Does the command itself work if you leave out the redirect and let it go to the screen?

I could be wrong or out of date, but I thought only a single 'greater than' was required to redirect the output to a file.

Also, the 'hash mark' may be a reserved character; have you tried leaving it out? It's probably a good practice to leave the parenthesis (and all punctuation marks) out of file name you expect to perform additional processing on.

by nicknielsen

If you want the script to insert the output from the csproduct utility into the filename position, try this command:

wmic csproduct get identifyingnumber >> c:\users\%username%\desktop\%%identifyingnumber.txt

I'm a little rusty, but something close to this should work.

This discussion is closed to new replies.