Reputation: 3
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
Upvotes: 0
Views: 1406
Reputation: 3
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
Upvotes: 0
Reputation: 201652
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}
}
Upvotes: 0
Reputation: 7638
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"
Upvotes: 2