Copy-Item cmdlet 应该只复制差异
我正在使用 powershell 编写备份脚本。我知道我可以使用 robocopy 或 rsync 但我想在 powershell 中执行此操作。我遇到的问题与复制项目 cmdlet 有关。我的脚本的作用:
- 读取 var 并从 csv 填充它们
- Ping 目标主机
- 检查 Outlook 是否在源主机上打开并询问是否应该关闭它
- 然后它应该将一些文件夹复制到目标上
我的问题是它总是执行完整复制所有文件。我希望它只复制已更改或目标上不存在的文件。
我遇到的第二个问题是,在Win7中,“用户/文档”中有隐藏的系统文件夹链接到“我的图片”和“我的视频”。我不需要复制这些,但我没有设法使用排除参数排除它们。
Im writeing a backupscript useing powershell. I know that i could just use robocopy or rsync but i would like to do this in powershell. The problem i have has to do with the copy-item cmdlet. What my script does:
- Read var's and fills them from a csv
- Pings destination host
- Checks if Outlook is open on source host and asks if it should close it
- Then it should copy some folders onto the destination
My problem is that it always does a full copy of all files. I would like it to only copy the files that were changed or do not exist on the destination.
The second problem i have is that in Win7 there are hidden systemfolders in "Users/Documents" that link to "My Pictures" and "My Videos". I dont need to copy these but i didnt manage to exclude them useing the exclude agrument.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是一些快速和一般性的建议...
我希望它只复制已更改的文件
我将复制比较源和目标修改日期的文件
我遇到的第二个问题是在Win7中存在隐藏的系统文件夹在链接到“我的图片”和“我的视频”的“用户/文档”中。我不需要复制这些,但我没有设法使用排除参数排除它们。:
不要直接使用
copy-item
,而是使用不带force
参数的get-childitem
的输出。这将防止复制隐藏文件或系统文件。Just some quick and general suggestion...
I would like it to only copy the files that were changed
I would copy the files comparing the source and destination modified date
The second problem i have is that in Win7 there are hidden systemfolders in "Users/Documents" that link to "My Pictures" and "My Videos". I dont need to copy these but i didnt manage to exclude them useing the exclude agrument. :
Do not use
copy-item
directly, but use the output ofget-childitem
withoutforce
parameter. This will prevent to copy hidden or system files.