Skip to content

Instantly share code, notes, and snippets.

@Hexalon
Last active July 20, 2016 16:09
Show Gist options
  • Save Hexalon/8b2b3cad46918d0bb504b44dc271d2cd to your computer and use it in GitHub Desktop.
Save Hexalon/8b2b3cad46918d0bb504b44dc271d2cd to your computer and use it in GitHub Desktop.
Automates installation of System Center Endpoint Protection.
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.2.123
Created on: 6/24/2016 10:24
Created by: Colin Squier <Hexalon@gmail.com>
Filename: Install-SCEP.ps1
===========================================================================
.DESCRIPTION
Automates installation of System Center Endpoint Protection.
#>
[CmdletBinding()]
Param (
[switch]$Uninstall = $false
)
<#
.SYNOPSIS
Returns the path of the executing script's directory.
.DESCRIPTION
Sapien's implementation of the variable $HostInvocation
causes a conflict the with the system's variable.
.EXAMPLE
PS C:\> Get-ScriptDirectory
.NOTES
Work around for handling Sapien's custom host environment.
#>
function Get-ScriptDirectory
{
if ($null -ne $HostInvocation)
{
Split-Path $HostInvocation.MyCommand.path
}
else
{
Split-Path $script:MyInvocation.MyCommand.Path
}
}
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"
Break
}
$Option = New-CimSessionOption -Protocol Dcom
$Session = New-CimSession -SessionOption $Option -ComputerName $env:COMPUTERNAME
$OS = (Get-CimInstance -ClassName Win32_OperatingSystem -CimSession $Session)
$OSVersion = $OS.Version
$scriptDirectory = Get-ScriptDirectory
$Source = (Split-Path -Path $scriptDirectory -Parent)
$PackagePath = (Join-Path -Path $Source -ChildPath "ComputerSetup\SCCM2012R2Client")
$File = "scepinstall.exe"
$PolicyFile = "ep_defaultpolicy.xml"
switch ($OSVersion)
{
"6.1.7601"
{
$Version = "4.7.214.0"
}
"10.0.10240"
{
$Version = "4.9.219.0"
}
"10.0.10586"
{
$Version = "4.9.219.0"
}
default
{
Write-Error -Message "The computer does not meet system requirements." -Category ResourceUnavailable
}
}
$Product = "System Center Endpoint Protection"
$FullPath = Join-Path -Path $PackagePath -ChildPath $File
$FullPolicyPath = Join-Path -Path $PackagePath -ChildPath $PolicyFile
$SCEP = (Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' | Where-Object { $_.DisplayName -eq $Product })
if ($Uninstall)
{
if (!($null -eq $SCEP))
{
$InstalledVersion = $SCEP.DisplayVersion
Write-Verbose -Message "Installed $Product version is $InstalledVersion"
$Removal = Start-Process -FilePath "`"$FullPath`"" -ArgumentList "/u /s /q" -Wait -Passthru -NoNewWindow
$ExitCode = $Removal.ExitCode
Write-Verbose -Message "$Product uninstaller exit code: $ExitCode"
If ($ExitCode -eq 0)
{
Write-Verbose -Message "Uninstall was successful."
}
}
else
{
Write-Verbose -Message "$Product has already been removed."
}
Remove-CimSession -CimSession $Session
break;
}
if (!($null -eq $SCEP))
{
$InstalledVersion = $SCEP.DisplayVersion
Write-Verbose "Installed $Product version is $InstalledVersion"
If ([version]$InstalledVersion -ge $Version)
{
Write-Verbose "$Product version $InstalledVersion or later already installed."
}
}
if ($null -eq $InstalledVersion -or [version]$InstalledVersion -lt $Version)
{
Write-Verbose "Installing $Product $Version"
$SCEP = Start-Process -FilePath "`"$FullPath`"" -ArgumentList "/s /q /policy `"$FullPolicyPath`"" -Wait -Passthru -NoNewWindow
$ExitCode = $SCEP.ExitCode
Write-Verbose "$Product installer exit code: $ExitCode"
}
Remove-CimSession -CimSession $Session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment