Hi @IniobongNkanga-8038,
Thanks for reaching out to us. We are very pleased to assist you.
First of all, there is the question about the automatic execution of PowerShell scripts, we can use Azure Automation to run your PowerShell scripts. Azure Automation provides a robust platform for automating tasks across Microsoft 365, including SharePoint.
Since our team is primarily focused on SharePoint, we have provided some links to the use of Azure Automation for your reference and learning:
- Tutorial: Create a PowerShell Workflow runbook in Automation
- How to use Azure Automation – Complete Guide Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.
Second, regarding not popping up the login box when using the script, there are three ways to do this.
Please note in advance:
- Method 1 use
Connect -SPOService
, but not for tenants with MFA turned on. TheConnect -SPOService
command has to pop up a login popup for MFA logins. Reference: Connect-SPOService#example-3 - Methods 2 and 3 use
Connect-PnPOnline
, which also works for tenants with MFA turned on. But I am afraid your scripts need to be changed to apply the PnP PowerShell commands.
Method 1: Write the username and password in plaintext in the script. However, this method is not suitable for tenants with MFA enabled.
$username = "admin@contoso.onmicrosoft.com"
$password = "password"
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force)
Connect-SPOService -Url https://contoso-admin.sharepoint.com -Credential $cred
Method 2: Connect-PnPOnline using ClientID and ClientSecret
Please refer this document: PnP PowerShell: Connect-PnPOnline using ClientID and ClientSecret.
Note: Non-official, just for reference.
Method 3: Connect to SharePoint Online using Azure AD App ID from PowerShell
Please refer this document: PnP PowerShell: Connect to SharePoint Online using Azure AD App ID from PowerShell.
Note: Non-official, just for reference.
If you have any questions, please do not hesitate to contact me.
Moreover, if the issue can be fixed successfully, please click "Accept Answer" so that we can better archive the case and the other community members who are suffering the same issue can benefit from it.
Your kind contribution is much appreciated.