4

Windows CMD shell - any easy way of redirecting the command itself into the output? If I do net localgroup administrators > %computername%-admins.txt, I'd like the output file to contain the net statement as well.

No powershell available to me; pure CMD/COMMAND only.

This is for an audit; the auditors want to see what command generated the output. I'm trying to avoid screenshots or enormous copy-paste from CMD windows.

1 Answer 1

3

Maybe kinda lame, but put the command in a batch file and redirect the output of the batch file to your txt file.

c:\echo net localgroup administrators > net_local_administrators.bat c:\net_local_administrators.bat > %computername%-admins.txt c:\del net_local_administrators.bat 

Contents of %computername%-admins.txt (member names cleansed):

C:\>net localgroup administrators Alias name administrators Comment Administrators have complete and unrestricted access to the computer/domain Members ------------------------------------------------------------------------------- Administrator MYDomain\Domain Admins User1 User2 The command completed successfully. 
5
  • That shows the batch file name, which is not guaranteed to match the contents. This is for an audit; the auditors want to see what command generated the output. I'm trying to avoid screenshots or enormous copy-paste from CMD windows. Commented Oct 30, 2013 at 20:54
  • I get the full command prompt with the command in the .txt file Commented Oct 30, 2013 at 20:57
  • Ooh - nice. Got it. Commented Oct 30, 2013 at 20:59
  • Works for me. Ugly-ish workaround, but I'll take it Commented Oct 30, 2013 at 21:01
  • Gives the auditors something to weed through. Commented Oct 30, 2013 at 21:02

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.