Created
April 13, 2015 21:04
-
-
Save p0w3rsh3ll/01b5babfa6ebf99d1160 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -Version 4.0 | |
#Requires -RunAsAdministrator | |
configuration RemoveEMET52 { | |
param | |
( | |
[string[]]$NodeName = 'localhost' | |
) | |
Node $NodeName | |
{ | |
Script DownloadEMET52 { | |
GetScript = { | |
@{ | |
GetScript = $GetScript | |
SetScript = $SetScript | |
TestScript = $TestScript | |
Result = $(Test-Path (Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath 'EMET 5.2 Setup.msi')); | |
} | |
} | |
SetScript = { | |
try { | |
$tmpfile = [System.IO.Path]::GetTempFileName() | |
$null = Invoke-WebRequest -Uri 'http://download.microsoft.com/download/7/0/A/70AF5150-10DD-4838-ACFC-C4390B05620A/EMET%205.2%20Setup.msi' ` | |
-OutFile $tmpfile -ErrorAction Stop | |
Write-Verbose -Message 'Sucessfully downloaded EMET 5.2 MSI Package' | |
Unblock-File -Path $tmpfile -ErrorAction Stop | |
$package = Join-Path -Path (Split-Path -Path $tmpfile -Parent) -ChildPath 'EMET 5.2 Setup.msi' -ErrorAction SilentlyContinue | |
if (Test-Path $package) { | |
Remove-Item -Path $package -Force -ErrorAction Stop | |
} | |
$tmpfile | Rename-Item -NewName 'EMET 5.2 Setup.msi' -Force -ErrorAction Stop | |
} catch { | |
Write-Verbose -Message "Something went wrong $($_.Exception.Message)" | |
} | |
} | |
TestScript = { | |
$MSI = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath 'EMET 5.2 Setup.msi' -ErrorAction SilentlyContinue | |
if (-not(Test-Path -Path $MSI -PathType Leaf)) { | |
return $false | |
} | |
if( | |
(Get-FileHash -Path $MSI -Algorithm SHA256).Hash -eq '7125CA4ACC33BDDF46657039277D8FDE752618A00B51604D2890E9E429EA4DD3' -and | |
(Get-AuthenticodeSignature -FilePath $MSI).Status.value__ -eq 0 # Valid | |
) { | |
Write-Verbose -Message 'Successfully found a valid signed EMET 5.2 package' | |
return $true | |
} else { | |
Write-Verbose -Message 'A valid signed package of EMET 5.2 was not found' | |
return $false | |
} | |
} | |
} | |
Package UninstallEMET52msi { | |
Name = 'EMET 5.2'; | |
Path = 'C:\Windows\Temp\EMET 5.2 Setup.msi'; | |
ProductId = '{F4DCB44D-F072-43A1-B4A5-57619C7B22D2}'; | |
Arguments = '/norestart' ; | |
Ensure = 'Absent'; | |
DependsOn = "[Script]DownloadEMET52" | |
} | |
} | |
} | |
if (-not(test-path -Path C:\DSC -PathType Container)){ | |
mkdir C:\DSC | |
} | |
# Compile the configuration file to a MOF format | |
RemoveEMET52 -OutputPath C:\DSC | |
# Run the configuration on localhost | |
Start-DscConfiguration -Path C:\DSC -ComputerName localhost -Verbose -Force -Wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment