Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1. function Get-CheckedOutDocument
  2.  
  3. {
  4.  
  5. {
  6.  
  7. #Adding the Client OM Assemblies
  8. Add-Type -Path "C:\Microsoft.SharePoint.Client.dll"
  9. Add-Type -Path "C:\Microsoft.SharePoint.Client.Runtime.dll"
  10.  
  11. #SPO Client Object Model Context
  12. $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteUrl)
  13. #$spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUserName, $sPassword)
  14. $spoCredentials = New-Object System.Net.NetworkCredential($sUserName, $sPassword)
  15. $spoCtx.Credentials = $spoCredentials
  16.  
  17. $web = $spoCtx.Web
  18. $List = $web.Lists.GetByTitle($ListTitle);
  19.  
  20. $caml="<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='FSObjType' /><Value Type='Lookup'>0</Value></Eq></Where></Query></View>"
  21. $cquery = New-Object Microsoft.SharePoint.Client.CamlQuery
  22. $cquery.ViewXml=$caml
  23. $listItems = $List.GetItems($cquery)
  24.  
  25. $spoCtx.Load($List)
  26. $spoCtx.Load($listItems)
  27. $spoCtx.ExecuteQuery()
  28.  
  29. $AllListItems = @()
  30. foreach ($listitem in $listItems)
  31. {
  32. $Title =""
  33. $FileType =""
  34. $FileRef =""
  35. $FileSize ="0 KB"
  36. $CreatedBy = "System Account"
  37. $ModifiedBy = "System Account"
  38. $IsCheckedoutToLocal = "No"
  39. $CheckoutUser =""
  40. $CheckoutUserEmail =""
  41. If([string]::IsNullOrEmpty($listitem.FieldValues["FileLeafRef"]))
  42. {
  43. $Title = "No Title"
  44. }
  45. else
  46. {
  47. $Title =$listitem.FieldValues["FileLeafRef"]
  48. }
  49.  
  50. If([string]::IsNullOrEmpty($listitem.FieldValues["File_x0020_Type"]))
  51. {
  52. $FileType = "None"
  53. }
  54. else
  55. {
  56. $FileType =$listitem.FieldValues["File_x0020_Type"]
  57. }
  58.  
  59. If([string]::IsNullOrEmpty($listitem.FieldValues["FileRef"]))
  60. {
  61. $FileRef = "None"
  62. }
  63. else
  64. {
  65. $FileRef =($sWeburl + $listitem.FieldValues["FileRef"])
  66. }
  67.  
  68. If([string]::IsNullOrEmpty($listitem.FieldValues["File_x0020_Size"]))
  69. {
  70. $FileSize = "0 KB"
  71. }
  72. else
  73. {
  74. $value = [math]::Round(($listitem.FieldValues["File_x0020_Size"]/1024),2)
  75. $decimal = "{0:N2}" -f $value
  76. $FileSize = ($decimal + " KB")
  77. #Write-Host " Field Size2 = $($FileSize)"
  78. }
  79.  
  80. If([string]::IsNullOrEmpty($listitem.FieldValues["IsCheckedoutToLocal"]))
  81. {
  82. $IsCheckedoutToLocal = "No"
  83. }
  84. else
  85. {
  86. $value = $listitem.FieldValues["IsCheckedoutToLocal"]
  87. if($value -ne "0")
  88. {
  89. $IsCheckedoutToLocal ="Yes"
  90.  
  91. If([string]::IsNullOrEmpty($listitem.FieldValues["CheckoutUser"]))
  92. {
  93. $CheckoutUser = "No"
  94. }
  95. else
  96. {
  97. $FieldCheckoutUser = [Microsoft.SharePoint.Client.FieldUserValue]$listitem.FieldValues["CheckoutUser"]
  98. $CheckoutUser =$FieldCheckoutUser.LookupValue
  99. }
  100. }
  101. else
  102. {
  103. $IsCheckedoutToLocal ="No"
  104. }
  105.  
  106. }
  107.  
  108. if($IsCheckedoutToLocal -eq "Yes")
  109. {
  110.  
  111. $AllListItems += New-Object -TypeName PSObject -Property @{
  112.  
  113. SiteUrl =$sSiteUrl
  114. ListTitle = $ListTitle
  115. DocumentID=$listitem.ID
  116. FileName=$Title
  117. FileType= $FileType
  118. FileSize= $FileSize
  119. FileRef= $FileRef
  120. IsCheckedoutToLocal =$IsCheckedoutToLocal
  121. CheckoutUser =$CheckoutUser
  122. CreatedBy = $listitem.FieldValues["Created_x0020_By"]
  123. ModifiedBy = $listitem.FieldValues["Modified_x0020_By"]
  124. CreatedDate = $listitem.FieldValues["Created_x0020_Date"]
  125. ModifiedDate = $listitem.FieldValues["Last_x0020_Modified"]
  126.  
  127. } | Select SiteUrl,ListTitle,DocumentID,FileName,FileType,FileSize,FileRef,IsCheckedoutToLocal,CheckoutUser,CreatedBy,ModifiedBy,CreatedDate,ModifiedDate
  128. }
  129. }
  130. $AllListItems| Export-CSV ($sCSOMPath+""+$FileName+".csv") -NoTypeInformation -Append #-Encoding UTF8
  131.  
  132. $spoCtx.Dispose()
  133. Read-Host -Prompt "Document created at $($sCSOMPath). Please presss any key to close this"
  134.  
  135.  
  136. }
  137. catch [System.Exception]
  138. {
  139. Write-Host -ForegroundColor Red $_.Exception.ToString()
  140. Read-Host -Prompt "Operation failed..! Press any key to close this and re run the script"
  141. }
  142. }
  143.  
  144. $FileName = "Checkedout_Document_Collection"
  145. $sWeburl = "http://rootwebsiteurl"
  146. $sSiteUrl = "http://site collection url"
  147. $sUserName = "domainuserid"
  148. $sPassword = "********"
  149. $ListTitle = "Document LibraryName"
  150.  
  151.  
  152.  
  153. $scriptpath = $MyInvocation.MyCommand.Path
  154. $dir = Split-Path $scriptpath
  155.  
  156.  
  157.  
  158. Get-CheckedOutDocument -sCSOMPath $dir -sSiteUrl $sSiteUrl -ListTitle $ListTitle -sUserName $sUserName -sPassword $sPassword -sWeburl $sWeburl -FileName $FileName
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement