I have written following powershell script to check if a folder exists in a document library. My function is not able to find the folder which is existing. I am not sure, if it is due to the pattern of folder name or the function code it self. Appreciate the help Thanks Nate
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
}