Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to include the date in the DSGET command output file

Posted on 2009-05-12
7
Medium Priority
?
454 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 4

Accepted Solution

by:
delyan_valchev earned 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

971 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