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!
bbimisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITCommented:
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

0
Bill PrewCommented:
This should get the job done.  It determines today's day of the week, and then gets the appropriate prior business day folder.  Should give the concept, let me know questions, or how you need adjusted.

@echo off
setlocal EnableDelayedExpansion

REM Define folder base path
set BaseDir=B:\Base
set DayDir[1]=Friday
set DayDir[2]=Monday
set DayDir[3]=Tuesday
set DayDir[4]=Wednesday
set DayDir[5]=Thursday

REM Get day of week, and then check the prior days folder
call :DayOfWeek DOW
if %DOW% GEQ 1 (
  if %DOW% LEQ 5 (
    echo Check folder: %BaseDir%\!DayDir[%DOW%]!
  )
)

REM Done
exit /b

:DayOfWeek [return-var]
  REM Sunday = 0
  for /f "skip=2 tokens=2 delims=," %%A in ('WMIC Path Win32_LocalTime Get DayOfWeek /Format:csv') do set "%~1=%%A"
  exit /b

Open in new window

~bp
0
Bill PrewCommented:
@NVIT,

A slight change of handle I see...

~bp
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

bbimisAuthor Commented:
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!
0
footechCommented:
I'm not sure what your naming structure is or exactly what the directory check should be.
Here's an example of a switch statement in PowerShell that does different things depending on the dya of the week.

switch ( (Get-Date).DayOfWeek )
{
    "Monday"     { "check Friday"; break }
    "Tuesday"    { "check Monday"; break }
    "Wednesday"  { "check Tuesday"; break }
    "Thursday"   { "check Wednesday"; break }
    "Friday"     { "check Thursday"; break }
}

Open in new window

0
Bill PrewCommented:
So you wanted Powershell, not DOS batch?

~bp
0
NVITCommented:
@BP,

Hi Bill.

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

I like it!

~bp
0
bbimisAuthor Commented:
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 ?
0
footechCommented:
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).
0
oBdACommented:
Try if this works for you:
#requires -Version 3
$SourceShare = "\\SomeServer\SomeShare"
$SourceUser = "SomeDomain\SomeUser"
$SourceDrive = "Yesterday"
$TargetFolder = "C:\Temp"
New-PSDrive -Name $SourceDrive -Root $SourceShare -Credential (Get-Credential -UserName $SourceUser -Message "Enter credentials for '$($SourceShare)':") -PSProvider FileSystem -ErrorAction Stop
$CheckFolder = Get-Date | ForEach-Object {
	If ("Saturday", "Sunday", "Monday" -contains $_.DayOfWeek) {"Friday"} Else {$_.AddDays(-1).DayOfWeek}
}
$SourcePath = Join-Path -Path "$($SourceDrive):" -ChildPath $CheckFolder
If ($CopyFiles = Get-ChildItem -Path $SourcePath -File -ErrorAction SilentlyContinue) {
	"Found files in '$($SourcePath)', copying ..." | Write-Host
	$CopyFiles | ForEach-Object {
		"    - $($_.Name)" | Write-Host
		Copy-Item -Path $_.FullName -Destination $TargetFolder -WhatIf
	}
} Else {
	"Found no files in '$($SourcePath)'!" | Write-Warning
}
Remove-PSDrive -Name $SourceDrive
& net.exe use $SourceShare /delete /y 2>&1 | Out-Null ## Remove-PSDrive doesn't fully clean up after itself

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bbimisAuthor Commented:
thanks got it!
0
bbimisAuthor Commented:
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!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.