Skip to content

Instantly share code, notes, and snippets.

@tdewin
Created February 15, 2019 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdewin/c2b48df494a219831cd25c0087893df6 to your computer and use it in GitHub Desktop.
Save tdewin/c2b48df494a219831cd25c0087893df6 to your computer and use it in GitHub Desktop.
#auto install
<# plan_vbo365.json sample :
{
"license": { "src":"veeam_backup_microsoft_office_nfr_50.lic" },
"steps": [
{
"src":"Veeam.Backup365_2.0.0.567.msi",
"install":"__file__",
"arguments":[
"/qn",
"/log __log__"
]
},
{
"src":"VeeamExplorerForExchange_9.6.3.567.msi",
"install":"__file__",
"arguments":[
"/qn",
"/log __log__"
],
"disabled":1
},
{
"src":"VeeamExplorerForSharePoint_9.6.3.568.msi",
"install":"__file__",
"arguments":[
"/qn",
"/log __log__"
],
"disabled":1
},
{
"src":"VBO2.0-KB2809.msp",
"install":"__file__",
"arguments":[
"/qn",
"/log __log__"
]
},
{
"src":"VeeamExplorerForSharePoint.msi",
"install":"__file__",
"arguments":[
"/qn",
"/log __log__"
]
},
{
"src":"VeeamExplorerForExchange.msi",
"install":"__file__",
"arguments":[
"/qn",
"/log __log__"
]
}
]
}
#>
$baseurl = "http://192.168.1.169/redistr"
function log {
param($logline)
write-host ("[{0}] - {1}" -f (get-date).ToString("yyyyMMdd - hh:mm:ss"),$logline)
}
function urlfile {
param ($baseurl,$file)
return ("{0}/{1}" -f $baseurl,$file)
}
function replaceenv {
param( $line, $file, $log)
$line = $line -replace "__file__",$file
$line = $line -replace "__log__",$log
return $line
}
function install {
param ($baseurl,$hostname)
$index = (wget ( urlfile -baseurl $baseurl -file plan_vbo365.json)).content
$json = @($index | ConvertFrom-Json)[0]
$steps = $json.steps
$tmp = Join-Path -Path $env:TEMP -ChildPath "VeeamDownload"
mkdir $tmp -Force -ErrorAction SilentlyContinue | Out-Null
if ($steps.Count -gt 3) {
foreach($step in $steps) {
if ($step.disabled -and $step.disabled -eq 1 ) {
log(("Disabled step detected {0}" -f $step.src))
} else {
$src = ("{0}" -f $step.src)
$tmpfile = Join-Path -Path $tmp -ChildPath $src
$tmplog = Join-Path -Path $tmp -ChildPath "$src.log"
wget -Uri (urlfile -baseurl $baseurl -file $src ) -OutFile $tmpfile
log($tmpfile)
$installline = replaceenv -line $step.install -file $tmpfile -log $tmplog
$rebuildargs = @()
foreach($pa in $step.arguments) {
$rebuildargs += ((replaceenv -line $pa -file $tmpfile -log $tmplog))
}
log("Installing now:")
log($installline)
log($rebuildargs -join ",")
Start-Process -FilePath $installline -ArgumentList $rebuildargs -Wait
}
}
& 'C:\Program Files\Veeam\Backup365\Initialize-VBOToolkit.ps1'
if ($json.license -and $json.license.src) {
$tmpfile = Join-Path -Path $tmp -ChildPath $json.license.src
wget -Uri (urlfile -baseurl $baseurl -file $json.license.src ) -OutFile $tmpfile
Install-VBOLicense -Path $tmpfile
}
$cert = New-SelfSignedCertificate -subject $hostname -NotAfter (Get-Date).AddYears(10) -KeyDescription "Auto Install Magic Glue" -KeyFriendlyName "Auto Install Magic Glue"
$certfile = (join-path $tmp "cert.pfx")
$certpassword = ConvertTo-SecureString -String “tmpunsecure” -Force –AsPlainText
Export-PfxCertificate -Cert $cert -FilePath $certfile -Password $certpassword
Set-VBORestAPISettings -EnableService -CertificateFilePath $certfile -CertificatePassword $certpassword
} else {
log("didn't find plan_vbo365.json on $baseurl")
}
}
function createlocaladmin {
param($user,$password)
$Computer = [ADSI]"WinNT://$Env:COMPUTERNAME,Computer"
$LocalAdmin = $Computer.Create("User", $user)
$LocalAdmin.SetPassword($password)
$LocalAdmin.SetInfo()
$LocalAdmin.FullName = "REST User for Magic Glue"
$LocalAdmin.SetInfo()
$LocalAdmin.UserFlags = 64 + 65536 # ADS_UF_PASSWD_CANT_CHANGE + ADS_UF_DONT_EXPIRE_PASSWD
$LocalAdmin.SetInfo()
Add-LocalGroupMember -Group "Administrators" -Member $user
}
install -baseurl $baseurl -hostname ([System.Net.Dns]::GetHostEntry([string]$env:computername).hostname)
$pass = [string]([System.Guid]::NewGuid().Guid)
log($pass)
createlocaladmin -user "restuser" -password $pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment