# Credentials MFA

**URL:** <https://forums.powershell.org/t/credentials-mfa/17904>\
**Category:** PowerShell Help\
**Created:** [November 9, 2021, 11:39am UTC](https://forums.powershell.org/t/credentials-mfa/17904 "2021-11-09T11:39:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matze](https://avatars.discourse-cdn.com/v4/letter/m/ba8739/32.png) [@Matze](https://forums.powershell.org/u/Matze)\
**Post date:** [November 9, 2021, 11:39am UTC](https://forums.powershell.org/t/credentials-mfa/17904/1 "2021-11-09T11:39:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jammer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jammer/32/1885_2.png) [@Jammer](https://forums.powershell.org/u/Jammer)\
**Post date:** [November 20, 2021, 2:44am UTC](https://forums.powershell.org/t/credentials-mfa/17904/2 "2021-11-20T02:44:16Z")

</div>

> [@Matze](#):
>
> #Disconnect from Source Site  
> Disconnect-PnPOnline }

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:  
[https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/disconnect-pnponline?view=sharepoint-ps](https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/disconnect-pnponline?view=sharepoint-ps)

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:20pm UTC](https://forums.powershell.org/t/credentials-mfa/17904/3 "2024-05-16T20:20:11Z")

</div>


