I'm using the following SharePoint Online CSOM powershell that connects to my Office 365 tenant (E3). I'm using the Read-host to enter the password when I run the script and the script works fine...
If I plan to execute the script unattended (task scheduler) on a daily/weekly how do I authenticate without manual entering the password or how can I use the default network credentials to authenticate O365?
I don't want to hard-code password in the script file. I hope this is a very common scenario...
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
$siteUrl = "https://contoso.sharepoint.com"
$adminUsername = "[email protected]"
$secureAdminPassword = Read-Host -AsSecureString "please enter password"
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($adminUsername, $secureAdminPassword)