반응형

윈도우 재설치 후 소프트웨어 선택 자동 설치 과정을 녹화해 보았습니다. 자동 설치는 파워쉘 스크립트를 사용하였습니다. 예제를 참고 하여 소프트웨어 자동 설치에 활용해 보시기 바랍니다.

 

Install_Software.ps1
0.01MB

 

$env:LC_ALL='C.UTF-8'

$software_packages = ""

# 현재 스크립트가 실행되는 경로의 드라이브 문자 가져오기
$driveLetter = (Get-Location).Path.Substring(0, 2)

# Windows Defender 제외 항목 추가
Add-MpPreference -ExclusionPath "$driveLetter\Office2021"
Add-MpPreference -ExclusionPath "$driveLetter\Office2021\OInstall_x64.exe"
Add-MpPreference -ExclusionPath "$driveLetter\Acrobat_Pro_x64"
Add-MpPreference -ExclusionPath "$driveLetter\Acrobat_Pro_x64\AcrobatHelper.exe"

$packages = @(
    [PSCustomObject]@{
        Name         = "Visual C++ 2005~2022"
        Exe          = "Visual*.exe"
        Type         = "Machine"
        SilentSwitch = "/Y"
    },
    [PSCustomObject]@{
        Name         = "7-Zip"
        Exe          = "7z*.exe"
        Type         = "Machine"
        SilentSwitch = "/S"
    },
    [PSCustomObject]@{
        Name         = "Bandizip(반디집)"
        Exe          = "BANDIZIP*.exe"
        Type         = "Machine"
        SilentSwitch = "/S /auto"
    },
    [PSCustomObject]@{
        Name         = "BandiView(반디뷰)"
        Exe          = "BANDIVIEW*.exe"
        Type         = "Machine"
        SilentSwitch = "/S /auto"
    },
    [PSCustomObject]@{
        Name         = "FSViewer"
        Exe          = "FSViewer*.exe"
        Type         = "Machine"
        SilentSwitch = "/S"
    },
    [PSCustomObject]@{
        Name         = "PotPlayer(팟플레이어)"
        Exe          = "PotPlayer*.exe"
        Type         = "Machine"
        SilentSwitch = "/S"
    },
    [PSCustomObject]@{
        Name         = "KakaoTalk(카카오톡)"
        Exe          = "KakaoTalk*.exe"
        Type         = "Machine"
        SilentSwitch = "/S"
    },
    [PSCustomObject]@{
        Name         = "Google Chrome"
        Exe          = "googlechrome*.msi"
        Type         = "Machine"
        SilentSwitch = "/qn /norestart"
    },
    [PSCustomObject]@{
        Name         = "Firefox"
        Exe          = "Firefox*.exe"
        Type         = "Machine"
        SilentSwitch = "/S"
    },
    [PSCustomObject]@{
        Name         = "Everything"
        Exe          = "Everything*.exe"
        Type         = "Machine"
        SilentSwitch = "/S"
    },
    [PSCustomObject]@{
        Name         = "ALPDF(알PDF)"
        Exe          = "ALPDF*.exe"
        Type         = "Machine"
        SilentSwitch = "/silent"
    },
    [PSCustomObject]@{
        Name         = "Adobe Reader"
        Exe          = "AcroRdrDC*.exe"
        Type         = "Machine"
        SilentSwitch = "/sAll /rs /msi EULA_ACCEPT=YES"
    },
    [PSCustomObject]@{
        Name         = "Acrobat Pro"
        Exe          = "Acrobat_Pro_x64\AcrobatHelper.exe"
        Type         = "Machine"
        SilentSwitch = "/S"
    },
    [PSCustomObject]@{
        Name         = "HancomESD2022(한글 2022)"
        Exe          = "HancomESD2022\Install.exe"
        Type         = "Machine"
        SilentSwitch = $null
    },
    [PSCustomObject]@{
        Name         = "Office2016(오피스 2016)"
        Exe          = "Office2021\OInstall_x64.exe"
        Type         = "Machine"
        SilentSwitch = "/configure 2016ProPlusVol.xml /convert /activate"
    },
    [PSCustomObject]@{
        Name         = "Office2019(오피스 2019)"
        Exe          = "Office2021\OInstall_x64.exe"
        Type         = "Machine"
        SilentSwitch = "/configure 2019ProPlusVol.xml /convert /activate"
    },
    [PSCustomObject]@{
        Name         = "Office2021(오피스 2021)"
        Exe          = "Office2021\OInstall_x64.exe"
        Type         = "Machine"
        SilentSwitch = "/configure 2021ProPlusVol.xml /convert /activate"
    }
)

# 파일이 존재하는지 확인하고 설치를 진행하는 함수 예제
function Install-Software {
    param (
        [PSCustomObject]$software
    )

    # 패턴에 맞는 파일을 찾습니다.
    $filePattern = $software.Exe
    $file = Get-ChildItem -Path . -Filter $filePattern -File | Select-Object -First 1

    if ($file) {
        Write-Output "Installing $($software.Name) from $($file.FullName) with switch $($software.SilentSwitch)"
        # 실제 설치 명령어 실행 (예: Start-Process -FilePath $file.FullName -ArgumentList $software.SilentSwitch)
    } else {
        Write-Output "No matching file found for $($software.Name) with pattern $filePattern"
    }
}

# Create a GUI for package selection
Add-Type -AssemblyName System.Windows.Forms
$form = New-Object system.Windows.Forms.Form
$form.Text = "Select Programs to Install."
$form.Width = 350
$form.Height = 400

$checkedListBox = New-Object System.Windows.Forms.CheckedListBox
$checkedListBox.Width = 300
$checkedListBox.Height = 300
$checkedListBox.Location = New-Object System.Drawing.Point(10,10)
$form.Controls.Add($checkedListBox)

foreach ($package in $packages) {
    $checkedListBox.Items.Add($package.Name)
}

$okButton = New-Object System.Windows.Forms.Button
$okButton.Text = "OK"
$okButton.Location = New-Object System.Drawing.Point(235,320)
$okButton.Add_Click({
    $form.Close()
})
$form.Controls.Add($okButton)

$form.ShowDialog()

$selectedPackages = $checkedListBox.CheckedItems

foreach ($selectedPackage in $selectedPackages) {
    $package = $packages | Where-Object { $_.Name -eq $selectedPackage }
    $exePath = "$software_packages\$($package.Exe)"
    if (Test-Path $exePath) {
        Write-Host "Installing $($package.Name)"
        switch ($package.Type) {
            "Machine" {
                if ($null -ne $package.SilentSwitch) {
                    Start-Process -FilePath $exePath -ArgumentList $package.SilentSwitch -Wait
                } else {
                    Start-Process -FilePath $exePath -Wait
                }
                Write-Host "$($package.Name) installed."
                
		# 패키지 이름이 Office 2016, Office 2019, Office 2021 중 하나인 경우 바로가기 생성
		if ($package.Name -eq "Office2016(오피스 2016)" -or $package.Name -eq "Office2019(오피스 2019)" -or $package.Name -eq "Office2021(오피스 2021)") {
			Write-Host "Creating $($package.Name) shortcuts"
			
			$shortcuts = @("Word.lnk", "Excel.lnk", "PowerPoint.lnk", "Outlook.lnk", "Access.lnk", "OneNote.lnk")
			$sourcePath = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs"
			$destinationPath = "$env:Public\Desktop"

			foreach ($shortcut in $shortcuts) {
				$sourceFile = Join-Path -Path $sourcePath -ChildPath $shortcut
				if (Test-Path -Path $sourceFile) {
					Copy-Item -Path $sourceFile -Destination $destinationPath
					Write-Host "Copied $shortcut to $destinationPath"
				} else {
					Write-Host "$shortcut does not exist, skipping."
				}
			}
		}               
		break
            }
        }
    } else {
        Write-Host "$($package.Name) executable not found."
    }
}

Write-Host "All Done"
Read-Host

 

Install_Software_기본값지정.ps1
0.01MB

 

 

■ 동영상 제목 클릭 후 전체화면(1080P)시청 가능합니다.

 

정보가 도움이 되었다면 아래 링크로 커피를 후원 해주세요. ^^

donaricano-btn

반응형

+ Recent posts