Zum Inhalt springen

Azure powershell function collection

In this post I’ll collect all my base powershell functions and snippets.

function InstallPSModuleAndCheckForUpdates() {
    Write-Host "Checking installed PSS Modules"

    # If not exists, the base azure PSS will be installed and Imported
    if (-not (Get-Module -Name AZ)) 
    {
        Install-Module -Name Az -AllowClobber -Scope CurrentUser
    } else
    {
        update-Module -Name Az  
    }
    Import-Module -Name Az

    # For KeyVault integration, the ManagedServiceIdentity PSS-Module must be installed
    if (-not (Get-Module -Name "Az.ManagedServiceIdentity")) 
        {
        Install-Module -Name Az.ManagedServiceIdentity -AllowClobber -Scope CurrentUser
        }else
    {
        update-Module -Name Az.ManagedServiceIdentity 
    }
    Import-Module -Name Az.ManagedServiceIdentity

    # For Azure AD (B2C)  PSS-Module must be installed
    if (-not (Get-Module -Name "azuread")) 
        {
        Install-Module -Name azuread -AllowClobber -Scope CurrentUser
        }else
    {
        update-Module -Name azuread  
    }
    Import-Module -Name azuread
} #end Install PS Module or check for update

Schlagwörter:

Schreibe einen Kommentar