매일 사용자가 서버에서 로컬 컴퓨터로 복사하는 프로덕션 데이터베이스의 복사본을 만듭니다. 특정 경로의 마지막 세 파일을 선택하고 복사하는 스크립트로이 프로세스를 자동화하려고합니다.PowerShell에서 -last 매개 변수를 사용하여 복사 할 파일을 선택하려면 어떻게해야합니까?
나는
dir $HS3BackupPath | sort LastWriteTime | select -last 3
가 제대로 선택하는 데 사용할 내가 복사 할 세 개의 파일을 표시하지만, 나는 복사 명령이 결과를 파이프에 실패 있었어요 수 있습니다.
이 this question, this question 및 this one보고 후, 나는
dir $HS3BackupPath | sort LastWriteTime | select -last 3 |
copy-item $HS3BackupPath $Dest
을 시도하고이 오류를 가지고 : 변화를 시도
copy-item : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its
properties do not match any of the parameters that take pipeline input.
At C:\scripts\RefreshHS3.ps1:96 char:63
+ dir $HS3BackupPath | sort LastWriteTime |select -last 3 | copy-item $HS3Back ...
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (HS3PREcompress-...11-38-17-62.mdb:PSObject) [Copy-Item], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.CopyItemCommand
, 나는 지금 여기
Copy-Item $HS3BackupPath $Dest | sort LastWriteTime | select -last 3
해요 및 이 오류 :
Copy-Item : Container cannot be copied onto existing leaf item.
At C:\scripts\RefreshHS3.ps1:98 char:1
+ Copy-Item $HS3BackupPath $Dest | sort LastWriteTime | select -last 3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (\\DC1\HS3_db_Backups\:String) [Copy-Item], PSArgumentException
+ FullyQualifiedErrorId : CopyContainerItemToLeafError,Microsoft.PowerShell.Commands.CopyItemCommand
누구나이 파일을 적절하게 복사하는 올바른 구문을 알고 있습니까?
'Copy-Item'이 파이프 라인에서 읽을 수 있으므로 루프를 사용하지 않아도됩니다. 다음과 같이'-Destination'을 사용해야합니다 :'... | 항목 복사 - 대상 $ Dest'. –
@AnsgarWiechers 감사합니다. 가장 좋은 답변을 업데이트했습니다. – Matt