Pergunta

I can't believe this is as difficult as I'm finding it.

I have a folder on a server share. This folder has a number of subfolder which may, or may not, contain a file I want to overwrite with a latest-version.

I've done many a google search & figured the command below would get me what I want:

Get-ChildItem \\server1\websites\website\xml -Name "description-15240.txt" -Recurse | Copy-Item ".\description-15240.txt" -Destination $_.fullname

...but it doesn't.

So, I break the command down into parts & find the Get-ChildItem only returns the file path FROM the root of the -Name parameter i.e.

1\infinite\description-15240.txt 68\infinite\description-15240.txt 79\infinite\description-15240.txt 80\infinite\description-15240.txt

rather than \server1\websites\website\xml\1\infinite\description-15240.txt which is what I'm after.

The problem: I can't get the Get-ChildItem to return the full path | { $_.FullName } doesn't do it neither does | { $_.Parent }

Can someone help & possiblly tell me if the Copy-Item is likely to work as well?

Many thanks, N

Foi útil?

Solução

Name parameter only filter the name of the file, if you want full path of the file use include parameter.

Get-ChildItem \\server1\websites\website\xml -include "description-15240.txt" -Recurse | % { Copy-Item ".\description-15240.txt" -Destination $_.fullname }

Outras dicas

try

gci \\server1\websites\website\xml -Name "description-15240.txt" -recurse |%{ convert-path $_.pspath}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top