Powershell可以获取网站集和“子网站"的大小与OOTB存储指标的大小不匹配-缺少什么 [英] Powershell to get size for site collection and "subsites" does not matches the size as per OOTB storage metrics-what is missing

查看:57
本文介绍了Powershell可以获取网站集和“子网站"的大小与OOTB存储指标的大小不匹配-缺少什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<# Commented out for later use.
 Description: Script used to Get the stats for the given site collection                           
                                                           
 
#>

param( 
    [string] $url= "https://www.dev6888.snp-dev.kktet.com/sites/Enk", #$(throw "No URL parameter! Usage: GetUseageSPSitePerMonth.ps1 [site collection url] [Year][Report Location]"),
    [string] $year = "2015", #$(throw "No Year parameter! Usage: GetUseageSPSitePerMonth.ps1 [site collection url] [Year][File Path]"),
	[string] $cSVFilePath = "D:\Sudhanshu-USIT\EnCreport2015KB_2.csv"  #$(throw "No FilePath parameter! Usage: GetUseageSPSitePerMonth.ps1 [site collection url] [Year][CSV File Path]")
    
)

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
function Get-Stats {
        $createdDate =$((Get-Date).ToString())  #Get-Date -format G       
		$dates = ($year +"-01-01" ),($year +"-02-01") ,($year +"-03-01"),($year +"-04-01"),($year +"-05-01"),($year +"-06-01"),($year +"-07-01"),($year +"-08-01"),($year +"-09-01"),($year +"-10-01"),($year +"-11-01"),($year +"-12-01")
		$header = "URL,Name,ContentDB,DBSize in GB,SiteSize in KB,January Hits, January Unique Visitor,February Visitor,February Unique Visitor,March Visitor, March Unique Visitor,April Hits, April Unique Visitor,May Hits,May Unique Visitor,June Hits,June Uunique Visitor,July Hits,July Unique Visitor,August Hits,August Unique Visitor,September Hits, September Unique Visitor,October Hits,October Unique Visitor,November Hits,November Unique Visitor,December Hits,December Unique Visitor,Created Date"
				
		$location = $cSVFilePath| split-path
		$tempTxtFile = $location + "\templog"  +".txt"
		$header | Out-File $tempTxtFile 
		
		$searchApp = Get-SPEnterpriseSearchServiceApplication
	    $site = Get-SPSite $url

		$rootresult = $searchApp.GetRollupAnalyticsItemData(1,[System.Guid]::Empty,$site.ID,[System.Guid]::Empty)
		$ContentDBSizeInKB = $site.Usage.Storage
        $ContentDBSizeInGB = $SizeInKB/1024/1024/1024

        #$web = Get-SPWeb $site
    [long]$total = 0
   # $total += GetWebSize -Web $web
    #$total += GetSubWebSizes -Web $web
    $totalInkb = ($total/1024)
    $totalInMb = ($total/1024)/1024
    #$totalInMb = "{0:N2}" -f $totalInMb
    $totalInGb = (($total/1024)/1024)/1024
   # $totalInGb = "{0:N2}" -f $totalInGb

		[string]$statspersite = $site.URL + "Over All Hits -" +","+ $site.Name+","+$site.ContentDatabase.Name+","+$ContentDBSizeInGB+","+$totalInkb
		foreach ($datString in $dates) {
			
			$date = Get-Date $datString
			[System.Int32]$hits =0
			[System.Int32]$uniqueVisitor =0
			
		    $month =$date.Month
			try {
				$output = $rootresult.GetMonthlyData($date,[REF]$hits,[REF]$uniqueVisitor) 
			} catch {	}
			
			$statspersite += "," + [System.string]$hits +"," +[System.string]$uniqueVisitor

		}
        $statspersite+=","+""
		$statspersite | Out-File $tempTxtFile -Append
		$statspersite
		foreach($web in $site.AllWebs)
		{
            [long]$total = 0
            $total += GetWebSize -Web $web
            $total += GetSubWebSizes -Web $web
            $totalInkb = ($total/1024)
            $totalInMb = ($total/1024)/1024
            #$totalInMb = "{0:N2}" -f $totalInMb
            $totalInGb = (($total/1024)/1024)/1024
            #$totalInGb = "{0:N2}" -f $totalInGb

			$result = $searchApp.GetRollupAnalyticsItemData(1,[System.Guid]::Empty,$site.ID,$web.ID)
            $ContentDBSizeInKB = $web.Usage.Storage
            $ContentDBSizeInGB = $SizeInKB/1024/1024/1024

			[string]$statsperWeb = $web.URL+"," +$web.Name+","+$web.ContentDatabase.Name+","+$ContentDBSizeInGB+","+$totalInkb
			foreach ($datString in $dates) {
				
				$date = Get-Date $datString
				[System.Int32]$hits = 0
				[System.Int32]$uniqueVisitor = 0

			    $month =$date.Month
				try {
					$output = $result.GetMonthlyData($date,[REF]$hits,[REF]$uniqueVisitor) 
				} catch {	}
				
				$statsperWeb += "," + [System.string]$hits +"," +[System.string]$uniqueVisitor
			}
            $statsperWeb+=","+$web.Created
			$statsperWeb | Out-File $tempTxtFile -Append
			$statsperWeb
		}
		Import-Csv -Delimiter ',' -Path $tempTxtFile | Export-Csv $cSVFilePath -NoTypeInformation	
}
function GetWebSize ($Web)
{
    [long]$subtotal = 0
    foreach ($folder in $Web.Folders)
    {         
        $subtotal += GetStorageMetrics -Folder $folder
    }
    foreach($recycleBinItem in $web.RecycleBin)
        {
           $websize += $recycleBinItem.Size;
        }
    $subtotal+=$websize
    write-host "Site" $Web.Title "is" $subtotal "KB"
    return $subtotal
}

function GetSubWebSizes ($Web)
{
    [long]$subtotal = 0
    foreach ($subweb in $Web.GetSubwebsForCurrentUser())
    {
        [long]$webtotal = 0
        foreach ($folder in $subweb.Folders)
        {
            $webtotal += GetStorageMetrics -Folder $folder            
        }        
       write-host "Site" $subweb.Title "is" $webtotal "Bytes"
        $subtotal += $webtotal
        $subtotal += GetSubWebSizes -Web $subweb
    }
    return $subtotal
}

function GetFolderSize ($Folder)
{
    [long]$folderSize = 0  
    foreach ($file in $Folder.Files)
    {
        $folderSize += $file.Length;
    }
    foreach ($fd in $Folder.SubFolders)
    {
        $folderSize += GetFolderSize -Folder $fd
    }
    return $folderSize
}

Function GetStorageMetrics($Folder)
{  
    $TotalSize=0
    #Get the size of each file in the folder
    foreach ($File in $Folder.Files)
    {
        #Get File Size
        $FileSize = $File.TotalLength
         
        $VersionSize=0
        #Get the Versions Size
        foreach ($FileVersion in $File.Versions)
        {
            $VersionSize += $FileVersion.Size
        }
        $TotalSize += $VersionSize+ $FileSize 
    }
     
 
      #Get Files in Sub Folders
        foreach ($SubFolder in $Folder.SubFolders)
        {  
         if($SubFolder.Name -ne "Forms") #Leave "Forms" Folder which has List default Aspx Pages.
             {
     #Call the function recursively for the subfolders
                $TotalSize += GetStorageMetrics($SubFolder)         
             }
        }
         
        #Return the object
     return $TotalSize
}
Get-Stats

大家好,

我们通过powershell创建了一个报告,其中提供了年度点击次数,网站,子网站,创建日期和网站大小.

We created a report by powershell which gives yearly hit count,sites,subsites,created date and size of the site.

我们发现,网站大小与OOTB存储指标选项不完全匹配.

We found, sites size is not matching exactly with the OOTB storage metrics option.

此脚本中缺少什么?

我们可以在OOTB页面上做一些事情来获取大小吗(页面:_layouts/15/storman.aspx)在此页面上为什么不存在导出选项无法理解.

Can we do something with OOTB page to get the size (page: _layouts/15/storman.aspx)On this page why export option is not there could not understand.

任何帮助将不胜感激.

sudhanshu sharma做得好,扔进河里:)

sudhanshu sharma Do good and cast it into river :)

推荐答案

Hi sudhanshuSharma, 

Using the following PowerShell to Reset or recalculate the Storage Metrics output:


web = get-spsite https://MSTechtalk.com/
web = get-spsite https://MSTechtalk.com/


web.RecalculateStorageUsed ();
web.RecalculateStorageUsed();

您可以使用PowerShell来获取站点的每个文档库的大小:

You can use PowerShell to get size of each document library for the site:


这篇关于Powershell可以获取网站集和“子网站"的大小与OOTB存储指标的大小不匹配-缺少什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆