src/Public/New-MCSAssessmentReport.ps1
|
function New-MCSAssessmentReport { Param( [Alias("Tenant","Tenants")] [string]$TenantID, [Alias("Workload","Workloads")] [String]$WorkloadName, [string]$CustomerName, [string]$CsvFile, [string]$ExcelFile, [string]$FoundryEndpoint, [string]$ExtraRequest, [string]$AzureEnvironment = "AzureCloud", [switch]$Debug ) if ($Debug.IsPresent) { $DebugPreference = "Continue" } else { $DebugPreference = "SilentlyContinue" } Write-Host "Validating Parameters..." if (-Not $TenantID) { Write-Host "Error: No TenantID" -ForegroundColor Red exit 1 } if (-Not $WorkloadName) { Write-Host "Error: No WorkloadName" -ForegroundColor Red exit 1 } if (-Not $CustomerName) { Write-Host "Error: No CustomerName" -ForegroundColor Red exit 1 } if (-Not $CsvFile -and -Not $ExcelFile) { Write-Host "Error: No CsvFile or ExcelFile provided" -ForegroundColor Red exit 1 } Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Starting Get-MCSTemplatePPT function') $RootPath = (get-item $PSScriptRoot).parent $PPTTemplateFile = Join-Path $RootPath 'Private' 'Report' 'PPT' 'Template - MCSAW Consolidated Assessment Automated Deck.pptx' Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Connecting to Azure Account') Connect-MCSAzureAccount -TenantID $TenantID -AzureEnvironment $AzureEnvironment -Debug $Debug Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Connected to Azure Account') $workingFolderPath = Get-Location $workingFolderPath = $workingFolderPath.Path $NewPPTFile = ($workingFolderPath + '\Consolidated Assessment - ' + $CustomerName + ' - ' + (get-date -Format "yyyy-MM-dd-HH-mm") + '.pptx') Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Openning Assessment File (CSV or Excel)') $CSV = Get-MCSAssessmentFile -CSVFile $CsvFile -ExcelFile $ExcelFile -Debug $Debug $ResourceTypes = $CSV.'Resource Type' | Select-Object -Unique -CaseInsensitive Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Extracting Subscriptions from CSV') $Subscriptions = Get-MCSSubscriptionList -CSV $CSV Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Checking Foundry Endpoint') if($FoundryEndpoint) { Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'AI will be used to enhance the report') if($ExtraRequest) { Write-Host 'Extra Request to be used with the AI: ' -NoNewline Write-Host $ExtraRequest -ForegroundColor Green $ExtraRequest = "And also $ExtraRequest" } else { $ExtraRequest = 'And also make sure everything is written in English.' } $MetroAgent = Get-MCSMetroAIAgent -FoundryEndpoint $FoundryEndpoint if($MetroAgent.count -ge 2) { $MetroAgent = $MetroAgent[0] } $MetroAgentName = $MetroAgent.Name Write-Host 'Foundry Agent to be used: ' -NoNewline Write-Host $MetroAgentName -ForegroundColor Green Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Getting AI Implication for the Recommendations') $Recommendations = Get-MCSMetroAIImplications -Csv $CSV -MetroAgent $MetroAgent -ExtraRequest $ExtraRequest -Debug $Debug $AboutCx = Get-MCSMetroAICxData -CustomerName $CustomerName -MetroAgent $MetroAgent -ExtraRequest $ExtraRequest -Debug $Debug $AboutSfMC = Get-MCSSfMCDetails -MetroAgent $MetroAgent -ExtraRequest $ExtraRequest -Debug $Debug $AboutCxEnvironment = Get-MCSMetroAICxEnvironmentData -CustomerName $CustomerName -WorkloadName $WorkloadName -MetroAgent $MetroAgent -ExtraRequest $ExtraRequest -Debug $Debug $AboutGoalsOfSfMC = Get-MCSMetroAIGoalsOfSfMC -MetroAgent $MetroAgent -ExtraRequest $ExtraRequest -Debug $Debug } else { $Recommendations = @() Foreach ($Recommendation in $CSV) { $Answer = @{ "Recommendation" = $Recommendation.'Recommendation Title' "Priority" = $Recommendation.Priority "Description" = $Recommendation.Description "Implication" = "N/A" } $Recommendations += $Answer } } Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Processing Low Impact Recommendations') $LowRecommendation = $Recommendations | where-object {$_.Priority -eq "Low"} | Select-Object -Property "Recommendation","Implication" -Unique Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Processing Medium Impact Recommendations') $MediumRecommendation = $Recommendations | where-object {$_.Priority -eq "Medium"} | Select-Object -Property "Recommendation","Implication" -Unique Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Processing High Impact Recommendations') $HighRecommendation = $Recommendations | where-object {$_.Priority -eq "High"} | Select-Object -Property "Recommendation","Implication" -Unique Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Processing Critical Impact Recommendations') $CriticalRecommendation = $Recommendations | where-object {$_.Priority -eq "Critical"} | Select-Object -Property "Recommendation","Implication","Description" -Unique try { Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Openning PowerPoint Application to Build Slides') $Application = New-Object -ComObject PowerPoint.Application $Presentation = $Application.Presentations.Open($PPTTemplateFile, $null, $null, $null) } catch { Write-Host "Error: PowerPoint is not installed or could not be opened." -ForegroundColor Red Get-Process -Name 'POWERPNT' -ErrorAction Ignore | Where-Object { $_.CommandLine -like '*/automation*' } | ForEach-Object { $_ | Stop-Process -Force } Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Trying again to open PowerPoint Application') $Application = New-Object -ComObject PowerPoint.Application $Presentation = $Application.Presentations.Open($PPTTemplateFile, $null, $null, $null) } Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Building Slide 1 - Title Slide') Build-MCSSlide1 -Presentation $Presentation -CustomerName $CustomerName -WorkLoadName $WorkloadName Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Building What is SfMC Slide') Build-MCSWhatisSfMC -Presentation $Presentation -AboutSfMC $AboutSfMC -Debug $Debug if($FoundryEndpoint) { Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Building Slide 3 - Goals of SfMC') Build-MCSGoalsOfSfMC -Presentation $Presentation -AboutGoalsOfSfMC $AboutGoalsOfSfMC -Debug $Debug } Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Building Team Slide') Build-MCSCxTeamSlide -Presentation $Presentation -CustomerName $CustomerName if($FoundryEndpoint) { Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Building Customer Details with AI Data Slide') Build-MCSCustomerDetailsSlide -Presentation $Presentation -CustomerName $CustomerName -AboutCx $AboutCx } Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Building Application and Subscriptions Details Slide') Build-MCSApplicationSlide -Presentation $Presentation -AboutCxEnvironment $AboutCxEnvironment -CustomerName $CustomerName -WorkLoadName $WorkloadName -ResourceTypes $ResourceTypes -Subscriptions $Subscriptions Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Building Low Impact Recommendations Slide') Build-MCSLowImpactSlide -Presentation $Presentation -LowRecommendation $LowRecommendation -DEBUG $Debug Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Building Medium Impact Recommendations Slide') Build-MCSMediumImpactSlide -Presentation $Presentation -MediumRecommendation $MediumRecommendation -Debug $Debug Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Building High Impact Recommendations Slide') Build-MCSHighImpactSlide -Presentation $Presentation -HighRecommendation $HighRecommendation -Debug $Debug Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Building Critical Impact Recommendations Slide') Build-MCSCriticalImpactSlide -Presentation $Presentation -CriticalRecommendation $CriticalRecommendation -FoundryEndpoint $FoundryEndpoint -MetroAgent $MetroAgent -ExtraRequest $ExtraRequest -Debug $Debug Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Saving PPT File') $Presentation.SaveAs($NewPPTFile) $Presentation.Close() $Application.Quit() Start-Sleep -Milliseconds 500 if( Get-Process -Name 'POWERPNT' -ErrorAction Ignore | Where-Object { $_.CommandLine -like '*/automation*' } ) { Get-Process -Name 'POWERPNT' -ErrorAction Ignore | Where-Object { $_.CommandLine -like '*/automation*' } | ForEach-Object { $_ | Stop-Process -Force } } if($FoundryEndpoint) { Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Removing Metro AI Conversation') Get-MetroAIConversation | ForEach-Object {Invoke-MetroAIApiCall -Service 'openai/conversations' -Operation 'conversation' -Path $_.id -Method Delete | Out-Null} } Write-Host '' Write-Host ('Presentation file saved at: ') -NoNewline write-host $NewPPTFile -ForegroundColor Cyan Write-Host '' } |