Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-CheckedOutDocument
- {
- {
- #Adding the Client OM Assemblies
- Add-Type -Path "C:\Microsoft.SharePoint.Client.dll"
- Add-Type -Path "C:\Microsoft.SharePoint.Client.Runtime.dll"
- #SPO Client Object Model Context
- $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteUrl)
- #$spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUserName, $sPassword)
- $spoCredentials = New-Object System.Net.NetworkCredential($sUserName, $sPassword)
- $spoCtx.Credentials = $spoCredentials
- $web = $spoCtx.Web
- $List = $web.Lists.GetByTitle($ListTitle);
- $caml="<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='FSObjType' /><Value Type='Lookup'>0</Value></Eq></Where></Query></View>"
- $cquery = New-Object Microsoft.SharePoint.Client.CamlQuery
- $cquery.ViewXml=$caml
- $listItems = $List.GetItems($cquery)
- $spoCtx.Load($List)
- $spoCtx.Load($listItems)
- $spoCtx.ExecuteQuery()
- $AllListItems = @()
- foreach ($listitem in $listItems)
- {
- $Title =""
- $FileType =""
- $FileRef =""
- $FileSize ="0 KB"
- $CreatedBy = "System Account"
- $ModifiedBy = "System Account"
- $IsCheckedoutToLocal = "No"
- $CheckoutUser =""
- $CheckoutUserEmail =""
- If([string]::IsNullOrEmpty($listitem.FieldValues["FileLeafRef"]))
- {
- $Title = "No Title"
- }
- else
- {
- $Title =$listitem.FieldValues["FileLeafRef"]
- }
- If([string]::IsNullOrEmpty($listitem.FieldValues["File_x0020_Type"]))
- {
- $FileType = "None"
- }
- else
- {
- $FileType =$listitem.FieldValues["File_x0020_Type"]
- }
- If([string]::IsNullOrEmpty($listitem.FieldValues["FileRef"]))
- {
- $FileRef = "None"
- }
- else
- {
- $FileRef =($sWeburl + $listitem.FieldValues["FileRef"])
- }
- If([string]::IsNullOrEmpty($listitem.FieldValues["File_x0020_Size"]))
- {
- $FileSize = "0 KB"
- }
- else
- {
- $value = [math]::Round(($listitem.FieldValues["File_x0020_Size"]/1024),2)
- $decimal = "{0:N2}" -f $value
- $FileSize = ($decimal + " KB")
- #Write-Host " Field Size2 = $($FileSize)"
- }
- If([string]::IsNullOrEmpty($listitem.FieldValues["IsCheckedoutToLocal"]))
- {
- $IsCheckedoutToLocal = "No"
- }
- else
- {
- $value = $listitem.FieldValues["IsCheckedoutToLocal"]
- if($value -ne "0")
- {
- $IsCheckedoutToLocal ="Yes"
- If([string]::IsNullOrEmpty($listitem.FieldValues["CheckoutUser"]))
- {
- $CheckoutUser = "No"
- }
- else
- {
- $FieldCheckoutUser = [Microsoft.SharePoint.Client.FieldUserValue]$listitem.FieldValues["CheckoutUser"]
- $CheckoutUser =$FieldCheckoutUser.LookupValue
- }
- }
- else
- {
- $IsCheckedoutToLocal ="No"
- }
- }
- if($IsCheckedoutToLocal -eq "Yes")
- {
- $AllListItems += New-Object -TypeName PSObject -Property @{
- SiteUrl =$sSiteUrl
- ListTitle = $ListTitle
- DocumentID=$listitem.ID
- FileName=$Title
- FileType= $FileType
- FileSize= $FileSize
- FileRef= $FileRef
- IsCheckedoutToLocal =$IsCheckedoutToLocal
- CheckoutUser =$CheckoutUser
- CreatedBy = $listitem.FieldValues["Created_x0020_By"]
- ModifiedBy = $listitem.FieldValues["Modified_x0020_By"]
- CreatedDate = $listitem.FieldValues["Created_x0020_Date"]
- ModifiedDate = $listitem.FieldValues["Last_x0020_Modified"]
- } | Select SiteUrl,ListTitle,DocumentID,FileName,FileType,FileSize,FileRef,IsCheckedoutToLocal,CheckoutUser,CreatedBy,ModifiedBy,CreatedDate,ModifiedDate
- }
- }
- $AllListItems| Export-CSV ($sCSOMPath+""+$FileName+".csv") -NoTypeInformation -Append #-Encoding UTF8
- $spoCtx.Dispose()
- Read-Host -Prompt "Document created at $($sCSOMPath). Please presss any key to close this"
- }
- catch [System.Exception]
- {
- Write-Host -ForegroundColor Red $_.Exception.ToString()
- Read-Host -Prompt "Operation failed..! Press any key to close this and re run the script"
- }
- }
- $FileName = "Checkedout_Document_Collection"
- $sWeburl = "http://rootwebsiteurl"
- $sSiteUrl = "http://site collection url"
- $sUserName = "domainuserid"
- $sPassword = "********"
- $ListTitle = "Document LibraryName"
- $scriptpath = $MyInvocation.MyCommand.Path
- $dir = Split-Path $scriptpath
- 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