2

I have a O365 client that has 85,000 items in a folder structure in a library in their SharePoint online. Also they have hundreds of items that were never checked in and invisible for other users. I am looking for a way to override check in those items with Powershell.

I came upon a great module with some useful cmdlets. I want to combine two:

  1. First one checks in all items in a folder.
  2. Another checks in recursively all items in a list ( and folders and subfolders).

Because the library is so overloaded, I want to check in top level folder by top leve folder and including all subfolders. It is a lttle over my head though, that recursive stuff, any help is welcome.

Example checkIn folder or everything

Make connection:

function Connect-SPOCSOM
{

<#
    .link
    http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx

  #>

 param (
  [Parameter(Mandatory=$true,Position=1)]
        [string]$Username,
        [Parameter(Mandatory=$true,Position=3)]
        [string]$Url


)

  $password = Read-Host "Password" -AsSecureString
  $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
  $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
  $ctx.ExecuteQuery()  
$global:ctx=$ctx
}

Code resursive :

function Get-SPOListItems
{
  <#
    .link
    http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx

  #>

   param (
        [Parameter(Mandatory=$true,Position=4)]
        [string]$ListTitle,
        [Parameter(Mandatory=$false,Position=5)]
        [bool]$IncludeAllProperties=$false,
        [switch]$Recursive
        )


  $ll=$ctx.Web.Lists.GetByTitle($ListTitle)
  $ctx.Load($ll)
  $ctx.Load($ll.Fields)
  $ctx.ExecuteQuery()
  $i=0



 $spqQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
# $spqQuery.ViewAttributes = "Scope='Recursive'"

if($Recursive)
{
$spqQuery.ViewXml ="<View Scope='RecursiveAll' />";
}
   $bobo=Get-SPOListFields -ListTitle $ListTitle 


  $itemki=$ll.GetItems($spqQuery)
  $ctx.Load($itemki)
  $ctx.ExecuteQuery()



 $objArray=@()

  for($j=0;$j -lt $itemki.Count ;$j++)
  {

        $obj = New-Object PSObject

        if($IncludeAllProperties)
        {

        for($k=0;$k -lt $bobo.Count ; $k++)
        {

         # Write-Host $k
         $name=$bobo[$k].InternalName
         $value=$itemki[$j][$name]
          $obj | Add-Member NoteProperty $name($value) -Force

        }

        }
        else
        {
          $obj | Add-Member NoteProperty ID($itemki[$j]["ID"])
          $obj | Add-Member NoteProperty Title($itemki[$j]["Title"])

        }

      #  Write-Host $obj.ID `t $obj.Title
        $objArray+=$obj


  }



  return $objArray


  }

And the checkin function:

function Set-SPOFileCheckin
{

<#
    .link
    http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx

  #>


param (
        [Parameter(Mandatory=$true,Position=4)]
        [string]$ServerRelativeUrl,
        [Parameter(Mandatory=$true,Position=5)]
        [ValidateSet('MajorCheckIn','MinorCheckIn','OverwriteCheckIn')]
        [System.String]$CheckInType,
        [Parameter(Mandatory=$false,Position=6)]
        [string]$CheckinComment=""     
        )


  $file =
        $ctx.Web.GetFileByServerRelativeUrl($ServerRelativeUrl);
        $ctx.Load($file)
        $ctx.ExecuteQuery()

  $file.CheckIn($CheckInComment, $CheckInType)
  $ctx.Load($file)
  try
  {
  $ctx.ExecuteQuery()        
  Write-Host $file.Name " has been checked in"     -ForegroundColor DarkGreen 
  }
        catch [Net.WebException]
     { 
        Write-Host $_.Exception.ToString()
     }


}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.