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 | ############################################################### #Script Function : Script will fetch the GUID and Document Name for Null DOCID, #Developed: Sanjiv kumar ################################################################ If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell } #Get SPWeb and Our List we are targeting. try { $web = Get-SPWeb "http://sp2010:23934/" $list = $web.Lists["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 "Number of Folders : $folderscount" Add-Content .\$LogFileName -Value ([string]::Concat("GUID_Name" +","+ "File_Name")) #Build Query $spQuery = New-Object Microsoft.SharePoint.SPQuery #CAML Query Using a DateTime Value and and Offset of Today $query = '' $spQuery.ViewAttributes = "Scope = 'Recursive'" $spQuery.Query = $query $spQuery.RowLimit = $list.ItemCount $spListItemCol = $list.GetItems($spQuery) #Writting the data to CSV foreach ($item in $spListItemCol) { #write-host "PD GUID:" $item["PDIGUID"] "File Name:" $item["Name"] -ForegroundColor Green Add-Content .\$LogFileName -Value ([string]::Concat($item["PDIGUID"] +","+ $item["Name"])) } $web.Dispose() } catch [System.Exception] { #write-host -f red $_.Exception.ToString() #write-host -f red $_.Exception.Message #write-host -f red $Error[0].Exception.Message #$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("System Message: "+ $Error[0])) #Add-Content .\$LogFileName_Error -Value ([string]::Concat("System Message: "+ $_.Exception.ItemName)) Add-Content .\$LogFileName_Error -Value ([string]::Concat("************************************")) continue } Remove-PSSnapin Microsoft.SharePoint.PowerShell |
Tuesday, April 28, 2015
Powershell Script to fetch the GUID and Document Name for Null DOCID
Subscribe to:
Post Comments (Atom)
HTML
Script:
No comments:
Post a Comment