Update and a much better way to approach this:
Use a SharePoint App Only Client Id and Secret to access the site, list, or library.
Microsoft documentation:
https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs
You can create an app principle that is limited to a single site, list, library, or a combination of them:
https://piyushksingh.com/2018/12/26/register-app-in-sharepoint/
1 2 3 | Write-Host $sampleConnect .Url
|
In this example, I’m connecting to a Site Collection on my tenant.
Assumptions:
1) You have created a token in your o365 site
1.1) https://portal.office.com/account/
1.2) On the left site of the page click Security & privacy, then click Create and manage app passwords
1.3) In the app password page click the create button and give it a name.
1.4) Save the password to a secure location.
1.5) There is a better way of doing this that I will cover in a future post.
2) You have downloaded to CSOM DLL(s) from Nuget
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | Clear-Host
$userName = "me@sharepointed.com"
$pw = "abc123taco"
#Secure the password
$securePassword = ConvertTo-SecureString $pw -AsPlainText -Force
Add-Type -Path " C:\Code\DLL\Microsoft.SharePoint.Client.dll "
Add-Type -Path " C:\Code\DLL\Microsoft.SharePoint.Client.Runtime.dll "
#Create Context
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteCollectionUrl)
#Authorise
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $securePassword)
$web = $ctx.Web
$properties = $web.AllProperties
$ctx.Load($web)
$ctx.Load($properties)
$ctx.ExecuteQuery()
Write-Host " Site Collectione URL: $( $web .Url) "
Write-Host " Properties are "
foreach ( $prop in $properties ) {
$prop .FieldValues
}
|