2013-11-14 96 views
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%\" 

我有麻煩。我想能夠每天做一個子文件夾,但所有我的作品是%日期:〜0,3%\PowerShell複製項目PS1腳本

但我知道PowerShell這樣做,但我不太清楚如何將其複製到您複製它的那一天的位置。

$a = Get-Date 
$a.DayOfWeek 
+0

當你在下面試試我們的答案時,你會得到什麼錯誤? – Eris

回答

0

有多種方式做事情在PowerShell中。另一種選擇是:

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

而且,由於PowerShell的允許位置參數可以簡化爲:

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

修改您的功能創建目標目錄,如果不存在的話:

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

這些也沒有工作。 – MrJello85

+0

看看更新的答案是否有幫助。 –

+0

得到它的工作! – MrJello85

2

最直接的方法:-to "\\Testserver\Back-Ups\TEST\$(get-date -format 'dddd')"

我的首選方法:

$Destination = '\\Testserver\Back-Ups\TEST\{0:dddd}' -f (get-date); 
... -to "$Destination" 
+0

這些沒有奏效。 – MrJello85

0

我可以在這些結尾添加這樣的內容嗎?

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 
相關問題