Windows

[Windows] Powershell 이용하여 PC 정보 획득 (OS,Mac addr, SW list)

Victory_HA 2025. 3. 31. 11:04
  • PC 정보를 조사하기 위한 스크립트 파일입니다.

    • OS 버전
    • MAC 주소
    • 설치 프로그램 리스트
    • Disk 정보
  • ps1확장자 파일로 생성하여 실행합니다.

# PowerShell 스크립트: PC 정보 조회
# 목적: OS 버전, MAC 주소, 설치된 소프트웨어 목록, 디스크 정보 출력

$output = @()

# 1. 운영 체제 버전 조회
Write-Host "`n=== Operating System Version ===" -ForegroundColor Cyan
$os = Get-WmiObject -Class Win32_OperatingSystem
$osInfo = "$($os.Caption) (Version: $($os.Version))"
Write-Host $osInfo
$output += "=== OS Version === `n$osInfo"

# 2. MAC 주소 조회
Write-Host "`n=== MAC Addresses ===" -ForegroundColor Cyan
$macAddresses = Get-NetAdapter | Where-Object { $_.MacAddress -ne $null -and $_.MacAddress -ne "" }

if ($macAddresses) {
    $macAddresses | Format-Table -Property Name, MacAddress -AutoSize
    $macOutput = $macAddresses | ForEach-Object { "Interface: $($_.Name), MAC Address: $($_.MacAddress)" }
    $output += "=== MAC Addresses ===`n" + ($macOutput -join "`n")
} else {
    Write-Host "=== No MAC addresses found ==="
    $output += "=== MAC Addresses Not found ==="
}

# 3. 설치된 소프트웨어 목록을 가져오는 함수 정의
function Get-InstalledSoftware {
    $registryPaths = @(
        "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*",
        "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*",
        "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*",
        "HKCU:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
    )
    $softwareList = @()
    foreach ($path in $registryPaths) {
        if (Test-Path $path) {
            $softwareList += Get-ItemProperty -Path $path | 
                Where-Object { $_.DisplayName } | 
                Select-Object @{Name="Name";Expression={$_.DisplayName}}, 
                              @{Name="Version";Expression={$_.DisplayVersion}}
        }
    }
    return $softwareList | Sort-Object Name
}

# 4. 설치된 소프트웨어 목록 가져오기
Write-Host "`n=== Installed Software List ===" -ForegroundColor Cyan
$allSoftware = Get-InstalledSoftware  # 수정된 부분

if ($allSoftware) {
    $allSoftware | Format-Table -AutoSize
    $softwareOutput = $allSoftware | ForEach-Object { "$($_.Name)" }
    $output += "=== Installed Software ===`n" + ($softwareOutput -join "`n")
} else {
    Write-Host "=== No installed software found ==="
    $output += "=== Installed Software: Not found ==="
}

# 5. 디스크 정보 조회
Write-Host "`n=== Disk Information ===" -ForegroundColor Cyan
$diskInfo = Get-Disk | ForEach-Object {
    "Model: $($_.Model), Name: $($_.FriendlyName), SerialNumber: $($_.SerialNumber)"
}
Write-Host ($diskInfo -join "`n")
$output += "=== Disk Information ===`n" + ($diskInfo -join "`n")

# 결과를 파일로 저장
$outputFile = "$env:USERPROFILE\Desktop\PC_Info_$((Get-Date).ToString('yyyyMMdd_HHmmss')).txt"
$output | Out-File -FilePath $outputFile
Write-Host "`nResults saved to: $outputFile" -ForegroundColor Green