src/Get-cciModule.ps1
function Get-cciModule { [CmdletBinding()] param ( [Parameter(Mandatory=$true)] $Name, $destination = 'C:\CCI', [string]$resourceGroupName = 'VS-cciplatform-Group', [string]$storageAccountName = 'cciplatformazdevops', [Parameter(Mandatory=$false)] [string]$Team=[string]::Empty, [switch]$NoClobber ) begin { Write-Verbose "Started running $($MyInvocation.MyCommand)" $GetModuleAz = Get-Module Az.* $cciConnectionParams = Get-cciConnectionParams } process { if (('Az.Storage' -in $GetModuleAz.Name)){ #I dont think this _and_ is needed# -and ('Az.Keyvault' -in $GetModuleAz.Name)) { Write-Verbose "Prerequisite modules are present. Continuing." } else { #Install-Module -Name Az.Storage -RequiredVersion 4.9.0 -Force -AllowClobber # Oct 2022 - 4.10.0 is bad, so forcing version 4.5.0 #The above was a temp fix that can be removed now since the latest version is usually best Install-Module -Name Az.Storage -Force -AllowClobber #Install-Module Az.Storage -Force # Install-Module Az.Keyvault -Force -AllowClobber #again I dont think this is nessesary -dk } if ($null -eq (Get-AzContext)) { Connect-cciAzAccount } if (!(Test-Path $destination)) { New-Item $destination -ItemType Directory } if (!($NoClobber)) { Remove-Item -Path "$($destination)\$($name)" -Recurse -Force -ErrorAction SilentlyContinue $azStorageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -StorageAccountName $storageAccountName $azStorageContainers = $azStorageAccount | Get-AzStorageContainer $azStorageContainerMatches = $azStorageContainers | Where-Object Name -eq $cciConnectionParams.azStorageContainer_Name_Modules $azStorageBlob = $azStorageContainerMatches | Get-AzStorageBlob -Prefix $Name $null = $azStorageBlob | Get-AzStorageBlobContent -Destination $destination Publish-CciCustomizationBats -moduleName $Name -team "$Team" } else { Publish-CciCustomizationBats -moduleName $Name -team "$Team" -NoClobber } } end { Write-Verbose "Finished running $($MyInvocation.MyCommand)" } } |