function Get-Boxstarter { # . { iwr -useb https://boxstarter.org/bootstrapper.ps1 } | iex; get-boxstarter -Force # # . C:\downloads_temp\bootstrapper-filename.ps1; iex Get-Boxstarter -Force Param( [string] $Version = "2.12.0", [switch] $Force ) $bootstrapperFile = ${function:Get-Boxstarter}.File Write-Host "#############################################################################################" Write-Host = "RUNNING: $bootstrapperFile" Write-Host "#############################################################################################" if(!(Test-Admin)) { # $bootstrapperFile = ${function:Get-Boxstarter}.File if($bootstrapperFile) { Write-Host "User is not running with administrative rights. Attempting to elevate..." $command = "-ExecutionPolicy bypass -noexit -command . '$bootstrapperFile';Get-Boxstarter $($args)" Start-Process powershell -verb runas -argumentlist $command } else { Write-Host "User is not running with administrative rights.`nPlease open a PowerShell console as administrator and try again." } return } $badPolicy = $false @("Restricted", "AllSigned") | ? { $_ -eq (Get-ExecutionPolicy).ToString() } | % { Write-Host "Your current PowerShell Execution Policy is set to '$(Get-ExecutionPolicy)' and will prohibit boxstarter from operating properly." Write-Host "Please use Set-ExecutionPolicy to change the policy to RemoteSigned or Unrestricted." $badPolicy = $true } if($badPolicy) { return } Write-Output "Welcome to the Boxstarter Module installer!" if(Check-Chocolatey -Force:$Force){ $message = "Chocolatey extensions..." Write-Host $message # configure license correctly # https://chocolatey.org/docs/installation-licensed # https://chocolatey.org/docs/features-install-directory-override $command = "choco install chocolatey.extension --install-directory=$env:ChocolateyToolsLocation -y" Invoke-Expression $command # Create python directory. Install to it. # New-Item c:\python -Force -type directory | Out-Null # $command = "choco install python --install-directory=c:\python -y" # Invoke-Expression $command $command = "choco list -lo" Invoke-Expression $command # Write-Output "Chocolatey installed, licensed, and configured. Boxstarter modules commented out." # Write-Output "Fin" Write-Output "Chocolatey installed, Installing Boxstarter Modules." # Alt+Shift, Shift+# $env:chocolateyVersion = 0.10.11 # $chocoVersion = "2.9.17" try { New-Object -TypeName Version -ArgumentList $chocoVersion.split('-')[0] | Out-Null $command = "cinst Boxstarter -y" } catch{ # if there is no -v then its an older version with no -y $command = "cinst Boxstarter" } $command += " --version $version" Invoke-Expression $command Import-Module "$env:ProgramData\boxstarter\boxstarter.chocolatey\boxstarter.chocolatey.psd1" -Force $Message = "Boxstarter Module Installer completed" } else { $Message = "Did not detect Chocolatey and unable to install. Installation of Boxstarter has been aborted." } if($Force) { Write-Host $Message } else { Read-Host $Message } } function Check-Chocolatey { Param( [switch] $Force ) $dirChocolateyInstall = "c:\choco" $dirChocolateyBinRoot = "$dirChocolateyInstall" $dirChocolateyLicense = "$dirChocolateyInstall\license" $dirChocolateyToolsLocation = "c:\tools" $fileChocolateyLicense = "$dirChocolateyLicense\chocolatey.license.xml" if(-not $env:ChocolateyInstall){ $env:ChocolateyInstall = "c:\choco" if(-not (Test-Path "$env:ChocolateyInstall")){ New-Item $env:ChocolateyInstall -Force -type directory | Out-Null } } if(-not $env:ChocolateyBinRoot){ $env:ChocolateyBinRoot = "$dirChocolateyBinRoot" } if(-not $env:ChocolateyToolsLocation){ $env:ChocolateyToolsLocation = "$dirChocolateyToolsLocation" if(-not (Test-Path "$env:ChocolateyToolsLocation")){ New-Item $env:ChocolateyToolsLocation -Force -type directory | Out-Null } } if(-not (Test-Path "$fileChocolateyLicense")){ Write-Host "COPY IN THE LICENSE" # Copy chocolatey license file Copy-Item -Path C:\downloads_temp\chocolatey.license.xml -Destination $fileChocolateyLicense } # TODO: Add cygwin, etc if(-not $env:ChocolateyInstall -or -not (Test-Path "$env:ChocolateyInstall\bin\choco.exe")){ $message = "Chocolatey not installed. Also .NET Framework Version 4 or greater." Write-Host $message if($Force -OR (Confirm-Install)){ $exitCode = Enable-Net40 if($exitCode -ne 0) { Write-Warning ".net install returned $exitCode. You likely need to reboot your computer before proceeding with the install." return $false } $message = "WOULD BE INSTALLING CHOCOLATEY" Write-Host $message # $message = "Chocolatey downloading..." # Write-Host $message # $url="https://chocolatey.org/api/v2/package/chocolatey/" # $wc=new-object net.webclient # $wp=[system.net.WebProxy]::GetDefaultProxy() # $wp.UseDefaultCredentials=$true # $wc.Proxy=$wp # $message = "Chocolatey installing..." # Write-Host $message # # install chocolatey # iex ($wc.DownloadString("https://chocolatey.org/install.ps1")) # $message = "Chocolatey added to bin.." # Write-Host $message # # add to path # $env:path="$env:path;$env:ChocolateyInstall\bin" # Write-Host "env: $env:path" } else{ return $false } } return $true } function Is64Bit { [IntPtr]::Size -eq 8 } function Enable-Net40 { Write-Host "Enable-Net40" if(Is64Bit) {$fx="framework64"} else {$fx="framework"} if(!(test-path "$env:windir\Microsoft.Net\$fx\v4.0.30319")) { Write-Host "Downloading .net 4.5..." Get-HttpToFile "https://download.microsoft.com/download/b/a/4/ba4a7e71-2906-4b2d-a0e1-80cf16844f5f/dotnetfx45_full_x86_x64.exe" "$env:temp\net45.exe" # Write-Host "Installing .net 4.5..." # $pinfo = New-Object System.Diagnostics.ProcessStartInfo # $pinfo.FileName = "$env:temp\net45.exe" # $pinfo.Verb="runas" # $pinfo.Arguments = "/quiet /norestart /log $env:temp\net45.log" # $p = New-Object System.Diagnostics.Process # $p.StartInfo = $pinfo # $p.Start() | Out-Null # $p.WaitForExit() # $e = $p.ExitCode if($e -ne 0){ Write-Host "Installer exited with $e" } return $e } return 0 } function Get-HttpToFile ($url, $file){ Write-Verbose "Downloading $url to $file" if(Test-Path $file){Remove-Item $file -Force} $downloader=new-object net.webclient $wp=[system.net.WebProxy]::GetDefaultProxy() $wp.UseDefaultCredentials=$true $downloader.Proxy=$wp try { $downloader.DownloadFile($url, $file) } catch{ if($VerbosePreference -eq "Continue"){ Write-Error $($_.Exception | fl * -Force | Out-String) } throw $_ } } function Confirm-Install { $caption = "Installing Chocolatey" $message = "Do you want to proceed?" $yes = new-Object System.Management.Automation.Host.ChoiceDescription "&Yes","Yes"; $no = new-Object System.Management.Automation.Host.ChoiceDescription "&No","No"; $choices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no); $answer = $host.ui.PromptForChoice($caption,$message,$choices,0) switch ($answer){ 0 {return $true; break} 1 {return $false; break} } } function Test-Admin { $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent() $principal = New-Object System.Security.Principal.WindowsPrincipal( $identity ) return $principal.IsInRole( [System.Security.Principal.WindowsBuiltInRole]::Administrator ) }