본문 바로가기
카테고리 없음

네트워크 드라이브 파일 대량 복사 robocopy powershell script

by xfree302 2026. 1. 19.
반응형

Z: 드라이브 특정 폴더를 E:드라이브 폴더로 복사하는 스크립트

1. file_list.txt : 복사 대상 경로 작성

Z:\aaa
Z:\bbb
Z:\ccc\123

 

2. file_copy.ps1 작성

$SourceList = "d:\file_list.txt"
$SourceRoot = "Z:\"
$TargetRoot = "E:\NAS"
$robocopylog = "E:\NAS\file_list.log"

Get-Content -Encoding Default $SourceList | ForEach-Object {

    $SourcePath = ($_ -replace '[\u00A0\u2000-\u200B\t]', '').Trim().TrimEnd('\')
    if ($SourcePath -eq "") { return }

    # 상대 경로 계산
    if ($SourcePath.StartsWith($SourceRoot)) {
        $RelativePath = $SourcePath.Replace($SourceRoot, "")
    } else {
        Write-Host "Path not found : $SourcePath"
        return
    }

    $TargetPath = Join-Path $TargetRoot $RelativePath

    # 대상 폴더 생성 (에러 무시)
    New-Item -ItemType Directory -Path $TargetPath -Force -ErrorAction SilentlyContinue | Out-Null

    # robocopy가 실제 존재 여부 판단
    robocopy "$SourcePath" "$TargetPath" /E /COPY:DAT /DCOPY:T /R:1 /W:1 /MT:8 /LOG+:"$robocopylog"

    Write-Host "robocopy done : $SourcePath"
}

 

3. powershell 관리자 권한으로 실행

 

4. powershell 명령어 실행

powershell -ExecutionPolicy Bypass -File file_copy.ps1

 

5. 혹시 powershell 에서 Z: 네트워크드라이브 인식이 안된다면 아래 명령어 실행

net use Z: \\NAS서버이름\공유폴더 /user:계정 비밀번호
반응형