Hi @Khushboo Kumari
Do you want to know how to connect SharePoint online using service principal in azure runbook to create folders and upload documents?
Here is a link on how to configure:
https://www.stadlersoftware.com/powershell/sharepoint-online-with-azure-runbooks/
For you want to implement create folder and upload the document, please refer to the following code and how to use power shell to implement operations on files
Connect to SharePoint Online using Service Principal
$TenantId = "<your-tenant-id>"
$ClientId = "<your-client-id>"
$ClientSecret = "<your-client-secret>"
$SiteURL = "<your-sharepoint-site-url>"
# Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.SharePoint.Client.Runtime.dll"
# Connect to SharePoint Online
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$credentials = New-Object Microsoft.SharePoint.Client.ClientCredential($ClientId, $ClientSecret)
$ctx.Credentials = $credentials
# Example: Create Folder
$folderName = "New Folder"
$list = $ctx.Web.Lists.GetByTitle("Documents")
$ctx.Load($list.RootFolder)
$ctx.ExecuteQuery()
$folder = $list.RootFolder.Folders.Add($folderName)
$ctx.ExecuteQuery()
Write-Host "Folder created successfully."
# Example: Upload Document to Folder
$filePath = "C:\Path\to\Document.docx"
$fileName = "Document.docx"
$fileContent = [System.IO.File]::ReadAllBytes($filePath)
$uploadFile = $folder.Files.Add($fileName, $fileContent, $true)
$ctx.Load($uploadFile)
$ctx.ExecuteQuery()
Write-Host "Document uploaded successfully."
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards
Cheng Feng