0
Function CopyTwolocations ($from, $to)
{
Copy-Item -Path $from $to -Recurse -Force
$?
if($false) {Return}
}

CopyTwolocations -from "C:\Test1\Subtest1\*" -to "\\Testserver\Back-Ups\TEST\%date:~0,3%\"
CopyTwolocations -from "C:\TESTMYSQL\*" -to "\\Testserver\Back-Ups\TEST\%date:~0,3%\"

I am having trouble. I want to be able to make a sub folder for every day but all I have that works is %date:~0,3%\

but I know powershell does this but I am not quite sure how to copy it into the location of the day you copy it.

$a = Get-Date
$a.DayOfWeek
1
  • What errors do you get when you try our answers below? Commented Nov 15, 2013 at 17:35

3 Answers 3

2

most direct method: -to "\\Testserver\Back-Ups\TEST\$(get-date -format 'dddd')"

My preferred method:

$Destination = '\\Testserver\Back-Ups\TEST\{0:dddd}' -f (get-date);
... -to "$Destination"
Sign up to request clarification or add additional context in comments.

Comments

0

There are multiple ways to do things in PowerShell. Another alternative is:

CopyTwolocations -from "C:\TESTMYSQL\*" -to "\\Testserver\Back-Ups\TEST\$(get-date -f ddd)\"

And since PowerShell allows for positional parameters that could be simplified to:

CopyTwolocations C:\TESTMYSQL\* "\\Testserver\Back-Ups\TEST\$(get-date -f ddd)\"

Modify you function to create the destination directory if it doesn't exist:

Function CopyTwolocations ($from, $to)
{
    if (!(Test-Path $to)) {
        md $to
    }
    Copy-Item -Path $from $to -Recurse -Force
    $?
   if($false) {Return}
}

Comments

0

Could I append something like this to the end of these ?

CopyTwolocations -from "C:\Test1\Subtest1\*" -to "\\Testserver\Back-Ups\TEST\%date:~0,3%\" -name ("Docs-"+ (Get-Date -format yyyyMMdd)) -type directory
CopyTwolocations -from "C:\TESTMYSQL\*" -to "\\Testserver\Back-Ups\TEST\%date:~0,3%\" -name ("Docs-"+ (Get-Date -format yyyyMMdd)) -type directory

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.