I am trying to map a SharePoint online document library to a network drive with PowerShell. It worked when I execute PowerShell with my account but failing when I try to execute same cod in a scheduler job whcih is configured to run as my account
Start-Transcript -Path "$PSScriptRoot\test.log";
$SPLibraryURL ="\\mycompany.sharepoint.com\DavWWWRoot\sites\Sandpit\TEST Incoming Mail"
Write-Host $SPLibraryURL
New-PSDrive -Name "B" -PSProvider FileSystem -Root $SPLibraryURL
$sourceRiskFile = Get-ChildItem "B:"
Foreach ($file in $sourceRiskFile)
{
Write-Host $file.Name
}
Stop-Transcript
I have also tried this URL but no success
https://mycompany.sharepoint.com/sites/Sandpit/TEST%20Incoming%20Mail
Error I am getting is
New-PSDrive : The specified drive root "https://mycompany.sharepoint.com/sites/Sandpit/TEST%20Incoming%20Mail" either does not exist, or it is not a folder.
job configuration is
There must be something to do with Scheduler job as same code works fine if I run PowerShell directly.