CSOM PowerShell not working without admin center access RRS feed

  • Question

  • I've written a CSOM PowerShell script to copy files from document library in SharePoint Online site to Shared drive. It seems working for SharePoint Online site from 1 month free Office 365 subscription where I do have admin center access. But it is not working for my project SharePoint online site where I do have site collection admin access but not admin center access. As it is CSOM PowerShell, it should work without admin center access. Please see the script below and suggest if admin center access can be bypassed.

    $SourceSiteURL = "*******"

    $UserName = "****"
    $Password = ConvertTo-SecureString "*" -AsPlainText -Force
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $Password)
    $SourceLibrary = "***"

    $SourceCtx = New-Object Microsoft.SharePoint.Client.ClientContext($SourceSiteURL)
    $SourceCtx.Credentials = $Credentials
    if(!$SourceCtx.ServerObjectIsNull.value){ Write-Host "Connected to Site" -ForegroundColor Green }
    Function DownloadFilesFromFolder()

           $diskLocation = "\\**\*\*";

           $docLib = $SourceCtx.Web.Lists.GetByTitle($SourceLibrary);

           $listRootFolder = $docLib.RootFolder;
           $FilesInRootFolder = $listRootFolder.Files;

           foreach($file in $FilesInRootFolder)
                  Write-Host $file.Name
                  $fileRef = $file.ServerRelativeUrl;
                  $fileInfo = [Microsoft.SharePoint.Client.File]::OpenBinaryDirect($SourceCtx, $fileRef);
                  $fileName = $diskLocation + $file.Name;
                  $fileStream = [System.IO.File]::Create($fileName)




    Wednesday, September 25, 2019 7:11 AM