Hi
All,
Below
is the script which is used to get the Checked out files from SharePoint 2013
and MOSS2007.
if(!(Get-PSSnapin Microsoft.SharePoint.PowerShell
-ea 0))
{
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
#Uncomment below line while executing in MOSS
#[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
> $null
#[System.Reflection.Assembly]::Load(“Microsoft.SharePoint,
Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
$LoggingDirectory
= "F:\Mahesh\BaseCSV\CheckedOutReports"
$CsvReportFile="";
function GetCheckedItems($spWeb)
{
try
{
$FileName
="$LoggingDirectory\"
$PIECES=$spWeb.split(“/”)
for ($i=3; $i -lt $PIECES.length; $i++) {
if($PIECES[$i] -ne $null -and $PIECES[$i] -ne "")
{
$FileName
+= $PIECES[$i]+"-"
}
}
$CsvReportFile
= $FileName+"CheckedOutItemCount-2013.csv"
#2013
#$spWeb=Get-SPWeb $spWeb
$site = new-Object Microsoft.SharePoint.SPSite($spWeb)
$spWeb
= $site.OpenWeb()
Write-Host "Scanning
Site: $($spWeb.Url)"
$writeColl = $null
$writeColl = @()
foreach ($list
in ($spWeb.Lists | ? {$_ -is [Microsoft.SharePoint.SPDocumentLibrary]})) {
Write-Host
$list.Title
Write-Host
"Scanning List: $($list.RootFolder.ServerRelativeUrl)"
if($list.ItemCount -gt
0)
{
foreach
($item in
$list.CheckedOutFiles)
{
try
{
if
(!$item.Url.EndsWith(".aspx")) { continue
}
$writeTable
= @{
"URL"=$spWeb.Site.MakeFullUrl("$($spWeb.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)");
"Checked
Out By"=$item.CheckedOutBy;
"Author"=$item.File.CheckedOutByUser.Name;
"Checked
Out Since"=$item.CheckedOutDate.ToString();
"File
Size (KB)"=$item.File.Length/1000;
"Email"=$item.File.CheckedOutByUser.Email;
}
New-Object
PSObject -Property
$writeTable
}
catch{
write-host "Issue in
First Loop() with..." +$list.RootFolder.ServerRelativeUrl
+$_.Exception.Message -BackgroundColor
DarkGray
}
}}
#deleted from here
if($list.ItemCount -gt
0)
{
foreach ($item
in $list.Items) {
try
{
if
($item.File.CheckOutStatus -ne
"None") {
if
(($list.CheckedOutFiles
| where {$_.ListItemId
-eq $item.ID}) -ne $null) { continue
}
$writeTable
= @{
"URL"=$spWeb.Site.MakeFullUrl("$($spWeb.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)");
"Checked
Out By"=$item.File.CheckedOutByUser.LoginName;
"Author"=$item.File.CheckedOutByUser.Name;
"Checked
Out Since"=$item.File.CheckedOutDate.ToString();
"File Size (KB)"=$item.File.Length/1000;
"Email"=$item.File.CheckedOutByUser.Email;
}
$writeCollArray= New-Object PSObject
-Property $writeTable;
$writeColl+=$writeCollArray
}
}
catch
{
write-host "Issue in
Second Loop() with..." +$list.RootFolder.ServerRelativeUrl
"Item ID:"$item.ID +$_.Exception.Message
-BackgroundColor DarkGray
}
}
}
}
$writeColl | Export-Csv $CsvReportFile
$spWeb.Dispose()
}
catch
{
write-host " Exception
in GetCheckedItems().." +$_.Exception.Message
-BackgroundColor DarkGray
}
}
Function GetReport($CSVPath)
{
Write-Host "Process
Started...."
try
{
#Import
the CSV File
$CSVData
= Import-CSV
-Path $CSVPath
foreach($row in $CSVData)
{
try
{
Write-Host
"Generating Report For:: " $row.SiteUrl;
GetCheckedItems($row.SiteUrl)
}
catch
{
write-host
$row.SiteUrl
"does not exist..." +$_.Exception.Message -BackgroundColor
DarkGray
}
}
}
catch
{
write-host
"Error while performing the operation..."+$_.Exception.Message -foregroundcolor
red
break
}
Write-Host "Process Completed...."
}
GetReport("F:\Mahesh\BaseCSV\CheckedOutSites.csv")
Note:
In the above script “CheckedOutSites.csv” is as csv file contains my site Urls.
Script 2:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
[void][System.reflection.Assembly]::Load("System, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089")
[System.Collections.ArrayList]
$AL = new-object System.Collections.ArrayList
$AL.Add("Url,Name,Checked
out by,Checked out user email id") |
Out-Null
$stream
= [System.IO.StreamWriter]
"D:\SharePointMigration\CheckedOutItemsList.csv"
function
Get-CheckedOutFiles($web)
{
foreach ($list
in ($web.Lists | ? {$_ -is [Microsoft.SharePoint.SPDocumentLibrary]}))
{
Write-Host “`tProcessing
List: $($list.RootFolder.ServerRelativeUrl)…”
$count =
0
$delimiter =
","
foreach ($item
in $list.CheckedOutFiles)
{
if (!$item.Url.EndsWith(“.aspx”))
{ continue }
$url
= $web.Site.MakeFullUrl(“$($web.ServerRelativeUrl.TrimEnd(‘/’))/$($item.Url)”);
$hash =
@{
“URL”=
$web.Site.MakeFullUrl(“$($web.ServerRelativeUrl.TrimEnd(‘/’))/$($item.Url)”);
“CheckedOutBy”=$item.CheckedOutBy;
“CheckedOutByEmail”=$item.CheckedOutByEmail
}
# New-Object PSObject -Property $hash
$tempAL =
""
$Name =
$item.Name
$tempAL = $url + $delimiter +
$Name +
$delimiter +
$item.CheckedOutBy
+ $delimiter
+ $item.CheckedOutByEmail
$AL.Add($tempAL) | Out-Null
$count++;
}
$count =
0;
foreach ($item
in $list.Items)
{
if ($item.File.CheckOutStatus
-ne “None”)
{
if (($list.CheckedOutFiles |
where {$_.ListItemId -eq
$item.ID})
-ne $null)
{ continue }
$url =
$web.Site.MakeFullUrl(“$($web.ServerRelativeUrl.TrimEnd(‘/’))/$($item.Url)”);
$hash = @{
“URL”=$web.Site.MakeFullUrl(“$($web.ServerRelativeUrl.TrimEnd(‘/’))/$($item.Url)”);
“CheckedOutBy”=$item.File.CheckedOutBy;
“CheckedOutByEmail”=$item.File.CheckedOutBy.Email
}
# New-Object PSObject -Property $hash
$Name = $item.Name
$tempAL = $url + $delimiter +
$Name +
$delimiter +
$item.File.CheckedOutBy +
$delimiter +
$item.File.CheckedOutBy.Email;
$AL.Add($tempAL) | Out-Null
$count++;
}
}
}
}
function
GetAllSites ($CsvFilePath)
{
write-host "Process
Started ...."
try
{
$CSVData =
Import-CSV -Path
$CsvFilePath
foreach($row
in $CSVData)
{
try
{
write-host "Fetching
the Site : " $row.Url;
$site = new-object Microsoft.SharePoint.SPSite($row.Url)
foreach($web
in $site.AllWebs)
{
Get-CheckedOutFiles($web)
$web.Dispose()
}
$site.Dispose()
catch
{
write-host $row.Url "does not
exist..." +$_.Exception.Message
-BackgroundColor DarkGray
}
}
}
catch
{
write-host "Error
while performing the operation..."+$_.Exception.Message
-foregroundcolor red
break
}
write-host "Process
Ended ...."
}
GetAllSites("F:\SPMigration\WSS_Conten324_CTOReport.csv")
foreach($AR in $AL)
{
$stream.WriteLine($AR)
}
$stream.Close()
Hope it helps,
Thanks.
0 comments:
Post a Comment