Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Script configuration
- [CmdletBinding()]
- param (
- [string]$LogPath = 'C:\install\logs',
- [switch]$Force,
- [switch]$SkipTeamViewer,
- [switch]$Test,
- [switch]$PC,
- [switch]$Laptop
- )
- # Enable strict mode for better error catching
- Set-StrictMode -Version Latest
- $ErrorActionPreference = 'Stop'
- # Load required assemblies
- Add-Type -AssemblyName System.Windows.Forms
- # The InstallationResult class definition
- class InstallationResult {
- [string]$Name
- [bool]$Success
- [string]$Message
- [datetime]$Timestamp
- InstallationResult([string]$name, [bool]$success, [string]$message) {
- $this.Name = $name
- $this.Success = $success
- $this.Message = $message
- $this.Timestamp = Get-Date
- }
- }
- Clear-Host
- # Initialize logging
- function Initialize-InstallationEnvironment {
- param (
- [string]$LogDirectory
- )
- $timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
- $logFile = Join-Path $LogDirectory "installation_$timestamp.log"
- if (-not (Test-Path $LogDirectory)) {
- New-Item -Path $LogDirectory -ItemType Directory -Force | Out-Null
- }
- return $logFile
- }
- # Enhanced logging function
- function Write-LogMessage {
- param (
- [Parameter(Mandatory=$true)]
- [string]$Message,
- [Parameter(Mandatory=$false)]
- [ValidateSet('Info', 'Warning', 'Error', 'Success')]
- [string]$Level = 'Info',
- [Parameter(Mandatory=$false)]
- [string]$LogFile
- )
- $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
- $logMessage = "[$timestamp] [$Level] $Message"
- $colorMapping = @{
- 'Info' = 'Cyan'
- 'Warning' = 'Yellow'
- 'Error' = 'Red'
- 'Success' = 'Green'
- }
- Write-Host $logMessage -ForegroundColor $colorMapping[$Level]
- if ($LogFile) {
- Add-Content -Path $LogFile -Value $logMessage
- }
- }
- # Function to check network connectivity
- function Test-NetworkConnectivity {
- try {
- $null = Test-Connection -ComputerName 'google.com' -Count 2 -ErrorAction Stop
- return $true
- }
- catch {
- return $false
- }
- }
- # Function to check available disk space
- function Test-DiskSpace {
- param (
- [int]$RequiredSpaceGB = 5,
- [string]$LogFile
- )
- try {
- $drive = Get-PSDrive -Name 'C' -ErrorAction Stop
- $driveFreeSpace = $drive.Free
- if ($driveFreeSpace -lt ($RequiredSpaceGB * 1GB)) {
- throw "Not enough disk space. Required: ${RequiredSpaceGB}GB, Available: $([math]::Round($driveFreeSpace / 1GB, 2))GB"
- }
- else {
- Write-LogMessage -Message "Sufficient disk space available: $([math]::Round($driveFreeSpace / 1GB, 2))GB" -Level Info -LogFile $LogFile
- }
- }
- catch {
- Write-LogMessage -Message "Error checking disk space: $_" -Level Error -LogFile $LogFile
- throw
- }
- }
- # Configuration validation
- function Test-InstallationPrerequisites {
- param (
- [string]$LogFile
- )
- Write-LogMessage -Message "Checking installation prerequisites..." -Level Info -LogFile $LogFile
- $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
- if (-not $isAdmin) {
- Write-LogMessage -Message "Script must be run as administrator." -Level Error -LogFile $LogFile
- throw "Administrator privileges required"
- }
- if (-not (Test-NetworkConnectivity)) {
- Write-LogMessage -Message "No network connectivity. Please ensure you are connected to the internet. Some installations might fail." -Level Warning -LogFile $LogFile
- }
- else {
- Write-LogMessage -Message "Internet connection available." -Level Info -LogFile $LogFile
- }
- try {
- Test-DiskSpace -RequiredSpaceGB 10 -LogFile $LogFile
- }
- catch {
- Write-LogMessage -Message "Insufficient disk space: $_" -Level Error -LogFile $LogFile
- throw $_
- }
- }
- function Test-RecursivePath {
- param (
- [string]$SoftwareName,
- [string]$LogFile
- )
- # Ensure the software list is populated
- if (-not $softwareList -or $softwareList.Count -eq 0) {
- Write-LogMessage -Message "Software list is empty. Please populate the list before running the script." -Level Error -LogFile $LogFile
- return $false
- }
- # Retrieve the matching software entry
- $softwareEntry = $softwareList | Where-Object { $_.Name -eq $SoftwareName }
- if (-not $softwareEntry) {
- Write-LogMessage -Message "Software $SoftwareName not found in the list." -Level Error -LogFile $LogFile
- return $false
- }
- # Use CheckName for search patterns and VerifyFile for validation
- $searchPattern = $softwareEntry.CheckName
- $verifyFile = $softwareEntry.VerifyFile
- # Common installation directories
- $commonPaths = @(
- "C:\Program Files",
- "C:\Program Files (x86)",
- "${env:ProgramFiles}",
- "${env:ProgramFiles(x86)}",
- "${env:LocalAppData}\Programs",
- "${env:ProgramData}",
- "C:\Program Files\WindowsApps"
- )
- Write-LogMessage -Message "Searching for $SoftwareName installation..." -Level Info -LogFile $LogFile
- $directoryFound = $false
- foreach ($basePath in $commonPaths) {
- if (Test-Path $basePath) {
- try {
- # Search for directories matching the CheckName pattern
- $matchingDirs = Get-ChildItem -Path $basePath -Directory -Recurse -ErrorAction SilentlyContinue |
- Where-Object { $_.FullName -like "*$searchPattern*" }
- foreach ($dir in $matchingDirs) {
- # Validate using VerifyFile, if provided
- if ($verifyFile) {
- $fullVerifyFilePath = Join-Path $dir.FullName $verifyFile
- if (Test-Path $fullVerifyFilePath) {
- Write-LogMessage -Message "Found valid installation directory for $SoftwareName" -Level Success -LogFile $LogFile
- Write-LogMessage -Message "- $($dir.FullName)" -Level Info -LogFile $LogFile
- return $true
- }
- } else {
- Write-LogMessage -Message "Found potential installation directory for $SoftwareName (no VerifyFile):" -Level Warning -LogFile $LogFile
- Write-LogMessage -Message "- $($dir.FullName)" -Level Info -LogFile $LogFile
- return $true
- }
- }
- } catch {
- Write-LogMessage -Message "Error searching in {$basePath}: $_" -Level Warning -LogFile $LogFile
- continue
- }
- }
- }
- Write-LogMessage -Message "No installation directories found for $SoftwareName." -Level Warning -LogFile $LogFile
- return $false
- }
- function Test-SoftwareInstallation {
- param (
- [Parameter(Mandatory=$true)]
- [hashtable]$Software,
- [string]$LogFile
- )
- # Define registry paths
- $registryPaths = @(
- "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*",
- "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*",
- "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*",
- "HKCU:\Software\Microsoft\$($Software.Name)"
- )
- # Initialize verification results
- $verificationResults = @{
- RegistryFound = $false
- PathFound = $false
- ProcessFound = $false
- RegistryDetails = $null
- }
- try {
- # Check registry for software
- foreach ($path in $registryPaths) {
- try {
- $registryEntries = Get-ItemProperty -Path $path -ErrorAction SilentlyContinue |
- Where-Object { $_.DisplayName -like $Software.CheckName }
- if ($registryEntries) {
- $verificationResults.RegistryFound = $true
- $verificationResults.RegistryDetails = @{
- DisplayName = $registryEntries.DisplayName
- DisplayVersion = $registryEntries.DisplayVersion
- InstallLocation = if ($registryEntries.PSObject.Properties.Name -contains 'InstallLocation') {
- $registryEntries.InstallLocation
- } else {
- $null
- }
- }
- }
- } catch { continue }
- }
- # Check critical file if InstallLocation exists
- if ($Software.VerifyFile -and $verificationResults.RegistryDetails.InstallLocation) {
- $verifyPath = Join-Path $verificationResults.RegistryDetails.InstallLocation $Software.VerifyFile
- if ($verifyPath -and (Test-Path $verifyPath)) {
- $verificationResults.PathFound = $true
- }
- }
- # Check for running process
- if (Get-Process -Name $Software.Name -ErrorAction SilentlyContinue) {
- $verificationResults.ProcessFound = $true
- }
- # Override if no directory or critical file is found
- if (-not $verificationResults.PathFound) {
- Write-LogMessage -Message "No valid installation directory or critical files found for $($Software.Name)." -Level Warning -LogFile $LogFile
- return @{ IsInstalled = $false; Details = $verificationResults }
- }
- # Final decision
- $isInstalled = $verificationResults.RegistryFound -or $verificationResults.PathFound -or $verificationResults.ProcessFound
- return @{ IsInstalled = $isInstalled; Details = $verificationResults }
- } catch {
- throw $_
- }
- }
- function Set-UninstallInformation {
- param (
- [Parameter(Mandatory=$true)]
- [string]$DisplayName,
- [Parameter(Mandatory=$true)]
- [string]$UninstallString,
- [Parameter(Mandatory=$false)]
- [string]$Publisher = "Medirex Group",
- [Parameter(Mandatory=$false)]
- [string]$DisplayVersion = "",
- [Parameter(Mandatory=$false)]
- [string]$EstimatedSize = "",
- [Parameter(Mandatory=$false)]
- [string]$InstallLocation = "",
- [string]$LogFile
- )
- try {
- $uninstallPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$DisplayName"
- if (-not (Test-Path $uninstallPath)) {
- New-Item -Path $uninstallPath -Force | Out-Null
- }
- $properties = @{
- "DisplayName" = $DisplayName
- "UninstallString" = $UninstallString
- "Publisher" = $Publisher
- "NoModify" = 1
- "NoRepair" = 1
- }
- if ($DisplayVersion) { $properties["DisplayVersion"] = $DisplayVersion }
- if ($EstimatedSize) { $properties["EstimatedSize"] = $EstimatedSize }
- if ($InstallLocation) { $properties["InstallLocation"] = $InstallLocation }
- foreach ($prop in $properties.GetEnumerator()) {
- Set-ItemProperty -Path $uninstallPath -Name $prop.Key -Value $prop.Value
- }
- Write-LogMessage -Message "Successfully set uninstall information for ${DisplayName}" -Level Info -LogFile $LogFile
- }
- catch {
- Write-LogMessage -Message "Error setting uninstall information for ${DisplayName}: $_" -Level Error -LogFile $LogFile
- throw
- }
- }
- function Get-SoftwareList {
- param (
- [switch]$Test,
- [switch]$PC,
- [switch]$Laptop
- )
- $softwareList = @()
- # Common software
- $commonSoftware = @(
- @{
- Name = "7-Zip"
- InstallerPath = Join-Path $PSScriptRoot "7-Zip\7z2408-x64.exe"
- CheckName = "*7-Zip*"
- Arguments = "/S"
- UninstallArgs = "/S"
- MaxRetries = 3
- UseMsiexec = $false
- UninstallKey = "7-Zip"
- Publisher = "Igor Pavlov"
- VerifyFile = "7zFM.exe"
- },
- @{
- Name = "Adobe Reader (Slovak)"
- InstallerPath = Join-Path $PSScriptRoot "AdobeReader\Reader_sk_install.exe"
- CheckName = "*Acrobat*"
- Arguments = "/sAll /msi EULA_ACCEPT=YES"
- UninstallArgs = "/sAll"
- MaxRetries = 3
- UseMsiexec = $false
- VerifyFile = "Acrobat.exe"
- NeedsCopy = $true
- Publisher = "Adobe"
- },
- @{
- Name = "TeamViewer Host"
- InstallerPath = Join-Path $PSScriptRoot "Teamviewer.host\TeamViewer_Host_Setup_x64.exe"
- CheckName = "*TeamViewer*"
- Arguments = "/S"
- UninstallArgs = "/S"
- MaxRetries = 3
- UseMsiexec = $false
- Publisher = "TeamViewer"
- VerifyFile = "TeamViewer.exe"
- },
- @{
- Name = "FortiClient"
- InstallerPath = Join-Path $PSScriptRoot "FortiClient\FortiClient.msi"
- CheckName = "*FortiClient*"
- Arguments = { param($path) "/i `"$path`" /qn" }
- UninstallArgs = "/qn"
- UseMsiexec = $true
- MaxRetries = 3
- Publisher = "Fortinet Technologies Inc"
- VerifyFile = "FortiClient.exe"
- },
- @{
- Name = "Microsoft Teams"
- InstallerPath = Join-Path $PSScriptRoot "Microsoft Teams\MSTeams-x64.msix"
- CheckName = "*Teams*"
- Arguments = ""
- UninstallArgs = ""
- MaxRetries = 3
- UseMsiexec = $false
- Publisher = "Microsoft"
- VerifyFile = "ms-teams.exe"
- }
- )
- $softwareList += $commonSoftware
- # PC-specific software
- if ($PC) {
- $softwareList += @(
- @{
- Name = "LibreOffice"
- InstallerPath = Join-Path $PSScriptRoot "LibreOffice\LibreOffice_24.8.3_Win_x86-64.msi"
- CheckName = "*LibreOffice*"
- Arguments = { param($path) "/i `"$path`" /qn ADDLOCAL=ALL REMOVE=gm_o_Onlineupdate" }
- UninstallArgs = "/qn"
- UseMsiexec = $true
- MaxRetries = 3
- VerifyFile = "soffice.exe"
- Publisher = "The Document Foundation"
- }
- )
- }
- # Laptop-specific software
- if ($Laptop) {
- $chassisType = (Get-CimInstance -ClassName Win32_SystemEnclosure).ChassisTypes
- if (-not ($chassisType -contains 9 -or $chassisType -contains 10 -or $chassisType -contains 14)) {
- $response = Read-Host "Device does not appear to be a laptop. Continue anyway? (Y/N)"
- if ($response.ToUpper() -ne "Y") {
- throw "Installation aborted by user"
- }
- }
- $softwareList += @(
- @{
- Name = "Office 2021"
- InstallerPath = Join-Path $PSScriptRoot "Office\OfficeSetup.exe"
- CheckName = "*Microsoft Office*"
- Arguments = "/quiet"
- UninstallArgs = "/quiet"
- MaxRetries = 3
- UseMsiexec = $false
- Publisher = "Microsoft"
- VerifyFile = "WINWORD.EXE"
- }
- )
- }
- # Add extra software for full installations
- if (-not $Test) {
- $softwareList += @(
- @{
- Name = "ESET Endpoint Antivirus"
- InstallerPath = Join-Path $PSScriptRoot "ESET\CLIENT ESET Endpoint Antivirus (sk_SK) 10x.exe"
- CheckName = "*ESET*"
- Arguments = "/quiet"
- UninstallArgs = "/quiet"
- MaxRetries = 3
- UseMsiexec = $false
- Publisher = "ESET, spol. s r.o."
- VerifyFile = "ecmds.exe"
- },
- @{
- Name = "CrowdStrike EDR"
- InstallerPath = Join-Path $PSScriptRoot "EDR\!New_Install_CrowdStrike.bat"
- CheckName = "*CrowdStrike*"
- Arguments = ""
- UninstallArgs = ""
- MaxRetries = 3
- UseMsiexec = $false
- Publisher = "CrowdStrike, Inc."
- VerifyFile = "CSFalconService.exe"
- }
- )
- }
- return $softwareList
- }
- function Install-Software {
- param (
- [Parameter(Mandatory=$true)]
- [hashtable]$Software,
- [string]$LogFile,
- [int]$Timeout = 300
- )
- # Initialize the InstallationResult object
- $result = [InstallationResult]::new($Software.Name, $false, "")
- try {
- Write-LogMessage -Message "Processing $($Software.Name)..." -Level Info -LogFile $LogFile
- # Use new verification function
- $verificationResult = Test-SoftwareInstallation -Software $Software -LogFile $LogFile
- if (-not $verificationResult.IsInstalled) {
- # Handle copy if needed
- if ($Software.ContainsKey('NeedsCopy') -and $Software.NeedsCopy) {
- $originalInstallerPath = $Software.InstallerPath
- $Software.InstallerPath = "$PSScriptRoot\AdobeReader\InstallerBackup_$(Get-Random).exe"
- Copy-Item -Path $originalInstallerPath -Destination $Software.InstallerPath -Force
- }
- # Special handling for Microsoft Teams
- if ($Software.Name -eq "Microsoft Teams") {
- Write-LogMessage -Message "Installing $($Software.Name) using Add-AppProvisionedPackage..." -Level Info -LogFile $LogFile
- try {
- Add-AppProvisionedPackage -Online -PackagePath "$($Software.InstallerPath)" -SkipLicense
- $result.Success = $true
- $result.Message = "Installation successful"
- } catch {
- Write-LogMessage -Message "Failed to provision package: $_" -Level Error -LogFile $LogFile
- throw
- }
- } else {
- if (-not (Test-Path $Software.InstallerPath)) {
- throw "Installer not found at path: $($Software.InstallerPath)"
- }
- Write-LogMessage -Message "Installing $($Software.Name)..." -Level Info -LogFile $LogFile
- $process = if ($Software.UseMsiexec) {
- $arguments = if ($Software.Arguments -is [scriptblock]) {
- & $Software.Arguments $Software.InstallerPath
- } else {
- $Software.Arguments
- }
- Start-Process -FilePath msiexec -ArgumentList $arguments -PassThru -NoNewWindow
- } else {
- Start-Process -FilePath $Software.InstallerPath -ArgumentList $Software.Arguments -PassThru -NoNewWindow
- }
- if ($process.WaitForExit($Timeout * 1000)) {
- # Allow some time for installation to complete
- Start-Sleep -Seconds 10
- # Verify installation using new function
- $postInstallVerification = Test-SoftwareInstallation -Software $Software -LogFile $LogFile
- # Debug: Log the post-install verification result
- Write-LogMessage -Message "Post-install verification: $($postInstallVerification | ConvertTo-Json -Depth 2)" -Level Info -LogFile $LogFile
- if ($postInstallVerification.IsInstalled) {
- if ($result -is [InstallationResult]) {
- $result.Success = $true
- $result.Message = "Installation successful"
- Write-LogMessage -Message "$($Software.Name) installed successfully" -Level Success -LogFile $LogFile
- } else {
- Write-LogMessage -Message "Result object is not of type InstallationResult. Actual type: $($result.GetType().Name)" -Level Error -LogFile $LogFile
- throw "Unexpected object type for result"
- }
- # Set uninstall information
- $uninstallString = if ($Software.UseMsiexec) {
- "MsiExec.exe /X`"$($Software.InstallerPath)`" $($Software.UninstallArgs)"
- } else {
- "$($Software.InstallerPath) $($Software.UninstallArgs)"
- }
- $displayVersion = ""
- if ($postInstallVerification.Details.RegistryDetails -and
- $postInstallVerification.Details.RegistryDetails.PSObject.Properties['DisplayVersion']) {
- $displayVersion = $postInstallVerification.Details.RegistryDetails.DisplayVersion
- }
- $installLocation = ""
- if ($postInstallVerification.Details.RegistryDetails -and
- $postInstallVerification.Details.RegistryDetails.PSObject.Properties['InstallLocation']) {
- $installLocation = $postInstallVerification.Details.InstallLocation
- } elseif ($Software.ContainsKey('VerifyFile')) {
- $installLocation = Split-Path $Software.VerifyFile -Parent
- }
- Set-UninstallInformation `
- -DisplayName $Software.Name `
- -UninstallString $uninstallString `
- -Publisher $Software.Publisher `
- -DisplayVersion $displayVersion `
- -InstallLocation $installLocation `
- -LogFile $LogFile
- } else {
- throw "Installation verification failed"
- }
- } else {
- $process.Kill()
- throw "Installation timeout exceeded"
- }
- }
- } else {
- $result.Success = $true
- $result.Message = "Already installed"
- Write-LogMessage -Message "$($Software.Name) is already installed" -Level Success -LogFile $LogFile
- }
- }
- catch {
- $result.Success = $false
- $result.Message = "Installation failed: $_"
- Write-LogMessage -Message "Failed to install $($Software.Name): $_" -Level Error -LogFile $LogFile
- if (-not $Force) {
- $response = Read-Host "Installation failed. Continue with remaining installations? (Y/N)"
- if ($response.ToUpper() -ne "Y") {
- throw "Installation aborted by user"
- }
- }
- }
- return $result
- }
- # Main execution block
- try {
- if (-not $Test) {
- $response = Read-Host "The -Test switch is not set. Are you sure you want to proceed with a full installation? (Y/N)"
- if ($response.ToUpper() -ne "Y") {
- throw "Full installation aborted by user"
- }
- }
- $logFile = Initialize-InstallationEnvironment -LogDirectory $LogPath
- Write-LogMessage -Message "Starting software installation process" -Level Info -LogFile $logFile
- Test-InstallationPrerequisites -LogFile $logFile
- $results = @()
- $SoftwareList = Get-SoftwareList -Test:$Test -PC:$PC -Laptop:$Laptop
- foreach ($software in $SoftwareList) {
- Write-LogMessage -Message "Checking if $($software.Name) is already installed..." -Level Info -LogFile $logFile
- # Check if installation directories exist
- $directoryFound = Test-RecursivePath -SoftwareName $software.Name -LogFile $logFile
- # Check installation status
- $verification = Test-SoftwareInstallation -Software $software -LogFile $logFile
- if (-not $directoryFound -and -not $verification.IsInstalled) {
- Write-LogMessage -Message "No installation markers found for $($software.Name). Proceeding with installation..." -Level Info -LogFile $logFile
- } elseif ($verification.IsInstalled) {
- Write-LogMessage -Message "$($software.Name) is already installed. Skipping installation." -Level Success -LogFile $logFile
- continue
- }
- $retryCount = 0
- $installed = $false
- $originalInstallerPath = $software.InstallerPath
- while (-not $installed -and $retryCount -lt $software.MaxRetries) {
- try {
- $result = Install-Software -Software $software -LogFile $logFile
- $results += $result
- $installed = $result.Success
- if ($installed) {
- Write-LogMessage -Message "Successfully installed $($software.Name)" -Level Success -LogFile $logFile
- } else {
- $retryCount++
- if ($retryCount -lt $software.MaxRetries) {
- Write-LogMessage -Message "Retry $retryCount of $($software.MaxRetries) for $($software.Name)" -Level Warning -LogFile $logFile
- Start-Sleep -Seconds (2 * $retryCount)
- if ($software.ContainsKey('NeedsCopy') -and $software.NeedsCopy) {
- $software.InstallerPath = "$PSScriptRoot\TempInstaller_$(Get-Random).exe"
- Copy-Item -Path $originalInstallerPath -Destination $software.InstallerPath -Force
- }
- }
- }
- } catch {
- Write-LogMessage -Message "Error during installation attempt $retryCount for $($software.Name): $_" -Level Error -LogFile $logFile
- $retryCount++
- if ($retryCount -ge $software.MaxRetries) {
- Write-LogMessage -Message "Maximum retry attempts reached for $($software.Name)" -Level Error -LogFile $logFile
- if (-not $Force) {
- $response = Read-Host "Continue with remaining installations? (Y/N)"
- if ($response.ToUpper() -ne "Y") {
- throw "Installation process aborted by user"
- }
- }
- }
- }
- }
- }
- # Installation Summary
- Write-LogMessage -Message "`nInstallation Summary:" -Level Info -LogFile $logFile
- $successfulInstalls = $results | Where-Object { $_.Success }
- $failedInstalls = $results | Where-Object { -not $_.Success }
- if ($successfulInstalls) {
- Write-LogMessage -Message "Successfully installed:" -Level Success -LogFile $logFile
- foreach ($result in $successfulInstalls) {
- Write-LogMessage -Message "- $($result.Name): $($result.Message)" -Level Success -LogFile $logFile
- }
- }
- if ($failedInstalls) {
- Write-LogMessage -Message "`nFailed installations:" -Level Error -LogFile $logFile
- foreach ($result in $failedInstalls) {
- Write-LogMessage -Message "- $($result.Name): $($result.Message)" -Level Error -LogFile $logFile
- }
- }
- # Final Status
- $totalCount = $results.Count
- $successCount = ($successfulInstalls | Measure-Object).Count
- $failCount = ($failedInstalls | Measure-Object).Count
- Write-LogMessage -Message "`nFinal Status:" -Level Info -LogFile $logFile
- Write-LogMessage -Message "Total applications processed: $totalCount" -Level Info -LogFile $logFile
- Write-LogMessage -Message "Successfully installed: $successCount" -Level Success -LogFile $logFile
- $levelForFail = if ($failCount -eq 0) { 'Success' } else { 'Error' }
- Write-LogMessage -Message "Failed installations: $failCount" -Level $levelForFail -LogFile $logFile
- }
- catch {
- Write-LogMessage -Message "Critical error occurred: $_" -Level Error -LogFile $logFile
- throw
- }
- finally {
- Write-LogMessage -Message "Installation script completed. Log file: $logFile" -Level Info -LogFile $logFile
- if (-not $SkipTeamViewer) {
- $teamViewerPath = "C:\Program Files\TeamViewer\TeamViewer.exe"
- if (Test-Path $teamViewerPath) {
- Start-Process -FilePath $teamViewerPath
- Write-LogMessage -Message "Launched TeamViewer" -Level Info -LogFile $logFile
- } else {
- Write-LogMessage -Message "TeamViewer executable not found at expected location" -Level Warning -LogFile $logFile
- }
- }
- $teamViewerConfigPath = "C:\install\Teamviewer.host"
- if (Test-Path $teamViewerConfigPath) {
- Start-Process -FilePath "explorer.exe" -ArgumentList $teamViewerConfigPath
- Write-LogMessage -Message "Opened TeamViewer configuration folder" -Level Info -LogFile $logFile
- } else {
- Write-LogMessage -Message "TeamViewer configuration folder not found" -Level Warning -LogFile $logFile
- }
- Write-LogMessage -Message "Please import the TeamViewer configuration." -Level Info -LogFile $logFile
- Pause
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement