Powershell 的 Copy-Item 的 -container 参数是什么意思? [英] What is the meaning of Powershell's Copy-Item's -container argument?

查看:47
本文介绍了Powershell 的 Copy-Item 的 -container 参数是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 MS PowerShell 编写脚本.此脚本使用 Copy-Item 命令.此命令的可选参数之一是-container".该参数的文档指出,指定此参数在复制操作期间保留容器对象."

这一切都很好,因为在复制操作期间我将是最后一个想要未保存的容器对象的人.但说真的,这个论点有什么作用呢?特别是在我将磁盘目录树从一个地方复制到另一个地方的情况下,这对 Copy-Item 命令的行为有何不同?

解决方案

文档所讨论的容器是文件夹结构.如果您正在执行递归复制并希望保留文件夹结构,则可以使用 -container 开关.(注意:默认情况下 -container 开关设置为 true,所以你真的不需要指定它.如果你想关闭它,你可以使用 -container: $false.)>

有一个问题...如果您列出目录并将其通过管道传输到 Copy-Item,它将不会保留文件夹结构.如果要保留文件夹结构,则必须指定 -path 属性和 -recurse 开关.

I am writing a script for MS PowerShell. This script uses the Copy-Item command. One of the optional arguments to this command is "-container". The documentation for the argument states that specifying this argument "Preserves container objects during the copy operation."

This is all well and good, for I would be the last person to want unpreserved container objects during a copy operation. But in all seriousness, what does this argument do? Particularly in the case where I am copying a disk directory tree from one place to another, what difference does this make to the behavior of the Copy-Item command?

解决方案

The container the documentation is talking about is the folder structure. If you are doing a recursive copy and want to preserve the folder structure, you would use the -container switch. (Note: by default the -container switch is set to true, so you really would not need to specify it. If you wanted to turn it off you could use -container: $false.)

There is a catch to this... if you do a directory listing and pipe it to Copy-Item, it will not preserve the folder structure. If you want to preserve the folder structure, you have to specify the -path property and the -recurse switch.

这篇关于Powershell 的 Copy-Item 的 -container 参数是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆