这就是我所拥有的,但不断出现以下错误。我使用的是Windows 7家庭高级版64位。我需要将笔记本电脑硬盘中的所有内容复制到桌面K:\ Mybackup文件夹。
$source = "M:\"
$dest = "K:\MyBackup"
Copy-item $source $dest -recurse
PS C:> copy-item $ source $ dest Copy-Item:不支持给定路径的格式。 在行:1 char:10 + copy-item<<<< $ source $ dest + CategoryInfo:InvalidOperation:(K:\ gateway \ M:\:String)[Copy-Item],NotSupportedException + FullyQualifiedErrorId:ItemExistsNotSupportedError,Microsoft.PowerShell.Commands.CopyItemCommand
PS C:>拷贝项目
命令管道位置1处的cmdlet Copy-Item 提供以下参数的值: 路径[0]:
答案 0 :(得分:2)
function Copy-Directories
{
param (
[parameter(Mandatory = $true)] [string] $source,
[parameter(Mandatory = $true)] [string] $destination
)
try
{
Get-ChildItem -Path $source -Recurse -Force |
Where-Object { $_.psIsContainer } |
ForEach-Object { $_.FullName -replace [regex]::Escape($source), $destination } |
ForEach-Object { $null = New-Item -ItemType Container -Path $_ }
Get-ChildItem -Path $source -Recurse -Force |
Where-Object { -not $_.psIsContainer } |
Copy-Item -Force -Destination { $_.FullName -replace [regex]::Escape($source), $destination }
}
catch
{
Write-Host "$_"
}
}
$source = "M:\"
$dest = "K:\MyBackup"
Copy-Directories $source $dest