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.

mfinni
  • 36,144
  • 4
  • 53
  • 86

1 Answers1

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.
squillman
  • 37,883
  • 12
  • 92
  • 146