Link to home
Start Free TrialLog in
Avatar of bbimis
bbimis

asked on

switch statement either powershell or bat file

how would it take and check the current date say for example monday and then do the following
if monday check directory friday
if tuesday check monday
if weds check tuesday
if thurs check weds
if friday check thurs

?
basically I need to be able to check for files in a directory for the previous day.  Thanks!
Avatar of NVIT
NVIT
Flag of United States of America image

If you can use  yesterday in format YYYYMMDD, then...

With a .bat or .cmd file, you can use something like...
- Yesterdays date in yyyymmdd format

Revise it, removing the PAUSE line.

This returns yesterday in format YYYYMMDD:
for /f "tokens=1-3" %a in ('call yesterday-yyyymmdd.cmd') do echo %c

20150802

Open in new window

SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bill Prew
Bill Prew

@NVIT,

A slight change of handle I see...

~bp
Avatar of bbimis

ASKER

let me ask you as i'm totally new to powershell here is what i'm trying to acheive.
basically i want to test a directory on a remote system with maybe test-path ?
i can't figure out how to pass it the credientials because normally i would use like get-credientals and then -computername $compname -credientials $creds

so to clarify i want to take and test to see if the files are in the previous days folder
and if so return a true or false and then copy them to another computer which i have the drive networked on my local computer that is running the script.

Any help would be great!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So you wanted Powershell, not DOS batch?

~bp
@BP,

Hi Bill.

Yes. With the hope that it would be easier to remember... and type.
NVIT,

I like it!

~bp
Avatar of bbimis

ASKER

so how do i pass the test-path command to a remote computer or is there something else to use?
test-path c:\somefolderonremote  -computername $compname -credientals $creds

Open in new window


i know this would work for a wmi pass but do i need to pipe it somehow ?
You either need to use a UNC path, or if you have PS Remoting set up you can use local paths (since you would be running the command on the remote server).
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bbimis

ASKER

thanks got it!
Avatar of bbimis

ASKER

have a question is there a way to basically go through a whole directory for example
\\share\tranferme

and then look inside the directory(s) and see if you have a modification of the previous day
and then copy those files?

so if i have files in there
file1.txt 8/3/2015
file2.txt 8/5/2015

i would only want to pull over 8/5

Thanks for the help!