Wed. Jun 8th, 2022
Function Get-ListItemsFromFolder()
    [Parameter(Mandatory=$true)] [string] $SiteURL,
    [Parameter(Mandatory=$true)] [string] $ListName,
    [Parameter(Mandatory=$true)] [string] $FolderURL
    Try {
    #Setup Credentials to connect
    $Cred = Get-Credential
    $Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred
    #Get the list
    #Frame CamlQuery to retrieve the items from the Folder
    $CAMLQuery= New-Object Microsoft.SharePoint.Client.CamlQuery
    #Set relative URL of the folder
    $camlQuery.ViewXml = '<View><Query><Where><Eq><FieldRef Name=''Title'' /><Value Type=''Text''>' + $directorate + '</Value></Eq></Where></Query></View>';

    #Get List Items from the Folder
    Write-host "Total Number of Items Found:"$ListItems.Count
    #Iterate through all list items
    Foreach($Item in $ListItems)
        #Get Ids for each Item
        Write-Host $item["ID"]
    Catch {
        write-host -f Red "Error Getting List Items from Folder!" $_.Exception.Message

This website uses cookies. By continuing to use this site, you accept our use of cookies.