user2776281
user2776281

Reputation: 9

Ho can I copy files from mutible pcs to network share and create a folder?

I need to copy 10 .ini files from various locations on a pc to a network share. I need to run this against 500 computers. The below code works great but the issue is they have the same name on each computer and this puts all the files in the one folder.

Can anyone tell me how I can add extra locations to the below code and to create a new folder based on the name in list.txt eg branch01, branch02 etc and have all the ini files from branch01 copy to \networkshare\branch01.

Get-Content list.txt | ForEach-Object {
if(Test-Connection $_ -Quiet -Count 1){

Copy-Item "\\$_\c$\windows\test.ini" "\\Networkshare\Branch01"

Upvotes: 0

Views: 155

Answers (1)

rugkei
rugkei

Reputation: 70

$branch = 1

Get-Content list.txt | ForEach-Object {
    if(Test-Connection $_ -Quiet -Count 1){
        $branch2 = $branch.ToString()
        $folder = $_ + $branch2
        Copy-Item "\\$_\c$\windows\*.ini" "\\Networkshare\$folder"
    }

    $branch = $branch + 1
}

The way I understand your question, that should solve your problem.

EDIT: Look at this:

PS C:\> $v1 = "hello"
PS C:\> $v2 = "world"
PS C:\> $v3 = $v1 + $v2
PS C:\> echo $v3
hello world

EDIT 2: Look at the String conversion

Upvotes: 1

Related Questions