Skip to content

Commit

Permalink
Merge pull request #133 from jakkulabs/development [Release]
Browse files Browse the repository at this point in the history
PowervRA 2.2.0
  • Loading branch information
chelnak committed Apr 25, 2017
2 parents d4e427a + 1dba794 commit 8a5f54f
Show file tree
Hide file tree
Showing 23 changed files with 1,141 additions and 161 deletions.
157 changes: 59 additions & 98 deletions Get-PowervRA.ps1
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
function Get-PowervRA {
<#
<#
.SYNOPSIS
Install PowervRA
.DESCRIPTION
Install powervRA
Install PowervRA
.PARAMETER Global
Install for all users
.PARAMETER URI
The location of the latest release
.PARAMETER ImportAfterInstall
Import the module after a succesfull installation
.PARAMETER InstallFromRepo
Install latest release from github repo
.INPUTS
None
Expand All @@ -23,35 +20,23 @@
.EXAMPLE
Get-PowervRA
.EXAMPLE
Get-PowervRA -Global
.EXAMPLE
Get-PowervRA -Global -ImportAfterInstall
#>
[CmdletBinding(SupportsShouldProcess,ConfirmImpact="High",DefaultParameterSetName="Standard")]
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = "High")]

Param (

[parameter(Mandatory=$false,ParameterSetName="Standard")]
[ValidateNotNullOrEmpty()]
[String]$URI,

[parameter(Mandatory=$false,ParameterSetName="Standard")]
[ValidateNotNullOrEmpty()]
[Switch]$Global,

[parameter(Mandatory=$false,ParameterSetName="Standard")]
[ValidateNotNullOrEmpty()]
[Switch]$ImportAfterInstall
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[String]$URI,

[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[Switch]$ImportAfterInstall
)

try {

begin {

$Header = @"
$Header = @"
_____ _____
| __ \ | __ \ /\
| |__) |____ _____ _ ____ _| |__) | / \
Expand All @@ -60,94 +45,70 @@
|_| \___/ \_/\_/ \___|_| \_/ |_| \_\/_/ \_\
"@

Write-Output $Header
Write-Output "Jakku Labs $([char]0x00A9) 2016"

}

process {

try {

# --- Set the installtion directory
$InstallationDir = "C:\Users\$($env:USERNAME)\Documents\WindowsPowerShell\Modules\PowervRA\"

if ($PSBoundParameters.ContainsKey('Global')) {

$InstallationDir = "C:\Program Files\WindowsPowerShell\Modules\PowervRA\"

}

Write-Verbose -Message "Intallation directory is: $($InstallationDir)"
Write-Output $Header
Write-Output "Jakku Labs $([char]0x00A9) 2016"

# --- Download and unpack the latest release
# --- Set the installtion directory
$InstallationDir = "C:\Users\$($env:USERNAME)\Documents\WindowsPowerShell\Modules\PowervRA\"
Write-Verbose -Message "Intallation directory is: $($InstallationDir)"

Write-Verbose -Message "Downloading latest release from $($URI)"
# --- Download and unpack the latest release
Write-Verbose -Message "Downloading latest release from $($URI)"

$Response = Invoke-RestMethod -Method Get -Uri $URI
$Response = Invoke-RestMethod -Method Get -Uri $URI
$ZipUrl = $Response.assets[0].browser_download_url

$ZipUrl = $Response.zipball_url
$GUID = ([guid]::NewGuid()).ToString()
$OutputFile = "$($env:TEMP)\powervra-$($GUID).zip"

$GUID = ([guid]::NewGuid()).ToString()
Invoke-RestMethod -Method Get -Uri $ZipUrl -OutFile $OutputFile

$OutputFile = "$($env:TEMP)\powervra-$($GUID).zip"

Invoke-RestMethod -Method Get -Uri $ZipUrl -OutFile $OutputFile

Add-Type -assembly system.io.compression.filesystem

$PowervRAModulePath = $OutputFile.Substring(0, $OutputFile.LastIndexOf('.'))

Write-Verbose -Message "Unpacking module to $($PowervRAModulePath)"

[io.compression.zipfile]::ExtractToDirectory($OutputFile, $PowervRAModulePath)

if ($PSCmdlet.ShouldProcess($InstallationDir)){

# --- Remove module if it is present
if ((Test-Path -Path $InstallationDir)){

Write-Verbose -Message "Removing old module"

Remove-Item -Path $InstallationDir -Recurse -Force

}

# --- Install PowervRA
Write-Verbose -Message "Installing PowervRA to $($InstallationDir)"

Copy-Item -Path "$($PowervRAModulePath)\*\PowervRA" -Destination $InstallationDir -Force -Recurse
$PowervRAModulePath = $OutputFile.Substring(0, $OutputFile.LastIndexOf('.'))
Write-Verbose -Message "Unpacking module to $($PowervRAModulePath)"

if ($PSVersionTable.PSEdition) {
Expand-Archive -Path $OutputFile -DestinationPath $PowervRAModulePath
}
else {
Add-Type -Assembly "System.IO.Compression.FileSystem" -ErrorAction SilentlyContinue
[Io.Compression.ZipFile]::ExtractToDirectory($OutputFile, $PowervRAModulePath)
}

if ($PSCmdlet.ShouldProcess($InstallationDir)) {

if ($PSBoundParameters.ContainsKey('ImportAfterInstall')) {
# --- Remove module if it is present
if ((Test-Path -Path $InstallationDir)) {

Write-Verbose -Message "Attempting to remove old module from session"
Remove-Module -Name "PowervRA" -Force -ErrorAction SilentlyContinue
Write-Verbose -Message "Removing old module"
Remove-Item -Path $InstallationDir -Recurse -Force
}

Write-Verbose -Message "Importing module"
Import-Module -Name "PowervRA" -Force
# --- Install PowervRA
Write-Verbose -Message "Installing PowervRA to $($InstallationDir)"
Copy-Item -Path "$($PowervRAModulePath)\PowervRA" -Destination $InstallationDir -Force -Recurse

}
if ($PSBoundParameters.ContainsKey('ImportAfterInstall')) {

Write-Verbose -Message "Installation complete"
Write-Verbose -Message "Attempting to remove old module from session"
Remove-Module -Name "PowervRA" -Force -ErrorAction SilentlyContinue

Write-Verbose -Message "Importing module"
Import-Module -Name "PowervRA" -Force
}
}
catch [Exception]{

throw
Write-Verbose -Message "Installation complete"
}
}
end {
catch [Exception] {

Write-Verbose -Message "Removing temporary file $($OutputFile)"
Remove-item -Path $OutputFile -Recurse -Force -ErrorAction SilentlyContinue -Confirm:$false
throw $_
}
finally {

Write-Verbose -Message "Removing temporary directory $($PowervRAModulePath)"
Remove-item -Path $OutputFile -Recurse -Force -ErrorAction SilentlyContinue -Confirm:$false
Remove-Item -Path $PowervRAModulePath -Recurse -Force -ErrorAction SilentlyContinue -Confirm:$false

}

}
}
}

# --- Install PowervRA for the current user
Get-PowervRA -URI "https://api.github.com/repos/jakkulabs/PowervRA/releases/latest" -ImportAfterInstall -Verbose
36 changes: 14 additions & 22 deletions PowervRA/Functions/Private/xRequires.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,24 @@ function xRequires {
#>

[CmdletBinding()]

[CmdletBinding()][Alias("FunctionRequires")]
Param (

[Parameter(Mandatory=$true)]
[Parameter(Mandatory=$true, Position=0)]
[String]$Version

)
# --- Test for vRA API version
if (-not $Global:vRAConnection){

throw "vRA Connection variable does not exist. Please run Connect-vRAServer first to create it"
}

# --- Convert version strings to [version] objects
$APIVersion = [version]$Global:vRAConnection.APIVersion
$RequiredVersion = [version]$Version

if ($APIVersion -lt $RequiredVersion) {

$PSCallStack = Get-PSCallStack

throw "$($PSCallStack[1].Command) is not supported with vRA API version $($Global:vRAConnection.APIVersion)"

}

# --- Test for vRA API version
if (-not $Global:vRAConnection){
throw "vRA Connection variable does not exist. Please run Connect-vRAServer first to create it"
}

# --- Convert version strings to [version] objects
$APIVersion = [version]$Global:vRAConnection.APIVersion
$RequiredVersion = [version]$Version

if ($APIVersion -lt $RequiredVersion) {
$PSCallStack = Get-PSCallStack
Write-Error -Message "$($PSCallStack[1].Command) is not supported with vRA API version $($Global:vRAConnection.APIVersion)"
break
}
}
3 changes: 3 additions & 0 deletions PowervRA/Functions/Public/Invoke-vRARestMethod.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@
if ($PSBoundParameters.ContainsKey("Body")) {

$Params.Add("Body", $Body)

# --- Log the payload being sent to the server
Write-Debug -Message $Body

} elseif ($PSBoundParameters.ContainsKey("OutFile")) {

Expand Down

0 comments on commit 8a5f54f

Please sign in to comment.