bootstrap.ps1

#Requires -Version 3 <# 2018-12-11 LSKP(A)ITADEL.DK #> #Variables $currentTime = (Get-Date -Format dd-MM-yyThh-mm-ss) $webClient = New-Object -TypeName System.Net.WebClient $itadelDir = $env:windir + '\ITADEL' $logsDir = $itadelDir + '\Logs' $scriptsDir = $itadelDir + '\Scripts' $logFile = $logsDir + ('\{0}_Bootstrap' -f $currentTime) + '.log' $script1 = $scriptsDir + '\phase1.ps1' $script2 = $scriptsDir + '\phase2.ps1' $url1 = 'https://gist.githubusercontent.com/itadel/ea73fe0bba4954f250553a9efeb61e72/raw/efacf12a1c980c5f28995c204537aab1bc65806b/phase1.ps1' $url2 = 'https://gist.githubusercontent.com/itadel/59ce2cab78cd830fb13c9988d9a1c3ff/raw/fc0605c6a73f1d8a2cec47eca5fec47f44a3bef6/phase2.ps1' $ErrorActionPreference = 'SilentlyContinue' $oldverbose = $VerbosePreference $VerbosePreference = 'Continue' #Create folders If (!(Test-Path -Path $logsDir)) { Write-Output -InputObject ('Create the folder {0}' -f $logsDir) $null = New-Item -Path ('{0}' -f $logsDir) -ItemType Directory -Force Test-Path -Path ('{0}' -f $logsDir) } If (!(Test-Path -Path $scriptsDir)) { Write-Output -InputObject ('Create the folder {0}' -f $scriptsDir) $null = New-Item -Path ('{0}' -f $scriptsDir) -ItemType Directory -Force Test-Path -Path ('{0}' -f $scriptsDir) } #Start logging Try { Start-Transcript -Path $logFile -Append -Force } Catch { Stop-Transcript Start-Transcript -Path $logFile -Append -Force } #Download scripts Write-Output -InputObject ('Download the file {0} to {1}' -f $url1, $script1) $webClient.DownloadFile(('{0}' -f $url1), ('{0}' -f $script1)) Test-Path -Path ('{0}' -f $script1) Write-Output -InputObject ('Download the file {0} to {1}' -f $url2, $script2) $webClient.DownloadFile(('{0}' -f $url2), ('{0}' -f $script2)) Test-Path -Path ('{0}' -f $script2) #Run script Write-Output -InputObject ('Run the script {0}' -f $script1) . ('{0}' -f $script1) #Stop logging Stop-Transcript $VerbosePreference = $oldverbose

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.