Translate

Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

Tuesday, February 10, 2015

To find all the large lists with items count - PowerShell


I have seen many times you have the immediate requirement of getting the large list for any or all the web apps in your SharePoint farm.

Please run this PowerShell for each content database - Best practice is off production hours 

Use wss_content_relatedDBName

SELECT ItemChildCount + FolderChildCount as Items, DirName +'/' + LeafName as RelativePath FROM alldocs WITH(NOLOCK) WHERE ItemChildCount + FolderChildCount > 5000 ORDER BY Items DESC

Thank you!

Thursday, August 21, 2014

PS Script to do the sizing which includes all versions

#-----------------------------------
cls
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
Add-PsSnapin Microsoft.SharePoint.PowerShell
}
$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path C:\outputsize.txt -append
function GetWebSize ($Web)
{
[long]$subtotal = 0
foreach ($folder in $Web.Folders)
{
$subtotal += GetFolderSize -Folder $folder
}
$sitetotal=$subtotal
$SiteInGb = (($sitetotal/1024)/1024)/1024
$SiteInGb = "{0:N4}" -f $SiteInGb
write-host "," $Web.Url "," $SiteInGb ","
write-host "`r`n"
return $subtotal
} 
function GetSubWebSizes ($Web)
{
[long]$subtotal = 0
foreach ($subweb in $Web.GetSubwebsForCurrentUser())
{
[long]$webtotal = 0
foreach ($folder in $subweb.Folders)
{
$webtotal += GetFolderSize -Folder $folder
}
$subsitetotal=$webtotal
$subsiteInGb = (($subsitetotal/1024)/1024)/1024
$subsiteInGb = "{0:N4}" -f $subsiteInGb
write-host "," $subweb.Url "," $subsiteInGb ","
write-host "`r`n"
$subtotal += $webtotal
$subtotal += GetSubWebSizes -Web $subweb
}
return $subtotal
} 
function GetFolderSize ($Folder)
{
[long]$folderSize = 0
foreach ($file in $Folder.Files)
{
if ($file.Versions -ne $NULL -and $file.Versions.Count -gt 1) {
foreach ($version in $file.Versions)
{
$folderSize += $version.Size;
}
}
else {
$folderSize += $file.Length;
}
}
foreach ($fd in $Folder.SubFolders)
{
$folderSize += GetFolderSize -Folder $fd
}
return $folderSize
}

$web = Get-SPWeb $args[0]
[long]$total = 0
$total += GetWebSize -Web $web
$total += GetSubWebSizes -Web $web
$totalInMb = ($total/1024)/1024
$totalInMb = "{0:N4}" -f $totalInMb
$totalInGb = (($total/1024)/1024)/1024
$totalInGb = "{0:N4}" -f $totalInGb
write-host "Total size of all sites below" $StartWeb "is" $total "Bytes,"
write-host "which is" $totalInMb "MB or" $totalInGb "GB"
$web.Dispose()
Stop-Transcript
#--------------------------------------------
To run the above PowerShell - first copy the above code and save in a file with anyname.PS1 and fireup the PowerShell with administrator 
# how to run this script -
c:\>anyname.ps1 http://portal/
OR
c:\>anyname.ps1 http://portal/portal1
OR
c:\>anyname.ps1 http://portal/portal1/portal2


Tuesday, August 12, 2014

Poweshell - Get the list of all template files or layout pages

Not interested in writing big story for small things  :)

List all the template files for given content SharePoint content database -

stsadm.exe -o enumallwebs -databasename <contentdbname>  > c:\template.txt

=====================================
List all page layouts -

$web = get-spweb http://yoursite
$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$pubWeb.GetAvailablePageLayouts() | select Name

List of all master pages for all web apps

Method 1
Get-SPWebApplication | Get-SPSite -Limit All | Get-SPWeb -Limit All | Select Title, URL, MasterUrl | Export-CSV C:\allmasterpage.csv

Method 2
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get All site collections
$SiteCollections = Get-SPWebApplication | Get-SPSite -Limit All
#Loop through all site collections
   foreach($Site in $SiteCollections)
    {
        #Loop throuh all Sub Sites
       foreach($Web in $Site.AllWebs)
       {
      $MasterPage = $Web.GetFile($Web.MasterUrl);
          $MasterPage.Name  +" : " +$Web.Url
       }
    }
     

Content Inventory - Powerful PS

Get-SPWebApplication http://changeweburl.com/ | Get-SPSite -Limit All | Get-SPWeb -Limit All | Select Title, URL | Export-CSV C:\changefilename.csv -NoTypeInformation - This is inventory of all the URLs with Title and URL


Get-SPWeb http://changeweburl/changesite1/changesub-site/ | Select -ExpandProperty Lists | Where { $_.GetType().Name -eq "SPDocumentLibrary" -and  -not $_.Hidden } | Select -ExpandProperty Items | Select Name, url, {$_["Created By"]}, {$_["Modified"]} | Export-CSV C:\changefilename.csv - Content Inventory at sub-site level