Powershell script to get checkout files from Sharepoint 2010 web application

PowerShell Script to get checkout files

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
$webapps = @()
$WebAppName =""
$webName = ""
$siteOwner ="" 
$siteSecondaryContact  = ""
$WebUrl = ""
$siteContentDatabase =""
#Create Export File
$FilePath = "C:\AllACACheckedOut.csv"
New-Item $FilePath -type file -force

function GetACALibraryData($webappname,$webname,$siteowner,$sitesecondarycontact,$sitecontentdatabase,$urlin, $library){
    [string]$url = $urlIn
    $site = New-Object Microsoft.SharePoint.SPSite($url)
    $web = $site.OpenWeb()
    $list = $web.Lists[$library]
    $checkedout = ""
    $delimiter = ","

    # Gets all files in list
    foreach ($listItem in $list.Items  ) {
        if($listItem.File.CheckedOutByUser -ne $null){

            # Clean up title and name strings to eliminate potential comma delimiters
            $name = $listItem.Name
            $name = $name -replace ",",""
            $title = $listItem.Title
            $title = $title -replace ",",""

        Write-Host $webappname $delimiter $webname $delimiter $siteowner $delimiter $sitesecondarycontact $delimiter $sitecontentdatabase   $delimiter  $listItem.ParentList  $delimiter  $listItem.File.CheckedOutBy  $delimiter  $listItem.File.TimeLastModified $delimiter $name $delimiter $title
        $mystring = $webappname +$delimiter+ $webname+ $delimiter  + $siteowner  + $delimiter  + $sitesecondarycontact  + $delimiter  + $sitecontentdatabase  + $delimiter  + $listItem.ParentList  + $delimiter + $listItem.File.CheckedOutBy  + $delimiter + $listItem.File.TimeLastModified + $delimiter + $name + $delimiter + $title
        Add-Content -path $FilePath  -value $mystring
        }
    }
$site.Dispose()
}
# Add Header
Write-Host "WebAppName,WebName,siteOwner,SecondaryContact,ContentDatabase,Parent,CheckedOutBy,LastModified,Name,Title"
Add-Content -path $FilePath  -value "WebAppName,WebName,siteOwner,SecondaryContact,ContentDatabase,Parent,CheckedOutBy,LastModified,Name,Title"
# "Farm"
foreach ($websvc in $websvcs) { 
    # "Web Applications" 
        foreach ($webapp in $websvc.WebApplications) {     
        $WebAppName = $webapp.Name
        # "Site Collections"         
            foreach ($site in $webapp.Sites) {     
            $siteOwner = $site.Owner 
            $siteSecondaryContact = $site.SecondaryContact
            $siteContentDatabase = $site.ContentDatabase             
            #Website
            foreach ($web in $site.AllWebs  | Where { ($webapp.Name = "ACA") }) { 
                $WebUrl = $web.URL 
                $webName = $web.Name
                # "Lists"                 
                foreach ($list in $web.Lists | Where { ($_.BaseType -eq "DocumentLibrary") -and ($_.BaseTemplate -notmatch "Catalog") }) {
                     $listTitle = $list.Title     
                    GetACALibraryData $WebAppName $webName $siteOwner $siteSecondaryContact $siteContentDatabase $WebUrl $listTitle                    
                    } 
                } 
            }         
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s