Credentials MFA

Hello all,
Good day , I am not so long in the world of Power Shell akiv. I have a concrete problem.
The script should connect to a SharePoint Online Server and check the SiteCollection from the csv.file for a Feature and activate it.This works so far. However, I have to enter authentication for every single web page.

The authentication should be requested before and stored in $Cred. This has to happen as multi-factor authentication.
Can someone explain to me how to do this ?

The -Interactive function opens a different prompt like Get-Credentials.
This prompt should appear at the beginning and store the password and user in $Cred.

$Cred should be used at this point “$Feature = Get-PnPFeature -Scope Site -Identity $FeatureID” to call the web page.

$FeatureID= “8a4b8de2-6fd8-41e9-923c-c7c3c00f8295” #Open Documents in Client Applications by Default
$ExportList= “C:\Users\xxx\Desktop\Sites__20210929082626491 - Kopie.csv”

$CSVArry = Import-CSV $ExportList

$CSVArry | foreach {

$SiteURL = $_.URL

#Connect to SharePoint Online site
Connect-PnPOnline -Url $SiteURL -Interactive

#Get the Feature
$Feature = Get-PnPFeature -Scope Site -Identity $FeatureID

#Get the Feature status
If($Feature.DefinitionId -eq $null)
{
#Activate the Feature
Enable-PnPFeature -Identity $FeatureID -Scope Site
Write-host -f Green “Feature Activated Successfully!”
}
Else
{
Write-host -f Yellow “Feature is already activated!”
}
#Disconnect from Source Site
Disconnect-PnPOnline }

Best greetings
Matze

Would be the issue. You’re closing the connection within the loop therefore it has to be initialised each time. Not recommended to use as per MS Docs: