Scripts/Install-OSDUpdateMcAfee.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#Requires -Version 5

<#
.SYNOPSIS
    Installs McAfee SuperDAT v2 renamed to xdat.exe
 
.DESCRIPTION
    Installs McAfee SuperDAT v2 renamed to xdat.exe
 
.NOTES
    Author: David Segura
    Website: osdeploy.com
    Twitter: @SeguraOSD
    Version: 21.1.7.2
#>

#======================================================================================
# Validate Admin Rights
#======================================================================================
Write-Host ""
# Verify Running as Admin
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
If (!( $isAdmin )) {
    Write-Host "Checking User Account Control settings ..." -ForegroundColor Green
    if ((Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System).EnableLUA -eq 0) {
        #UAC Disabled
        Write-Host '========================================================================================' -ForegroundColor DarkGray
        Write-Host "User Account Control is Disabled ... " -ForegroundColor Green
        Write-Host "You will need to correct your UAC Settings ..." -ForegroundColor Green
        Write-Host "Try running this script in an Elevated PowerShell session ... Exiting" -ForegroundColor Green
        Write-Host '========================================================================================' -ForegroundColor DarkGray
        Start-Sleep -s 10
        Exit 0
    } else {
        #UAC Enabled
        Write-Host "UAC is Enabled" -ForegroundColor Green
        Start-Sleep -s 3
        if ($Silent) {
            Write-Host "-- Restarting as Administrator (Silent)" -ForegroundColor Cyan ; Start-Sleep -Seconds 1
            Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" -Silent" -Verb RunAs -Wait
        } elseif($Restart) {
            Write-Host "-- Restarting as Administrator (Restart)" -ForegroundColor Cyan ; Start-Sleep -Seconds 1
            Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" -Restart" -Verb RunAs -Wait
        } else {
            Write-Host "-- Restarting as Administrator" -ForegroundColor Cyan ; Start-Sleep -Seconds 1
            Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs -Wait
        }
        Exit 0
    }
} else {
    Write-Host '========================================================================================' -ForegroundColor DarkGray
    Write-Host "-- Running with Elevated Permissions ..." -ForegroundColor Cyan ; Start-Sleep -Seconds 1
    Write-Host '========================================================================================' -ForegroundColor DarkGray
}
#======================================================================================
# Script Information
#======================================================================================
$Invocation = (Get-Variable MyInvocation -Scope Script).Value
$ScriptPath = Split-Path -Parent $Invocation.MyCommand.Path
$ParentName = Split-Path $ScriptPath -Leaf
#======================================================================================
# Logs
#======================================================================================
$OSDAppName = "OSDUpdate-$ParentName"
$OSDLogs = "$env:Temp"
if (!(Test-Path $OSDLogs)) {New-Item $OSDLogs -ItemType Directory -Force | Out-Null}
$OSDLogName = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$OSDAppName.log"
Start-Transcript -Path (Join-Path $OSDLogs $OSDLogName)
#======================================================================================
# Start Script
#======================================================================================
Write-Host "Start ... $(Join-Path $PSScriptRoot $MyInvocation.MyCommand.Name)" -ForegroundColor Green
Write-Host ""
#======================================================================================
# OS Information
#======================================================================================
$OSCaption = $((Get-WmiObject -Class Win32_OperatingSystem).Caption).Trim()
$OSArchitecture = $((Get-WmiObject -Class Win32_OperatingSystem).OSArchitecture).Trim()
$OSProductType = $((Get-WmiObject -Class Win32_OperatingSystem).ProductType)
$OSVersion = $((Get-WmiObject -Class Win32_OperatingSystem).Version).Trim()
$OSBuildNumber = $((Get-WmiObject -Class Win32_OperatingSystem).BuildNumber).Trim()
Write-Host "Operating System: $OSCaption" -ForegroundColor Cyan
Write-Host "OS Architecture: $OSArchitecture" -ForegroundColor Cyan
Write-Host "OS ProductType: $OSProductType" -ForegroundColor Cyan
Write-Host "OS Version: $OSVersion" -ForegroundColor Cyan
Write-Host "OS Build Number: $OSBuildNumber" -ForegroundColor Cyan
if ($OSVersion -Like "10*") {
    $OSReleaseID = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ReleaseId).ReleaseId
    Write-Host "OS Release ID: $OSReleaseID" -ForegroundColor Cyan
}
#======================================================================================
# Begin
#======================================================================================
Write-Host "Updating McAfee xDAT Signatures" -ForegroundColor Green
#======================================================================================
# Validate McAfee SuperDAT v2
#======================================================================================
if (Test-Path "$PSScriptRoot\xdat.exe") {
    $Software = "McAfee VirusScan"
    $Installed = Get-ItemProperty ('HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*','HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*') -EA SilentlyContinue | Where-Object { $_.DisplayName -like "*$Software*" }
    #======================================================================================
    # Execute
    #======================================================================================
    If ($null -eq $Installed) {
        Write-Warning "McAfee VirusScan is not installed"
    } else {
        Write-Host "Installing McAfee xDAT" -ForegroundColor Cyan
        if (!(Test-Path "$env:Temp\McAfee\xDAT")) {
            New-Item "$env:Temp\McAfee\xDAT" -ItemType Directory -Force | Out-Null
        }
        Copy-Item "$PSScriptRoot\xdat.exe" "$env:Temp\McAfee\xDAT" -Force | Out-Null
        Start-Process "$env:Temp\McAfee\xDAT\xdat.exe" -ArgumentList '/SILENT','/F' -Wait
    }
}
#======================================================================================
# Validate McAfee SuperDAT v3
#======================================================================================
if (Test-Path "$PSScriptRoot\V3_xdat.exe") {
    $Software = "McAfee Endpoint Security Threat Prevention"
    $Installed = Get-ItemProperty ('HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*','HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*') -EA SilentlyContinue | Where-Object { $_.DisplayName -like "*$Software*" }
    #======================================================================================
    # Execute
    #======================================================================================
    If ($null -eq $Installed) {
        Write-Warning "McAfee Endpoint Security is not installed"
    } else {
        Write-Host "Installing McAfee xDAT" -ForegroundColor Cyan
        if (!(Test-Path "$env:Temp\McAfee\xDAT")) {
            New-Item "$env:Temp\McAfee\xDAT" -ItemType Directory -Force | Out-Null
        }
        Copy-Item "$PSScriptRoot\V3_xdat.exe" "$env:Temp\McAfee\xDAT" -Force | Out-Null
        Start-Process "$env:Temp\McAfee\xDAT\V3_xdat.exe" -ArgumentList '/SILENT','/F' -Wait
    }
}
#======================================================================================
# Complete
#======================================================================================
Write-Host ""
Write-Host "Complete ... $(Join-Path $PSScriptRoot $MyInvocation.MyCommand.Name)" -ForegroundColor Green
Stop-Transcript
Start-Sleep 5