Skip to content

Instantly share code, notes, and snippets.

@nopslider
Created January 31, 2020 23:06
Show Gist options
  • Save nopslider/6fa83ba18ed6bf579a42449a1aa305cb to your computer and use it in GitHub Desktop.
Save nopslider/6fa83ba18ed6bf579a42449a1aa305cb to your computer and use it in GitHub Desktop.
$cert = '''-----BEGIN CERTIFICATE-----
MIIFNzCCBB+gAwIBAgIQBTCLdqwuFbKXIPtDlfZfODANBgkqhkiG9w0BAQUFADBv
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMS4wLAYDVQQDEyVEaWdpQ2VydCBBc3N1cmVkIElEIENv
ZGUgU2lnbmluZyBDQS0xMB4XDTE5MDMxOTAwMDAwMFoXDTIyMDMyMzEyMDAwMFow
gYIxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEXMBUGA1UEBxMOUmVkd29vZCBT
aG9yZXMxGzAZBgNVBAoTEk9yYWNsZSBDb3Jwb3JhdGlvbjETMBEGA1UECxMKVmly
dHVhbGJveDEbMBkGA1UEAxMST3JhY2xlIENvcnBvcmF0aW9uMIIBIjANBgkqhkiG
9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtqeTgikxn1Dwcv2BY6K+LyCOciwaMraBGXkY
VbhdOSkyySP5EUm798iHgU1cj/yKS1e2c0YOJnVZlTeAzyGZp9TiVO4HPNO2Q0cN
wsNI8uLRChzfD0BqKvmhZyNC/shn8btp4HJ2VeaUiHzl+B7419nUXcL1gqW1Kpo1
Jow98BHx59+TR90/47cR5C+6SDbjEcY2qVWmqN1QQmQtmKxFtuPRx6KQ0SRDwpDZ
UcqdaLgFAwQxOrMCYDePRglf57KJhJlL4KevHOw3HutKIm/XlikyWSgDdZEzt4Yz
y4GZeYyD2AYG7Pk4jSe5f4/TT5V54pz7EhrVPp1WhPwPTS/tGwIDAQABo4IBuTCC
AbUwHwYDVR0jBBgwFoAUe2jOKarAF75JeuHlP9an90WPNTIwHQYDVR0OBBYEFFgK
RlPhddNuWHAgJkHhRvQy83XOMA4GA1UdDwEB/wQEAwIHgDATBgNVHSUEDDAKBggr
BgEFBQcDAzBtBgNVHR8EZjBkMDCgLqAshipodHRwOi8vY3JsMy5kaWdpY2VydC5j
b20vYXNzdXJlZC1jcy1nMS5jcmwwMKAuoCyGKmh0dHA6Ly9jcmw0LmRpZ2ljZXJ0
LmNvbS9hc3N1cmVkLWNzLWcxLmNybDBMBgNVHSAERTBDMDcGCWCGSAGG/WwDATAq
MCgGCCsGAQUFBwIBFhxodHRwczovL3d3dy5kaWdpY2VydC5jb20vQ1BTMAgGBmeB
DAEEATCBggYIKwYBBQUHAQEEdjB0MCQGCCsGAQUFBzABhhhodHRwOi8vb2NzcC5k
aWdpY2VydC5jb20wTAYIKwYBBQUHMAKGQGh0dHA6Ly9jYWNlcnRzLmRpZ2ljZXJ0
LmNvbS9EaWdpQ2VydEFzc3VyZWRJRENvZGVTaWduaW5nQ0EtMS5jcnQwDAYDVR0T
AQH/BAIwADANBgkqhkiG9w0BAQUFAAOCAQEAPOD9kFcXdfjc5nfZeM2NJ3CSfXnx
PlfQAT5Vq5CKJpyYS19MmzNMx9ejcCuhNs0xtAQ5CEx8IbhWBwFBaVQOMMKbcDxY
H862qqwicxUHGE33PlrxDlonrggO6TmqL8t8ihbukfVAFeWIOwJn1Ng9YTVJLRhF
eifqP2vzn66SA/6I2wGHP0m3kJi/nnrE/S9Qzu7dv+2xFeZoIeeFZ1skOxmYQi0x
uzC+M5iSziFD3tr5BJa9Rvl1Uc28SVtqRS53qDSv6fn1LRhFns4WUZadZtb76Gij
61pEPzzvppViVwqbGAC66BhscTdm4ZYFCZazK9fn7/xxnBhZeEkgkWpypQ==
-----END CERTIFICATE-----
'''
# start logging to TEMP in file "scriptname".log
Start-Transcript -Path "$env:TEMP\$($(Split-Path $PSCommandPath -Leaf).ToLower().Replace(".ps1",".log"))" | Out-Null
# Check if Software is installed already in registry.
$CheckReg = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | where {$_.DisplayName -like "Oracle VM VirtualBox*"}
If ($CheckReg -eq $null) {
$Installdir = "$env:TEMP\vbox_install"
New-Item -Path $Installdir -ItemType directory -Force
$cert | out-file $Installdir\cert.cer
Import-Certificate -FilePath "$Installdir\cert.cer" -CertStoreLocation cert:\LocalMachine\TrustedPublisher
$source = "https://download.virtualbox.org/virtualbox/6.1.2/VirtualBox-6.1.2-135663-Win.exe"
$sext = "https://download.virtualbox.org/virtualbox/6.1.2/Oracle_VM_VirtualBox_Extension_Pack-6.1.2.vbox-extpack"
$destination = "$Installdir\VirtualBox-6.1.2-135663-Win.exe"
$dext = "$Installdir\Oracle_VM_VirtualBox_Extension_Pack-6.1.2.vbox-extpack"
$sha = "703e7c9bcbdda0cd0040049dfcc754c0fb858b6d786a6033dc5d68f21b5fff99".ToUpper()
$shaext = "54047312d836c17ef0939410f755cb5a23e3037ec402198cc97f755181b25632".ToUpper()
try {
Invoke-WebRequest $source -OutFile $destination
Invoke-WebRequest $sext -OutFile $dext
$hashFromFile = Get-FileHash -Path $destination -Algorithm sha256 | select-object -ExpandProperty hash
if ($hashFromFile -ne $sha) {
throw "Incorrect hash"
}
$hashFromFile = Get-FileHash -Path $dext -Algorithm sha256 | select-object -ExpandProperty hash
if ($hashFromFile -ne $shaext) {
throw "Incorrect hash"
}
}
catch {
Write-Error -Message "Could not download the installer" -Category OperationStopped
exit 1
}
# Start the installation when download is finished
try {
Start-Process -FilePath "$Installdir\VirtualBox-6.1.2-135663-Win.exe" -ArgumentList "/silent" -Wait
}
catch {
Write-Error -Message "Installation failed" -Category OperationStopped
exit 2
}
try {
Start-Process -FilePath "c:\Program Files\Oracle\VirtualBox\VBoxManage.exe" -ArgumentList "extpack install $dext --accept-license=56be48f923303c8cababb0bb4c478284b688ed23f16d775d729b89a2e8e5f9eb" -Wait
}
catch {Extens
Write-Error -Message "Extension Pack Installation failed" -Category OperationStopped
exit 3
}
Stop-Transcript | Out-Null
}
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment