1: [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
2: #Region MOSS2007-CmdLets
3: Function Get-SPWebApplication()
4: {
5: Param( [Parameter(Mandatory=$true)] [string]$WebAppURL )
6: return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL)
7: }
8: Function global:Get-SPSite()
9: {
10: Param( [Parameter(Mandatory=$true)] [string]$SiteCollURL )
11: if($SiteCollURL -ne '')
12: {
13: return new-Object Microsoft.SharePoint.SPSite($SiteCollURL)
14: }
15: }
16: Function global:Get-SPWeb()
17: {
18: Param( [Parameter(Mandatory=$true)] [string]$SiteURL )
19: $site = Get-SPSite($SiteURL)
20: if($site -ne $null)
21: {
22: $web=$site.OpenWeb();
23: }
24: return $web
25: }
26: #EndRegion
27: Function GetCheckedOutFiles()
28: {
29: #Define 'Web Application URL' as Mandatory Parameter
30: Param( [Parameter(Mandatory=$true)] [string]$WebAppURL )
31: $WebApp=Get-SPWebApplication($WebAppURL)
32: #Write the CSV Header - Tab Separated
33: "Site Collection Name `t Site Name`t Library `t File Name `t File URL `t Last Modified `t Checked-Out By" | out-file CheckedOutFiles.txt
34: write-host "start..."
35: #Arry to Skip System Lists and Libraries
36: $SystemLists =@("Converted Forms", "Master Page Gallery", "Customized Reports", "Form Templates",
37: "List Template Gallery", "Theme Gallery", "Reporting Templates", "Solution Gallery",
38: "Style Library", "Web Part Gallery","Site Assets", "wfpub")
39: #Loop through each site collection
40: foreach($Site in $WebApp.Sites)
41: {
42: #Loop through each site in the site collection
43: foreach($Web in $Site.AllWebs)
44: {
45: #Loop through each document library
46: foreach ($List in $Web.GetListsOfType([Microsoft.SharePoint.SPBaseType]::DocumentLibrary))
47: {
48: #Get only Document Libraries & Exclude Hidden System libraries
49: if ( ($List.Hidden -eq $false) -and ($SystemLists -notcontains $List.Title) )
50: {
51: #Loop through eadh Item
52: foreach ($ListItem in $List.Items)
53: {
54: if( ($ListItem.File.CheckOutStatus -ne "None") -and ($ListItem.File.CheckedOutByUser -ne $null))
55: {
56: #Log the data to a CSV file where versioning size > 0MB!
57: "$($Site.RootWeb.Title) `t $($Web.Title) `t $($List.Title) `t $($ListItem.Name) `t $($Web.Url)/$($ListItem.Url) `t $($ListItem['Modified'].ToString()) `t $($ListItem.File.CheckedOutByUser)" | Out-File CheckedOutFiles.txt -Append
58: #*** Uncomment the below line to Check-in****#
59: $ListItem.File.Checkin("Checked in by Administrator")
60: write-host $ListItem.Name
61: }
62: }
63: }
64: }
65: $Web.Dispose()
66: }
67: $Site.Dispose()
68: }
69: write-host "Checked out Files Report Generated Successfully!"
70: }
71: #Call the Function to Get Checked-Out Files
72: Write-Host "Enter the Web Application URL:"
73: $WebAppURL= Read-Host
74: GetCheckedOutFiles $WebAppURL
If you have any questions you can reach out our SharePoint Consulting team here.
No comments:
Post a Comment