# xp_share_setup.ps1 # 관리자 권한으로 실행해야 함 Write-Host "=== XP ↔ Win11 공유 설정 스크립트 시작 ===" -ForegroundColor Cyan # 1) SMB1 활성화 (클라이언트 + 서버) Write-Host "1) SMB1 기능 활성화 (SMB1Protocol / SMB1Protocol-Server)..." -NoNewline try { dism /online /enable-feature /featurename:SMB1Protocol /all /norestart | Out-Null dism /online /enable-feature /featurename:SMB1Protocol-Server /all /norestart | Out-Null Write-Host " 완료" -ForegroundColor Green } catch { Write-Host " 실패 (권한/환경 문제) - 수동 실행 필요" -ForegroundColor Red } # 2) 네트워크 프로필을 Private으로 변경 (가능한 모든 연결) Write-Host "2) 네트워크 프로필을 Private으로 변경 중..." -NoNewline try { $profiles = Get-NetConnectionProfile -ErrorAction Stop foreach ($p in $profiles) { if ($p.NetworkCategory -ne "Private") { Set-NetConnectionProfile -InterfaceIndex $p.InterfaceIndex -NetworkCategory Private -ErrorAction Stop } } Write-Host " 완료" -ForegroundColor Green } catch { Write-Host " 실패 (권한/모듈 문제) - 확인 필요" -ForegroundColor Yellow } # 3) 파일 및 프린터 공유 방화벽 규칙 활성화 Write-Host "3) 파일 및 프린터 공유 방화벽 규칙 활성화..." -NoNewline try { Get-NetFirewallRule -DisplayGroup "File and Printer Sharing" -ErrorAction Stop | Set-NetFirewallRule -Enabled True Write-Host " 완료" -ForegroundColor Green } catch { Write-Host " 실패 (규칙 없거나 권한 문제) - 대체 커맨드 시도" -ForegroundColor Yellow # 대체: 포트 허용 (TCP 445, 139 / UDP 137, 138) netsh advfirewall firewall add rule name="SMB TCP445" dir=in action=allow protocol=TCP localport=445 | Out-Null netsh advfirewall firewall add rule name="SMB TCP139" dir=in action=allow protocol=TCP localport=139 | Out-Null netsh advfirewall firewall add rule name="SMB UDP137" dir=in action=allow protocol=UDP localport=137 | Out-Null netsh advfirewall firewall add rule name="SMB UDP138" dir=in action=allow protocol=UDP localport=138 | Out-Null Write-Host " 포트 예외 추가 완료" -ForegroundColor Green } # 4) (테스트용) 전체 방화벽 끄기 - 보안상 위험. 필요하면 주석 해제해서 사용. # Write-Host "4) 전체 방화벽 일시 비활성화 (테스트용)..." -NoNewline # netsh advfirewall set allprofiles state off # Write-Host " 완료" -ForegroundColor Yellow # 5) 공유 폴더 생성 및 권한 설정 + SMB 공유 생성 $sharePath = "C:\Share" $shareName = "XPshare" Write-Host "5) 공유 폴더 생성 및 권한 설정 ($sharePath)..." -NoNewline try { if (-not (Test-Path $sharePath)) { New-Item -Path $sharePath -ItemType Directory -Force | Out-Null } # Everyone 전체 권한 부여 icacls $sharePath /grant "Everyone:(OI)(CI)F" /T | Out-Null Write-Host " 폴더권한 완료" -ForegroundColor Green } catch { Write-Host " 실패 (권한 문제)" -ForegroundColor Red } Write-Host " -> SMB 공유 생성 시도 (New-SmbShare)..." -NoNewline try { # 기존 같은 이름 있으면 삭제 후 생성 if (Get-SmbShare -Name $shareName -ErrorAction SilentlyContinue) { Remove-SmbShare -Name $shareName -Force -Confirm:$false } New-SmbShare -Name $shareName -Path $sharePath -FullAccess "Everyone" -ErrorAction Stop | Out-Null Write-Host " 완료" -ForegroundColor Green } catch { Write-Host " 실패 (New-SmbShare 불가) - net share로 대체 시도" -ForegroundColor Yellow net share $shareName="$sharePath" /grant:Everyone,full | Out-Null Write-Host " net share로 공유 생성 완료" -ForegroundColor Green } # 6) 네트워크/연결 확인: ipconfig 출력 및 ping 예시 안내 Write-Host "6) IP 정보 (확인용):" -ForegroundColor Cyan ipconfig Write-Host "" Write-Host "XP에서 접속하려면: \\\$shareName 로 접속" -ForegroundColor Magenta Write-Host "Win11에서 XP 접근 테스트: ping (XP에서 IP 확인 필요)" -ForegroundColor Magenta # 7) 안내 및 보안 권고 Write-Host "" Write-Host "=== 완료 ===" -ForegroundColor Green Write-Host "주의: SMB1은 보안 취약. 연결 확인 후 아래 명령으로 SMB1을 비활성화하세요:" -ForegroundColor Yellow Write-Host " dism /online /disable-feature /featurename:SMB1Protocol /norestart" -ForegroundColor Yellow Write-Host "" Write-Host "스크립트 종료. 필요하면 재부팅 권장." -ForegroundColor Cyan