Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

SharePoint 2013 Check folder exists in a document library using powershell

$
0
0

Following is a powershell function to check for a existence of folder in a document library.

Function CheckFolder($listParm) { TRY { $ErrActionPref = "CONTINUE"; $spQry = New-Object Microsoft.SharePoint.SPQuery $camlQry = "<Where><And><Contains><FieldRef Name='ContentType' /><Value Type='Computed'>Folder</Value></Contains></And><And><Eq><FieldRef Name='Title' /><Value Type='Text'>Name of Folder-To-Check</Value></Eq></And></Where>" $spQry.ViewAttributes = "Scope = 'Recursive'" $spQry.Query = $camlQry $spLstItms = $listParm.GetItems($spQry) if ($spLstItms.Items.Count -gt 0)

{

foreach ($item in $spLstItms) { #items found return $true }

} } CATCH { #Error handling return $false } return $false } #I am calling this CheckFolder function as follows if ((CheckFolder $list) -eq $true) { #Matching folder found }


When I run the checkFolder function, it is not finding the folder within the document library.

Any ideas on why it is not working.

Thanks

Nate


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>