Wednesday, May 6, 2015

Fetch all non missing DOCID from the document library

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
############################################################################################################################################
# Script: Fetch all non missing DOCID from the resume repository

############################################################################################################################################

If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }

$host.Runspace.ThreadOptions = "ReuseThread"

#Definition of the function that allows to do the CAML query
function DoCAMLQuery
{
    param ($sSiteCollection,$sListName)
    try
    {
        $spSite=Get-SPSite -Identity $sSiteCollection
        $spwWeb=$spSite.OpenWeb()        
        $splList = $spwWeb.Lists.TryGetList($sListName)
        if ($splList)
        {
            $spqQuery = New-Object Microsoft.SharePoint.SPQuery
   $spqQuery.ViewAttributes = "Scope = 'Recursive'"
            $spqQuery.Query =  ""
   #$spQuery.ViewAttributes = "Scope = 'Recursive'"
   
            #$spqQuery.ViewFields = "" 
            #$spqQuery.ViewFieldsOnly = $true
            $splListItems = $splList.GetItems($spqQuery)

            $iNumber=1
            foreach ($splListItem in $splListItems)
            {
                  
    Add-Content .\$LogFileName -Value ([string]::Concat( ($splListItem["ows_ID"] -as [string]) +"|"+ $splListItem["PDI GUID"] +"|"+ $splListItem["Document Title"] +"|"+ $splListItem["Created"]+"|"+ $splListItem["_dlc_DocIdUrl"]))
            }
        }    
        $spwWeb.Dispose()
    }
    catch [System.Exception]
    {

               $ErrorVar= $_.Exception.ToString()
                    Add-Content .\$LogFileName_Error -Value ([string]::Concat("************************************"))
                 
                    Add-Content .\$LogFileName_Error -Value ([string]::Concat("System Message: "+ $ErrorVar))
           
                    Add-Content .\$LogFileName_Error -Value ([string]::Concat("************************************"))
                    continue
    }
}
#Start-SPAssignment –Global
#Calling the function
$sSiteCollection="http://sp2010:23934/"

$sListName="Resumes"

$Datetime= Get-Date -Format dd_MM_yyyy_HH.mm.ss
#Log file for Missing DocID
$LogFileName=([string]::Concat("Output_DocID_Missing_Log " , $Datetime ,".csv"))
New-Item  .\$LogFileName  -ItemType file
#Log file for Error
$LogFileName_Error=([string]::Concat("Error_DocID_Missing_Log " , $Datetime ,".txt"))
New-Item  .\$LogFileName_Error  -ItemType file
     
     
Add-Content  .\$LogFileName -Value $webUrl
Add-Content .\$LogFileName -Value ([string]::Concat("ID"+"|"+"GUID_Name" +"|"+ "File_Name" +"|"+ "Created_Date"+"|"+ "DOCID"))
write-host "Started..."
DoCamlQuery -sSiteCollection $sSiteCollection -sListName $sListName
write-host "Finished.."
#Stop-SPAssignment –Global

Remove-PSSnapin Microsoft.SharePoint.PowerShell

No comments:

Post a Comment

HTML

Script:

JS