Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to include the date in the DSGET command output file

Posted on 2009-05-12
7
Medium Priority
?
452 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

715 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