Skip to content

. #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 6, 2015
Merged

. #141

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions setup-powershellget/Setup/ShortcutStartup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------
[CmdletBinding()]
[CmdletBinding(DefaultParametersetName="none")]
Param(
[Parameter(Mandatory=$False, HelpMessage="Use Install parameter to install Azure modules from PowerShell Gallery.")]
[switch]$Install
[Parameter(Mandatory=$True, HelpMessage="Use Install parameter to install Azure modules from PowerShell Gallery.", ParameterSetName="install")]
[switch]$Install,
[Parameter(Mandatory=$True, HelpMessage="Use Uninstall parameter to uninstall Azure modules from PowerShell Gallery.", ParameterSetName="uninstall")]
[switch]$Uninstall
)

function EnsureRegistryPath
Expand All @@ -38,7 +40,7 @@ try {
Write-Output @"

Finalizing installation of Azure PowerShell.
Installing Azure Modules from PowerShell Gallery.
Installing AzureRM Modules from PowerShell Gallery.
This may take some time...
"@
$env:PSModulePath = "$env:USERPROFILE\Documents\WindowsPowerShell\Modules;$env:ProgramFiles\WindowsPowerShell\Modules;$env:SystemRoot\system32\WindowsPowerShell\v1.0\Modules\"
Expand All @@ -59,7 +61,20 @@ This may take some time...
Write-Output "AzureRM $((Get-InstalledModule -Name AzureRM)[0].Version) installed..."

Update-AzureRM -Repository $DefaultPSRepository
} else {
}
elseif ($Uninstall.IsPresent)
{
Write-Output @"

Finalizing uninstallation of Azure PowerShell.
This may take some time...
"@
$env:PSModulePath = "$env:USERPROFILE\Documents\WindowsPowerShell\Modules;$env:ProgramFiles\WindowsPowerShell\Modules;$env:SystemRoot\system32\WindowsPowerShell\v1.0\Modules\"

Uninstall-AzureRM
}
else
{
cd c:\
$welcomeMessage = @"
For a list of all Azure RM cmdlets type 'help azurerm'.
Expand Down
2 changes: 2 additions & 0 deletions setup-powershellget/azurecmd.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@
<CustomAction Id="UpdatePSShortcut" BinaryKey="CustomActions" DllEntry="UpdatePSShortcut" Execute ="deferred" Impersonate="no"/>
<CustomAction Id="SetExecutionPolicy" Property="POWERSHELLEXE" ExeCommand="-NoLogo -NoProfile -Command &quot;Set-ExecutionPolicy RemoteSigned -Force&quot;" Execute="deferred" Impersonate="no" Return="check"/>
<CustomAction Id="RunModuleInstallScript" Property="POWERSHELLEXE" ExeCommand="-NoLogo -NoProfile -Command &quot;. \&quot;[PowerShellFolder]\ShortcutStartup.ps1\&quot; -Install&quot;" Execute="deferred" Impersonate="no" Return="check"/>
<CustomAction Id="RunModuleUninstallScript" Property="POWERSHELLEXE" ExeCommand="-NoLogo -NoProfile -Command &quot;. \&quot;[PowerShellFolder]\ShortcutStartup.ps1\&quot; -Uninstall&quot;" Execute="deferred" Impersonate="no" Return="check"/>

<InstallExecuteSequence>
<Custom Action="SetCustomActionDataValue" After="CreateShortcuts">NOT Installed</Custom>
<Custom Action="UpdatePSShortcut" After="SetCustomActionDataValue">NOT Installed</Custom>
<Custom Action="SetExecutionPolicy" After="UpdatePSShortcut">NOT Installed</Custom>
<Custom Action="RunModuleInstallScript" After="SetExecutionPolicy">NOT Installed</Custom>
<Custom Action="RunModuleUninstallScript" After="InstallInitialize">(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
</InstallExecuteSequence>

<WixVariable Id="WixUILicenseRtf" Value="$(var.ProjectDir)\media\License.rtf" />
Expand Down
Binary file modified tools/AzureRM/AzureRM.psd1
Binary file not shown.
70 changes: 44 additions & 26 deletions tools/AzureRM/AzureRM.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,29 @@ function Test-AdminRights([string]$Scope)
$isAdmin = (New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
if($isAdmin -eq $false)
{
throw "Administrator rights are required to install Microsoft Azure modules"
throw "Administrator rights are required to install or uninstall Microsoft Azure modules"
}
}
}

function Install-ModuleWithVersionCheck([string]$Name,[string]$MajorVersion,[string]$Repository,[string]$Scope)
{
$minVer = "$MajorVersion.0.0.0"
$maxVer = "$MajorVersion.9999.9999.9999"
$_MinVer = "$MajorVersion.0.0.0"
$_MaxVer = "$MajorVersion.9999.9999.9999"
try {
Install-Module -Name $Name -Repository $Repository -Scope $Scope -MinimumVersion $minVer -MaximumVersion $maxVer -Confirm:$false -Force -ErrorAction Stop
$_ExistingModule = Get-Module -ListAvailable -Name $Name
$_ModuleAction = "installed"
if ($_ExistingModule -ne $null)
{
Update-Module -Name $Name -MaximumVersion $_MaxVer -ErrorAction Stop
$_ModuleAction = "updated"
}
else
{
Install-Module -Name $Name -Repository $Repository -Scope $Scope -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -ErrorAction Stop
}
$v = (Get-InstalledModule -Name $Name -ErrorAction Ignore)[0].Version.ToString()
Write-Output "$Name $v installed..."
Write-Output "$Name $v $_ModuleAction..."
} catch {
Write-Warning "Skipping $Name package..."
Write-Warning $_
Expand Down Expand Up @@ -86,22 +96,30 @@ function Update-AzureRM

Write-Output "Installing AzureRM modules."

Install-ModuleWithVersionCheck "AzureRM.Profile" $MajorVersion $Repository $Scope
$_InstallationPolicy = (Get-PSRepository -Name PSGallery).InstallationPolicy

# Stop and remove any previous jobs
$AzureRMModules | ForEach {Get-Job -Name "*$_"} | Stop-Job | Remove-Job

# Start new job
$result = $AzureRMModules | ForEach {
Start-Job -Name $_ -ScriptBlock {
Install-ModuleWithVersionCheck $args[0] $args[1] $args[2] $args[3]
} -ArgumentList $_, $MajorVersion, $Repository, $Scope }

# Get results from the jobs
$AzureRMModules | ForEach {Get-Job -Name $_ | Wait-Job | Receive-Job }

# Clean up
$AzureRMModules | ForEach {Get-Job -Name $_ | Remove-Job}
try
{
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

Install-ModuleWithVersionCheck "AzureRM.Profile" $MajorVersion $Repository $Scope

# Stop and remove any previous jobs
$AzureRMModules | ForEach {Get-Job -Name "*$_"} | Stop-Job | Remove-Job

# Start new job
$result = $AzureRMModules | ForEach {
Start-Job -Name $_ -ScriptBlock {
Install-ModuleWithVersionCheck $args[0] $args[1] $args[2] $args[3]
} -ArgumentList $_, $MajorVersion, $Repository, $Scope }

# Get results from the jobs
$AzureRMModules | ForEach {Get-Job -Name $_ | Wait-Job | Receive-Job }
} finally {
# Clean up
Set-PSRepository -Name PSGallery -InstallationPolicy $_InstallationPolicy
$AzureRMModules | ForEach {Get-Job -Name $_ | Remove-Job}
}
}

<#
Expand All @@ -123,12 +141,12 @@ function Import-AzureRM

Write-Output "Importing AzureRM modules."

$minVer = "$MajorVersion.0.0.0"
$maxVer = "$MajorVersion.9999.9999.9999"
$_MinVer = "$MajorVersion.0.0.0"
$_MaxVer = "$MajorVersion.9999.9999.9999"

$AzureRMModules | ForEach {
$moduleName = $_
$matchedModule = Get-InstalledModule -Name $moduleName -MinimumVersion $minVer -MaximumVersion $maxVer -ErrorAction Ignore | where {$_.Name -eq $moduleName}
$matchedModule = Get-InstalledModule -Name $moduleName -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -ErrorAction Ignore | where {$_.Name -eq $moduleName}
if ($matchedModule -ne $null) {
try {
Import-Module -Name $matchedModule.Name -RequiredVersion $matchedModule.Version -ErrorAction Stop
Expand All @@ -143,10 +161,10 @@ function Import-AzureRM

function Uninstall-ModuleWithVersionCheck([string]$Name,[string]$MajorVersion)
{
$minVer = "$MajorVersion.0.0.0"
$maxVer = "$MajorVersion.9999.9999.9999"
$_MinVer = "$MajorVersion.0.0.0"
$_MaxVer = "$MajorVersion.9999.9999.9999"
# This is a workaround for a bug in PowerShellGet that uses "start with" matching for module name
$matchedModule = Get-InstalledModule -Name $Name -MinimumVersion $minVer -MaximumVersion $maxVer -ErrorAction Ignore | where {$_.Name -eq $Name}
$matchedModule = Get-InstalledModule -Name $Name -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -ErrorAction Ignore | where {$_.Name -eq $Name}
if ($matchedModule -ne $null) {
try {
Remove-Module -Name $matchedModule.Name -Force -ErrorAction Ignore
Expand Down