I cant seem to get my CSOM powershell to work with SharePoint Online any more, everything I try to initialise tells me it hasnt been requested?

Connect-SPOSite (Personal Module)

$location = "C:\Users\colin.cook\Dropbox\FluidSharePoint\Scripts\SharePointOnline\Lib"
    $files =  get-childItem -LiteralPath $location | select Name
    $files | % {
        $file = $location + "\" + $_.Name
        [System.Reflection.Assembly]::LoadFile("$file") | out-null  

function global:Connect-SPOSite { 
param ( 
    [Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]

begin {


process {         
    if ($global:spoCred -eq $null) { 
        $cred = Get-Credential -Message "Enter your credentials to log into SharePoint Online:" 
        $global:spoCred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($cred.UserName, $cred.Password) 

    $context = New-Object Microsoft.SharePoint.Client.ClientContext $Url 
    $context.Credentials = $spoCred 

    if (!$context.ServerObjectIsNull.Value) { 
        Write-Host "Connected to site: '$Url'" -ForegroundColor Green 
    return $context 
} end { 



PS C:\Windows\system32> $ctx = Connect-SPOSite "*****"
Connected to site: '*****'

PS C:\Windows\system32> $ctx

Web                          : Microsoft.SharePoint.Client.Web
Site                         : Microsoft.SharePoint.Client.Site
RequestResources             : Microsoft.SharePoint.Client.RequestResources
FormDigestHandlingEnabled    : True
ServerVersion                :
Url                          : <Removed for Security>
ApplicationName              : .NET Library
ClientTag                    :
DisableReturnValueCache      : False
ValidateOnClient             : True
AuthenticationMode           : Default
FormsAuthenticationLoginInfo :
Credentials                  : Microsoft.SharePoint.Client.SharePointOnlineCredentials
WebRequestExecutorFactory    : Microsoft.SharePoint.Client.DefaultWebRequestExecutorFactory
PendingRequest               : Microsoft.SharePoint.Client.ClientRequest1
HasPendingRequest            : True
Tag                          :
RequestTimeout               : 180000
StaticObjects                : {[Microsoft$SharePoint$SPContext$Current,  Microsoft.SharePoint.Client.RequestContext]}
ServerSchemaVersion          :
ServerLibraryVersion         :
RequestSchemaVersion         :
TraceCorrelationId           :

PS C:\Windows\system32> $web = $ctx.Web
PS C:\Windows\system32> $ctx.Load($web)
PS C:\Windows\system32> $ctx.ExecuteQuery()
PS C:\Windows\system32> $web
format-default : The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly
+ CategoryInfo          : NotSpecified: (:) [format-default], CollectionNotInitializedException
+ FullyQualifiedErrorId : Microsoft.SharePoint.Client.CollectionNotInitializedException,Microsoft.PowerShell.Commands.FormatDefaultCommand
  • Did you ever get this working? I'm having the same issue
    – Axemasta
    Nov 21, 2018 at 10:21

2 Answers 2


PowerShell is trying to access all properties and also tries to enumerate some colletions of $web (which have not been loaded - this is where your error occurs...).

Try not to "dump" everything. Try $Web.Title instead.


In order to use CSOM within your PowerShell scripts, you first need to download the Office Developer Tools based on your visual studio version.This package contains the client DLLs components for SharePoint Online.

Add-Type -Path "C:\Program Files\Common Files\microsoft shared\SharePoint Client\Microsoft.SharePoint.Client.dll" 
    Add-Type -Path "C:\Program Files\Common Files\microsoft shared\SharePoint Client\Microsoft.SharePoint.Client.Runtime.dll"

$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext("SharePointSiteURL")

$Web = $Ctx.Web

Or load assembly file like this



$ctx = New-Object Microsoft.SharePoint.Client.ClientContext("SharePointSiteURL")
  • Thanks, I already load everything and make the connection separately in a module, the $ctx is a return of that which you can see above when I query $ctx but then when I try and initiate anything beyond that it seems to go and do some work but then I get the error shown in my question, I will edit my answer with the connection module. Aug 15, 2016 at 2:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.