Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

PowerShell – Download/Install/Configure Nexus

Posted on March 7, 2016March 8, 2016 By David Kittell

This script is best followed by PowerShell – Java JDK/JRE Unattended Install as you need Java JDK installed.

# Nexus Download Link: http://www.sonatype.org/downloads/nexus-latest-bundle.zip

clear
 
# URL Parameter
$WebURL = "http://www.sonatype.org/downloads/nexus-latest-bundle.zip"
 
# Directory Parameter
$FileDirectory = "$($env:USERPROFILE)$("\downloads\")"

#Write-Output $FileDirectory

# If directory doesn't exist create the directory
if((Test-Path $FileDirectory) -eq 0)
    {
        mkdir $FileDirectory;
    }

# We assume the file you download is named what you want it to be on your computer
$FileName = [System.IO.Path]::GetFileName($WebURL)

# Concatenate the two values to prepare the download
$FullFilePath = "$($FileDirectory)$($FileName)"

#Write-Output $FullFilePath

function Get-FileDownload([String] $WebURL, [String] $FullFilePath)
{
        # Give a basic message to the user to let them know what we are doing
        Write-Output "Downloading '$WebURL' to '$FullFilePath'"

        $uri = New-Object "System.Uri" "$WebURL"
        $request = [System.Net.HttpWebRequest]::Create($uri) 
        $request.set_Timeout(30000) #15 second timeout 
        $response = $request.GetResponse() 
        $totalLength = [System.Math]::Floor($response.get_ContentLength()/1024) 
        $responseStream = $response.GetResponseStream() 
        $targetStream = New-Object -TypeName System.IO.FileStream -ArgumentList $FullFilePath, Create 
        $buffer = new-object byte[] 10KB 
        $count = $responseStream.Read($buffer,0,$buffer.length) 
        $downloadedBytes = $count
        while ($count -gt 0) 
            { 
                [System.Console]::Write("`r`nDownloaded {0}K of {1}K", [System.Math]::Floor($downloadedBytes/1024), $totalLength) 
                $targetStream.Write($buffer, 0, $count) 
                $count = $responseStream.Read($buffer,0,$buffer.length) 
                $downloadedBytes = $downloadedBytes + $count
            } 
        
        $targetStream.Flush()
        $targetStream.Close() 
        $targetStream.Dispose() 
        $responseStream.Dispose() 
        
        # Give a basic message to the user to let them know we are done
        Write-Output "`r`nDownload complete"
    }

function Expand-ZipFile([string]$File, [string]$Destination) #The targets to run.
{
    # If directory doesn't exist create the directory
    if((Test-Path $Destination) -eq 0)
    {
        mkdir $Destination;      
    }

    $Shell = new-object -com shell.application
 
    # Get the name of the Zip file
    $Zip = $Shell.NameSpace($File)
 
    #Expand/Extract each file from the zip file
    foreach($Item in $Zip.items())
        {
            $Shell.Namespace($Destination).copyhere($Item)
        }
}

Get-FileDownload $WebURL  $FullFilePath

Expand-ZipFile $FullFilePath c:\Nexus



cd C:\Nexus

$NexusFolder = (Get-ChildItem nexus* | Select Name).Name

# Create System Variable
[Environment]::SetEnvironmentVariable("NEXUS_HOME", "C:\Nexus\$NexusFolder", "Machine")

cd "C:\Nexus\$NexusFolder"

# Configure C:\Nexus\nexus-2.12.0-01\conf\nexus.properties
#     Set Port Number if you want something other than 8081

cd bin
# Nexus Download Link: http://www.sonatype.org/downloads/nexus-latest-bundle.zip
 
clear
  
# URL Parameter
$WebURL = "http://www.sonatype.org/downloads/nexus-latest-bundle.zip"
  
# Directory Parameter
$FileDirectory = "$($env:USERPROFILE)$("\downloads\")"
 
#Write-Output $FileDirectory
 
# If directory doesn't exist create the directory
if((Test-Path $FileDirectory) -eq 0)
    {
        mkdir $FileDirectory;
    }
 
# We assume the file you download is named what you want it to be on your computer
$FileName = [System.IO.Path]::GetFileName($WebURL)
 
# Concatenate the two values to prepare the download
$FullFilePath = "$($FileDirectory)$($FileName)"
 
#Write-Output $FullFilePath
 
function Get-FileDownload([String] $WebURL, [String] $FullFilePath)
{
        # Give a basic message to the user to let them know what we are doing
        Write-Output "Downloading '$WebURL' to '$FullFilePath'"
 
        $uri = New-Object "System.Uri" "$WebURL"
        $request = [System.Net.HttpWebRequest]::Create($uri) 
        $request.set_Timeout(30000) #15 second timeout 
        $response = $request.GetResponse() 
        $totalLength = [System.Math]::Floor($response.get_ContentLength()/1024) 
        $responseStream = $response.GetResponseStream() 
        $targetStream = New-Object -TypeName System.IO.FileStream -ArgumentList $FullFilePath, Create 
        $buffer = new-object byte[] 10KB 
        $count = $responseStream.Read($buffer,0,$buffer.length) 
        $downloadedBytes = $count
        while ($count -gt 0) 
            { 
                [System.Console]::Write("`r`nDownloaded {0}K of {1}K", [System.Math]::Floor($downloadedBytes/1024), $totalLength) 
                $targetStream.Write($buffer, 0, $count) 
                $count = $responseStream.Read($buffer,0,$buffer.length) 
                $downloadedBytes = $downloadedBytes + $count
            } 
         
        $targetStream.Flush()
        $targetStream.Close() 
        $targetStream.Dispose() 
        $responseStream.Dispose() 
         
        # Give a basic message to the user to let them know we are done
        Write-Output "`r`nDownload complete"
    }
 
function Expand-ZipFile([string]$File, [string]$Destination) #The targets to run.
{
    # If directory doesn't exist create the directory
    if((Test-Path $Destination) -eq 0)
    {
        mkdir $Destination;      
    }
 
    $Shell = new-object -com shell.application
  
    # Get the name of the Zip file
    $Zip = $Shell.NameSpace($File)
  
    #Expand/Extract each file from the zip file
    foreach($Item in $Zip.items())
        {
            $Shell.Namespace($Destination).copyhere($Item)
        }
}
 
Get-FileDownload $WebURL  $FullFilePath
 
Expand-ZipFile $FullFilePath c:\Nexus
 
 
 
cd C:\Nexus
 
$NexusFolder = (Get-ChildItem nexus* | Select Name).Name
 
# Create System Variable
[Environment]::SetEnvironmentVariable("NEXUS_HOME", "C:\Nexus\$NexusFolder", "Machine")
 
cd "C:\Nexus\$NexusFolder"
 
# Configure C:\Nexus\nexus-2.12.0-01\conf\nexus.properties
#     Set Port Number if you want something other than 8081
 
cd bin
 
Start-Process nexus.bat install -Wait
Start-Process nexus.bat start -Wait
 
start 'http://localhost:8081/nexus'
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code PowerShell

Post navigation

Previous post
Next post

Related Posts

Responsive Design Tabled Div

Posted on October 1, 2013October 26, 2015

#page { max-width: 1280px; height: 100%; } /* Portrait Start */ @media screen and (max-width: 540px) { } /* Portrait Stop */ /* Landscape Start */ @media screen and (min-width: 541px) { #BodyContent1 { width: 50%; float: left; height:100%; } #BodyContent2 { width: 50%; float: right; height:100%; } } /*…

Read More

Proxy Switch

Posted on June 18, 2015October 26, 2015

Recently had a need to be able to switch on/off proxy at will and got tired of going to Internet Explorer options to set/change it. Hopefully someone else will get benefit from this nice tool. Open Visual Studio File -> New Project -> Visual C# – Windows -> Windows Forms…

Read More

Mac OSX Terminal – Uninstall Palo Alto Global Protect

Posted on June 12, 2019

First copy this text to a file and name it uninstall_gp.sh The code below is right from the Palo Alto Global Protect installer for Mac #!/bin/sh USER_ID=`id -u` if [ "$USER_ID" -ne 0 ]; then echo "You must be root to run the script. Use sudo $0" exit fi install_dir=/Applications/GlobalProtect.app/Contents/Resources…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes