گزارش های ادمینی Power Shell
یافتن سایت هایی که در وب اپلیکیشن بیشترین استفاده را دارد.
#Set-ExecutionPolicy RemoteSigned
[System.Reflection.Assembly]
::LoadWithPartialName(
"Microsoft.SharePoint"
)
$url
=
"https://sharePoint.company.com"
$site
=
New-Object
Microsoft.SharePoint.SPSite(
$url
)
$spWebApp
=
$site
.WebApplication
$OutputFN
=
"c:\ActiveSitesReport.csv"
"Site Name `t URL `t Last Modified"
>
$OutputFN
# Iterate through all sites:
foreach
(
$spSite
in
$spWebApp
.Sites )
{
foreach
(
$spWeb
in
$spSite
.AllWebs)
{
if
(
$spWeb
.IsRootWeb)
{
$siteName
=
$spWeb
.Title +
" - Root"
;
}
else
{
$siteName
=
$spSite
.RootWeb.Title +
" - "
+
$spWeb
.Title;
}
$siteName
+
"`t"
+
$spWeb
.Url +
"`t"
+
$spWeb
.LastItemModifiedDate >>
$OutputFN
$spWeb
.Dispose()
}
$spSite
.Dispose()
}
حجم Sub Site ها
#Get Size of all Sub-sites in a Site Collection
[void][System.Reflection.Assembly]
::LoadWithPartialName(
"Microsoft.SharePoint"
)
# Function to calculate folder size
Function
CalculateFolderSize(
$Folder
)
{
[long]
$FolderSize
= 0
foreach
(
$File
in
$Folder
.Files)
{
#Get File Size
$FolderSize
+=
$file
.TotalLength;
#Get the Versions Size
foreach
(
$FileVersion
in
$File
.Versions)
{
$FolderSize
+=
$FileVersion
.Size
}
}
#Iterate through all subfolders
foreach
(
$SubFolder
in
$Folder
.SubFolders)
{
#Call the function recursively
$FolderSize
+= CalculateFolderSize
$SubFolder
}
return
$FolderSize
}
$SiteURL
=
"https://sharepoint.company.com/"
$Site
=
new-object
Microsoft.SharePoint.SPSite(
$SiteURL
)
foreach
(
$Web
in
$Site
.AllWebs)
{
#Call function to calculate Folder Size
[long]
$WebSize
= CalculateFolderSize(
$Web
.RootFolder)
#Get Recycle Bin Size
foreach
(
$RecycleBinItem
in
$Web
.RecycleBin)
{
$WebSize
+=
$RecycleBinItem
.Size
}
$Size
=
[Math]
::Round(
$WebSize
/1MB, 2)
Write-Host
$web
.Url
":`t"
$Size
"MB"
#Dispose the object
$web
.dispose()
}
یافتن سایت ها و لیست های دارای دسترسی منحصر به فرد
Add-PSSnapin
Microsoft.SharePoint.PowerShell
-ErrorAction
SilentlyContinue
#Get All Web Applications
$webApps
=
Get-SPWebApplication
#"https://sharepoint.company.com"
#Write Header to CSV File
"Site/List `t Title `t URL"
|
out-file
UniquePermissions.csv
foreach
(
$webApp
in
$webApps
)
{
foreach
(
$site
in
$webApp
.Sites)
{
foreach
(
$web
in
$site
.AllWebs)
{
if
( (
$web
.HasUniqueRoleAssignments)
-and
(
$web
.IsRootWeb
-eq
$false
))
{
$result
=
"Site `t $($web.Title) `t $($web.Url)"
$result
|
Out-File
UniquePermissions.csv
-Append
#You can get the permissions applied by: $web.permissions | format-list member, basepermissions
}
foreach
(
$list
in
$web
.Lists)
{
if
((
$list
.HasUniqueRoleAssignments)
-and
(
$list
.Hidden
-eq
$false
))
{
$result
=
"List `t $($list.Title) `t $($list.Url)"
$result
|
Out-File
UniquePermissions.csv
-Append
}
}
$web
.Dispose()
}
$site
.Dispose()
}
}
یافتن یوزر ایجاد کننده یا اصلاح کننده مدرک در تاریخ مشخص
Add-PSSnapin
Microsoft.SharePoint.PowerShell
-ErrorAction
SilentlyContinue
# Set the date Filter
$dateFilter
= (
Get-Date
).AddMonths(-1)
#Past Month
"File, Created Time, File Size"
|
out-file
NewDocuments.csv
# Get all Webs
$webs
=
Get-SPWebApplication
"https://sharepoint.crescent.com"
|
Get-SPSite
-Limit
All |
Get-SPWeb
-Limit
All
#Iterate through webs
ForEach
(
$web
in
$webs
)
{
#Iterate through All Lists
ForEach
(
$list
in
$web
.Lists)
{
#Check for Document Libraries
If
(
$list
.BaseType
-eq
"DocumentLibrary"
)
{
#Iterate through All documents
ForEach
(
$item
in
$list
.Items)
{
If
(
$item
.URL.StartsWith(
"_"
)) {
Break
}
#Skip _catalogs, etc
If
(
$item
.URL.EndsWith(
".aspx"
)) {
Break
}
#Skip Form pages
If
(
$item
.File.TimeCreated
-ge
$dateFilter
)
{
$result
=
"""$($web.URL)/$($item.URL)"", $($item.File.TimeCreated), $( [Math]::Round($item.File.Length/1024,2))"
$result
|
Out-File
NewDocuments.csv
-Append
}
}
}
}
}
یافتن فایل های حجیم (بیش از 50 مگابایت) در سطح وب اپلیکیشن
Add-PSSnapin
Microsoft.SharePoint.PowerShell
-ErrorAction
SilentlyContinue
Function
Get-LargeDocuments
(
[string]
$WebAppURL
)
{
$WebApp
=
Get-SPWebApplication
$WebAppURL
foreach
(
$SPSite
in
$WebApp
.Sites)
{
foreach
(
$SPWeb
in
$SPSite
.AllWebs)
{
foreach
(
$SPList
in
$SPWeb
.Lists)
{
# Get Document Libraries
if
(
$SPList
.BaseType
-eq
"DocumentLibrary"
)
{
foreach
(
$item
in
$SPList
.Items)
{
$data
= @{
"Site"
=
$SPSite
.Url
"Web"
=
$SPWeb
.Url
"list"
=
$SPList
.Title
"Item URL"
=
$item
.Url
"Item Name"
=
$item
.Name
"Item Created"
=
$item
[
"Created"
]
"Item Modified"
=
$item
[
"Modified"
]
"Size (KB)"
=
$item
.File.Length/1KB
"Size (MB)"
=
$item
.File.Length/1MB
}
# add files larger than 50 MB to the Output
if
(
$item
.File.Length
-gt
50MB)
{
Write-Host
(
$SPSite
.Url +
"/"
+
$item
.Url)
New-Object
PSObject
-Property
$data
}
}
}
$SPWeb
.Dispose();
}
$SPSite
.Dispose()
}
}
}
#call the function
Get-LargeDocuments
"https://sharepoint.crescent.com"
|
Export-Csv
-NoTypeInformation
-Path
"C:\LargeDocuments.csv"
Site Traffic Hits Report on Every Item on a SharePoint Site
[void][System.Reflection.Assembly]
::LoadWithPartialName(
"Microsoft.SharePoint"
)
#Functions to Imitate SharePoint 2010 Cmdlets in MOSS 2007
function
global:
Get-SPWeb
(
$url
)
{
$site
=
New-Object
Microsoft.SharePoint.SPSite(
$url
)
if
(
$site
-ne
$null
)
{
$web
=
$site
.OpenWeb();
}
return
$web
}
#Method to Get Usage Data
Function
GetWebUsageData(
$Web
)
{
try
{
#DataTable for Hits result - Because GetUsageData returns DataTable!
$dtHits
=
New-Object
System.Data.DataTable
$dtHits
=
$Web
.GetUsageData(
"url"
,
"lastMonth"
)
if
(
$dtHits
-ne
$null
)
{
return
(
$dtHits
);
}
else
{
return
(
$null
);
}
}
catch
{
Write-Host
$_
.Exception.Message
-ForegroundColor
Red
return
(
$null
);
}
}
$WebURL
=
"https://sharepoint.crescent.com/operations/sfdc/"
$CurrentPath
=
Split-Path
-Parent
-Path
$MyInvocation
.MyCommand.Definition
$OutPutFile
=
Join-path
$CurrentPath
"SiteUsageReport.txt"
#Get the Web
$Web
=
Get-SPWeb
$WebURL
#create a CSV file
"Page `t Total Hits `t Last Accessed"
>
$OutPutFile
#Write the Headers in to a text file
#Get the Hits Data
$HitsDT
= GetWebUsageData(
$Web
)
if
(
$HitsDT
-ne
$null
)
{
foreach
(
$dr
in
$HitsDT
)
{
$result
=
$webURL
+
"/"
+
$dr
[
"Folder"
]+
"/"
+
$dr
[
"Page"
] +
"`t"
+
$dr
[
"Total Hits"
] +
"`t"
+
$dr
[
"Most Recent Day"
]
$result
>>
$OutPutFile
#append the data
}
}
بررسی بزرگتر بودن تاریخ از تاریخ روز
[void][System.Reflection.Assembly]
::LoadWithPartialName(
"Microsoft.SharePoint"
)
#Region MOSS-2007-Cmdlets
Function
global:
Get-SPSite
(
$url
)
{
if
(
$url
-ne
$null
)
{
return
New-Object
Microsoft.SharePoint.SPSite(
$url
)
}
}
Function
global:
Get-SPWeb
(
$url
)
{
$site
=
Get-SPSite
(
$url
)
if
(
$site
-ne
$null
)
{
$web
=
$site
.OpenWeb();
}
return
$web
}
#EndRegion
Function
GeneratePermissionReport()
{
#Site Collection URL - Mandatory parameter
param
([
Parameter
(
Mandatory
=
$true
)]
[string]
$SiteCollectionURL
)
#Get the site collection
$Site
=
Get-SPSite
$SiteCollectionURL
$web
=
$site
.RootWeb
#Get HTML File with CSS into the Output report
$Content
=
Get-Content
-Path
"table.htm"
> PermissionReport.htm
"<h2> $($Site.RootWeb.Title) - Permission Report</h2>"
|
out-file
"PermissionReport.htm"
-Append
#Table of Contents
"<h3> List of Sites under $($Site.RootWeb.Title)</h3> <table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr><th>Site Name </th><th> URL </th></tr>"
>> PermissionReport.htm
#Get Users of All Webs : Loop throuh all Sub Sites
foreach
(
$Web
in
$Site
.AllWebs)
{
"<tr> <td> <a href='#$($web.Title.ToLower())'>$($web.Title)</a> </td><td> $($web.URL)</td> </tr>"
>> PermissionReport.htm
}
#Get Users of All Webs : Loop throuh all Sub Sites
foreach
(
$Web
in
$Site
.AllWebs)
{
#Check if site is using Unique Permissions or Inheriting from its Parent Site!
if
(
$Web
.HasUniqueRoleAssignments
-eq
$true
)
{
"</table><br/><hr> <h3>Site: [ <a name='$($Web.Title.ToLower())'>$($Web.Title) </a> ] at <a href='$($web.URL)'>$($web.URL)</a> is using Unique Permissions. </h3>"
>> PermissionReport.htm
}
else
{
"</table><br/><hr> <h3>Site: [ <a name='$($Web.Title.ToLower())'>$($Web.Title) </a> ] at <a href='$($web.URL)'>$($web.URL)</a> is Inheriting Permissions from its Parent Site.</h3>"
>> PermissionReport.htm
}
if
(
$Web
.HasUniqueRoleAssignments
-eq
$true
)
{
"<b>Site Users and Groups</b><table class='altrowstable' id='alternatecolor' cellpadding='5px'>"
>> PermissionReport.htm
#Get the Role Assignments - (Users & Groups Granted access to the site) with each Role
foreach
(
$RoleDefinition
in
$Site
.RootWeb.RoleDefinitions)
{
#Write-Host $RoleDefinition.Name
#Write Table Caption
"<tr><th colspan='3'> <b>Permission Level: $($RoleDefinition.Name) <b> </th></tr>"
>> PermissionReport.htm
#Write Table Header
"<tr> <td><b>Users/Groups </b></td> <td><b> Type </b></td> <td><b>User Name</b></td></tr>"
>> PermissionReport.htm
foreach
(
$WebRoleAssignment
in
$web
.RoleAssignments)
{
foreach
(
$RoleDefinitionBinding
in
$WebRoleAssignment
.RoleDefinitionBindings)
{
#If the current Role assignment contains the Site's Role Definition?
if
(
$RoleDefinitionBinding
.Name
-contains
$RoleDefinition
.Name)
{
#**** Get User/Group Type *****#
#Is it a SharePoint Group?
if
(
$WebRoleAssignment
.Member.LoginName
-eq
$NULL
)
{
$Type
=
"SharePoint Group"
$UserName
=
$WebRoleAssignment
.Member.Name
#Set Flag value for "Group Exists"
$GroupExistsFlag
=
$true
}
#Is it a SharePoint User Account or Domain Group?
else
{
$UserName
=
$WebRoleAssignment
.Member.LoginName
#Is it a Domain Group?
if
(
$WebRoleAssignment
.Member.IsDomainGroup)
{
$Type
=
"Domain Group"
}
else
{
$Type
=
"SharePoint User"
}
}
#Send Data to Report
"<tr> <td> $($WebroleAssignment.Member.Name) </td><td> $($Type) </td><td> $($UserName) </td> </tr>"
>> PermissionReport.htm
}
}
}
}
"</table></br> "
>> PermissionReport.htm
if
(
$GroupExistsFlag
-eq
$true
)
{
#**** Get All Members Group and its users ****
"<b>Group Members</b><table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr>"
>> PermissionReport.htm
foreach
(
$WebRoleAssignment
in
$web
.RoleAssignments)
{
#Check if its a group
if
(
$WebRoleAssignment
.Member.GetType().FullName
-eq
"Microsoft.SharePoint.SPGroup"
)
{
"<th colspan='2'><b>Group Name: $($WebRoleAssignment.Member.Name)<b></th></tr><tr><td><b>User ID</b></td><td><b>User Name</b></td></tr>"
>> PermissionReport.htm
foreach
(
$User
in
$WebRoleAssignment
.Member.users)
{
"<tr><td> $($User.LoginName) </td><td> $($User.Name) </td></tr>"
>> PermissionReport.htm
}
}
}
"</table> "
>> PermissionReport.htm
}
#Reset Group Exists Flag
$GroupExistsFlag
=
$false
}
#*** Get All List & Library permissions with Unique Access ***#
foreach
(
$List
in
$Web
.lists)
{
#Skip the Hidden Lists
if
( (
$List
.HasUniqueRoleAssignments
-eq
$True
)
-and
(
$List
.Hidden
-eq
$false
))
{
"</table><br/><b>Users and Groups in List: [ $($List.Title) ] at <a href='$($List.ParentWeb.Url)/$($List.RootFolder.Url)'>$($List.ParentWeb.Url)/$($List.RootFolder.Url)</a> with Unique Permissions.</b><table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr>"
|
Out-File
PermissionReport.htm
-Append
"<td><b>Users/Groups </b></td><td> <b> Type </b></td><td><b> User Name </b></td></tr>"
>> PermissionReport.htm
foreach
(
$RoleDefinition
in
$site
.RootWeb.RoleDefinitions)
{
"<tr><th colspan='3'> Permission Level: $($RoleDefinition.Name) </th></tr>"
>> PermissionReport.htm
#Get all the users granted permissions to the list
foreach
(
$ListRoleAssignment
in
$List
.RoleAssignments )
{
foreach
(
$RoleDefinitionBinding
in
$ListRoleAssignment
.RoleDefinitionBindings)
{
if
(
$RoleDefinitionBinding
.Name
-contains
$RoleDefinition
.Name)
{
#*** Get User/Group Name *****#
$UserGroupName
=
$ListRoleAssignment
.Member.Name
#**** Get User/Group Type *****#
#Is it a SharePoint Group?
if
(
$ListRoleAssignment
.Member.LoginName
-eq
$NULL
)
{
$Type
=
"SharePoint Group"
$UserName
=
$ListRoleAssignment
.Member.Name
}
#Is it a SharePoint User Account or Domain Group?
else
{
$UserName
=
$ListRoleAssignment
.Member.LoginName
#Is it a Domain Group?
if
(
$ListRoleAssignment
.Member.IsDomainGroup)
{
$Type
=
"Domain Group"
}
else
#if($ListRoleAssignment.Member.LoginName)
{
$Type
=
"SharePoint User"
}
}
#Send the Data to Log file
"<tr><td>$($UserGroupName) </td><td> $($Type) </td><td> $($UserName) </td></tr>"
>> PermissionReport.htm
}
}
}
}
}
}
#Dispose web object
$web
.dispose()
}
#*** Get Site Collection Permission Levels & Their base Permissions ***#
"</table> <h2> Site Collection's Permission Levels & Their Base permissions </h2><p>"
>>PermissionReport.htm
$site
.RootWeb.RoleDefinitions |
Where-Object
{
$_
.hidden
-eq
$false
} |
ForEach-Object
{
"<b>Permission Level Name:</b> $($_.Name) <br/> <b> Permissions: </b>$($_.BasePermissions) <br/></p>"
>>PermissionReport.htm
}
"</body></html>"
>>PermissionReport.htm
#Dispose the objects
$Site
.dispose()
}
#Call the function to Generate Report
GeneratePermissionReport
"https://sharepoint.crescent.com"
Get All Site Collections Size (Storage Used, Allocated), Owners, Database Details with STSADM
Stsadm -o EnumSites -url https://Sharepoint-web-app-URL
Stsadm -o EnumSites -url https://Sharepoint-web-app-URL > SitesInfo.xm
Find All Large Lists Exceeding Threshold Limit in SharePoint using PowerShell
Add-PSSnapin
Microsoft.SharePoint.PowerShell
-ErrorAction
SilentlyContinue
#Get All Web Applications
$WebAppsCollection
=
Get-SPWebApplication
#Array to Hold Result - PSObjects
$LargeListsResult
= @()
foreach
(
$WebApp
in
$WebAppsCollection
)
{
#Get the Throttling Limit of the Web App
$Threshold
=
$WebApp
.MaxItemsPerThrottledOperation
foreach
(
$Site
in
$WebApp
.Sites)
{
foreach
(
$Web
in
$Site
.AllWebs)
{
Write-host
"Scanning site:"
$Web
.URL
foreach
(
$List
in
$Web
.Lists)
{
if
(
$list
.ItemCount
-gt
$Threshold
)
{
$Result
=
New-Object
PSObject
$Result
|
Add-Member
NoteProperty Title(
$list
.Title)
$Result
|
Add-Member
NoteProperty URL(
$web
.URL)
$Result
|
Add-Member
NoteProperty Count(
$list
.ItemCount)
#Add the object with property to an Array
$LargeListsResult
+=
$Result
}
}
}
}
}
Write-host
"Total Number of Large Lists Found:"
$LargeListsResult
.Count
-f
Green
#Export the result Array to CSV file
$LargeListsResult
|
Export-CSV
"c:\LargeListData.csv"
-NoTypeInformation