Framework/Core/MetadataInfo/BasicInfo.ps1

using namespace System.Management.Automation
Set-StrictMode -Version Latest 

class BasicInfo: CommandBase
{    
    
    hidden [PSObject] $AzSDKRG = $null
    hidden [SubConfiguration[]] $Configurations = @();
    hidden [SubConfiguration] $SubConfiguration;
    hidden [String] $AutomationAccountName = "AzSDKContinuousAssurance";
    hidden [String] $AzSDKRGName = ""


    BasicInfo([string] $subscriptionId, [InvocationInfo] $invocationContext): 
        Base($subscriptionId, $invocationContext) 
    { 
        $this.DoNotOpenOutputFolder = $true;
        $this.AzSDKRGName = [ConfigurationManager]::GetAzSdkConfigData().AzSDKRGName;
        $this.AzSDKRG = Get-AzureRmResourceGroup -Name $this.AzSDKRGName -ErrorAction SilentlyContinue
    }
    
    GetBasicInfo()
    {
        $this.PublishCustomMessage("`r`nFetching AzSDK Info for current subscription...", [MessageType]::Default);

        $rmContext = Get-AzureRmContext;
        $this.PublishCustomMessage([Constants]::DoubleDashLine + "`r`nList of subscriptions " + $rmContext.Account.Type + " " + $rmContext.Account +" is having access to`r`n" + [Constants]::SingleDashLine, [MessageType]::Default);
        
        $subscriptions = Get-AzureRmSubscription
        $this.PublishCustomMessage(($subscriptions | select @{N='Subscription Id'; E={$_.Id}}, @{N='Subscription Name'; E={$_.Name}} | Format-Table | Out-String), [MessageType]::Default)
        
        $this.PublishCustomMessage([Constants]::DoubleDashLine + "`r`nExamining " + $this.InvocationContext.MyCommand.ModuleName +" components for subscription: " + $this.SubscriptionContext.SubscriptionId + " ("+ $this.SubscriptionContext.SubscriptionName +")" +"`r`n" + [Constants]::SingleDashLine, [MessageType]::Default);
        
        $this.GetAzSDKVersion()
        $this.GetAzSDKAlertVersion()
        $this.GetAzSDKARMPolicyVersion()
        $this.GetAzSDKRBACVersion()
        $this.GetAzSDKSecurityCenterVersion()
        $this.GetCAVersion()
        
        $this.PublishCustomMessage(($this.Configurations | Format-Table | Out-String), [MessageType]::Default)
    }

    GetAzSDKAlertVersion()
    {
        $AlertPolicyObj =  $this.LoadServerConfigFile("Subscription.InsARMAlerts.json");
        $serverVersion = $AlertPolicyObj.Version
        $configuredVersion = "Not Available"
        $actionMessage = "Use 'Set-AzSDKAlerts' to install Alerts"

        if($null -ne $this.AzSDKRG -and $this.AzSDKRG.Tags.Count -gt 0 -and $this.AzSDKRG.Tags.Contains([Constants]::AzSDKAlertsVersionTagName))
        {
            $configuredVersion = $this.AzSDKRG.Tags[[Constants]::AzSDKAlertsVersionTagName]
            if([System.Version]$serverVersion -gt [System.Version]$configuredVersion)
            {
                $updateAvailable = $true;
                $actionMessage = "Use 'Update-AzSDKSubscriptionSecurity' to update Alert"
            }
            else
            {
                $actionMessage = [Constants]::NoActionRequiredMessage
            }
        }

        $this.AddConfigurationDetails('Alert', $configuredVersion, $serverVersion, $serverVersion, $actionMessage)
    }

    GetAzSDKARMPolicyVersion()
    {
        $ARMPolicyObj = [PSObject] $this.LoadServerConfigFile("Subscription.ARMPolicies.json"); 
        $serverVersion = $ARMPolicyObj.Version
        $configuredVersion = "Not Available"
        $actionMessage = "Use 'Set-AzSDKARMPolicies' to install ARM policy"

        if($null -ne $this.AzSDKRG -and $this.AzSDKRG.Tags.Count -gt 0 -and $this.AzSDKRG.Tags.Contains([Constants]::ARMPolicyConfigVersionTagName))
        {
            $configuredVersion = $this.AzSDKRG.Tags[[Constants]::ARMPolicyConfigVersionTagName]
            if([System.Version]$serverVersion -gt [System.Version]$configuredVersion)
            {
                $updateAvailable = $true;
                $actionMessage = "Use 'Update-AzSDKSubscriptionSecurity' to update ARM policy"
            }
            else
            {
                $actionMessage = [Constants]::NoActionRequiredMessage
            }
        }

        $this.AddConfigurationDetails('ARM policy', $configuredVersion, $serverVersion, $serverVersion, $actionMessage)
    }

    GetAzSDKRBACVersion()
    {
        $rbacPolicy = [PSObject] $this.LoadServerConfigFile("Subscription.RBAC.json"); 
        $serverVersion = $rbacPolicy.ActiveCentralAccountsVersion
        $configuredVersion = "Not Available"
        $actionMessage = "Use 'Set-AzSDKSubscriptionRBAC' to install Central accounts RBAC"

        if($null -ne $this.AzSDKRG -and $this.AzSDKRG.Tags.Count -gt 0 -and $this.AzSDKRG.Tags.Contains([Constants]::CentralRBACVersionTagName))
        {
            $configuredVersion = $this.AzSDKRG.Tags[[Constants]::CentralRBACVersionTagName]
            if($configuredVersion -ne "Not Available") 
            {
                if([System.Version]$serverVersion -gt [System.Version]$configuredVersion)
                {
                    $updateAvailable = $true;
                    $actionMessage = "Use 'Update-AzSDKSubscriptionSecurity' to update Central accounts RBAC"
                }
                else
                {
                    $actionMessage = [Constants]::NoActionRequiredMessage
                }
            }
        }
        
        $this.AddConfigurationDetails('RBAC - Central accounts', $configuredVersion, $serverVersion, $serverVersion, $actionMessage)

        $configuredVersion = "Not Available"
        $serverVersion = $rbacPolicy.DeprecatedAccountsVersion
        $actionMessage = "Use 'Set-AzSDKSubscriptionRBAC' to install Central accounts RBAC"

        if($null -ne $this.AzSDKRG -and $this.AzSDKRG.Tags.Count -gt 0 -and $this.AzSDKRG.Tags.Contains([Constants]::DeprecatedRBACVersionTagName))
        {
            $configuredVersion = $this.AzSDKRG.Tags[[Constants]::DeprecatedRBACVersionTagName]
            if([System.Version]$serverVersion -gt [System.Version]$configuredVersion)
            {
                $updateAvailable = $true;
                $actionMessage = "Use 'Update-AzSDKSubscriptionSecurity' to update Deprecated accounts RBAC"
            }
            else
            {
                $actionMessage = [Constants]::NoActionRequiredMessage
            }
        }

        $this.AddConfigurationDetails('RBAC - Deprecated accounts', $configuredVersion, $serverVersion, $serverVersion, $actionMessage)
    }

    GetAzSDKSecurityCenterVersion()
    {
        $secCentObj =  $this.LoadServerConfigFile("SecurityCenter.json");
        $serverVersion = $secCentObj.Version
        $configuredVersion = "Not Available"
        $actionMessage = "Use 'Set-AzSDKAzureSecurityCenterPolicies' to install Security Center configuration"
        if($null -ne $this.AzSDKRG -and $this.AzSDKRG.Tags.Count -gt 0 -and $this.AzSDKRG.Tags.Contains([Constants]::SecurityCenterConfigVersionTagName))
        {
            $configuredVersion = $this.AzSDKRG.Tags[[Constants]::SecurityCenterConfigVersionTagName]
            if([System.Version]$serverVersion -gt [System.Version]$configuredVersion)
            {
                $updateAvailable = $true;
                $actionMessage = "Use 'Update-AzSDKSubscriptionSecurity' to update Security Center configuration"
            }
            else
            {
                $actionMessage = [Constants]::NoActionRequiredMessage
            }
        }

        $this.AddConfigurationDetails('Security Center', $configuredVersion, $serverVersion, $serverVersion, $actionMessage)
    }

    GetAzSDKVersion()
    {
        $configuredVersion = [System.Version] $this.GetCurrentModuleVersion()
        $serverVersion = [System.Version] ([ConfigurationManager]::GetAzSdkConfigData().GetLatestAzSDKVersion($this.GetModuleName()));
        $updateAvailable = $false;
        $actionMessage = "No Action Required"
        if($serverVersion -gt $this.GetCurrentModuleVersion()) 
        {
            $updateAvailable = $true;
            $actionMessage = "Use " + [ConfigurationManager]::GetAzSdkConfigData().InstallationCommand + " to update AzSDK"
        }
        else
        {
            $actionMessage = [Constants]::NoActionRequiredMessage
        }

        $this.AddConfigurationDetails('DevOpsKit (AzSDK)', $configuredVersion, $serverVersion, $serverVersion, $actionMessage)
    }

    GetCAVersion()
    {
        $configuredVersion = "Not Available"
        $serverVersion = ([ConfigurationManager]::GetAzSdkConfigData().AzSDKCARunbookVersion);
        $actionMessage = "Use 'Install-AzSDKContinuousAssurance' to install Continuous Assurance"
        $caAutomationAccount = Get-AzureRmAutomationAccount -Name $this.AutomationAccountName -ResourceGroupName $this.AzSDKRGName -ErrorAction SilentlyContinue
        if($caAutomationAccount -and $caAutomationAccount.Tags.Count -gt 0 -and $caAutomationAccount.Tags.Contains('AzSDKVersion'))
        {
            $configuredVersion = $caAutomationAccount.Tags['AzSDKVersion']
            if([System.Version]$serverVersion -gt [System.Version]$configuredVersion)
            {
                $updateAvailable = $true;
                $actionMessage = "Use 'Update-AzSDKContinuousAssurance' to update Continuous Assurance"
            }
            else
            {
                $actionMessage = [Constants]::NoActionRequiredMessage
            }
        }

        $this.AddConfigurationDetails('Continuous Assurance', $configuredVersion, $serverVersion, $serverVersion, $actionMessage)
    }

    AddConfigurationDetails([string] $ComponentName, [string] $CurrentVersion, [string] $LatestVersion, [string] $SupportedVesion, [string] $RequireAction)
    {
        $this.SubConfiguration = New-Object -TypeName PSObject
        $this.SubConfiguration.ComponentName = $ComponentName
        $this.SubConfiguration.InstalledVersion = $CurrentVersion
        $this.SubConfiguration.ServerVersion = $LatestVersion
        $this.SubConfiguration.SupportedVesion = ">= " + $SupportedVesion
        $this.SubConfiguration.Recommendation = $RequireAction
        $this.Configurations += $this.SubConfiguration
    }
}

class SubConfiguration
{
    [string] $ComponentName = "" 
    [string] $InstalledVersion = ""
    [string] $ServerVersion = ""
    [string] $SupportedVesion = ""
    [string] $Recommendation = ""
}