Solved

How to include the date in the DSGET command output file

Posted on 2009-05-12
7
444 Views
Last Modified: 2013-12-24
Hi Experts,

How could I include the date information (mmddyyy: i.e 05242009) in the output file I create with my script that already runs a DSGET to list all members in an AD group?

Thanks in advance.

0
Comment
Question by:HUSATech
  • 4
  • 3
7 Comments
 
LVL 4

Expert Comment

by:delyan_valchev
ID: 24368760
Simple version if you have the date command output formatted as dd/mm/yyyy or dd.mm.yyyy. If date /t outputs in mm/dd/yyyy or mm.dd.yyyy you can switch the places of Day and Month variables. then you can use %Day%Month%Year in the dsget's output.
Hope it helps
for /F "tokens=1-4 delims=/. " %%i in ('date /t') do (

     set Day=%%i

     set Month=%%j

     set Year=%%k

  ) 

Open in new window

0
 
LVL 4

Expert Comment

by:delyan_valchev
ID: 24368815
Here is international-independent version which runs on 2003/XP and up. You can get the time as well.

FOR /F "skip=2 tokens=2-7 delims=," %%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:csv') DO (

	SET Day=%%A

	SET Hour=%%B

	SET Minute=%%C

	SET Month=%%D

	SET Second=%%A

	SET Year=%%F

)

Open in new window

0
 

Author Comment

by:HUSATech
ID: 24369116
Hey thanks a lot for the quick answer, but let me ask you this: should I embed this in my batch file where I run the dsget? How should I use it?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 4

Accepted Solution

by:
delyan_valchev earned 50 total points
ID: 24369699
Just put it in the beginning of the batch file like the example below. Based on your question, I assume you have US regional settings (mm/dd/yyyy) so I edited a bit the first version.
Hope it helps!
@echo off

for /F "tokens=1-4 delims=/. " %%i in ('date /t') do (

     set Month=%%i

     set Day=%%j

     set Year=%%k

  ) 

set FileDate=%Month%%Day%%Year%
 

dsquery user -name SomeUser | dsget user -memberof > SomeUserMembership_%FileDate%.txt

Open in new window

0
 

Author Comment

by:HUSATech
ID: 24369884
Great, worked as expected. Thanks a lot.
0
 

Author Closing Comment

by:HUSATech
ID: 31580708
Thanks again, quick and easy to implement.
0
 
LVL 4

Expert Comment

by:delyan_valchev
ID: 24380217
The "international" version has a typo. Here is the correct one:
FOR /F "skip=2 tokens=2-7 delims=," %%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:csv') DO (

        SET Day=%%A

        SET Hour=%%B

        SET Minute=%%C

        SET Month=%%D

        SET Second=%%E

        SET Year=%%F

)

Open in new window

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
USB backup batch file help needed. 6 65
For loop to add numbers 3 23
Best RAID for a BDD Oracle 4 18
Slow SQL query 12 21
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

20 Experts available now in Live!

Get 1:1 Help Now