Monday, February 13, 2012

Reporting: List all Webs --> Output to Document Library

PowerShell Script:



Add-PsSnapin Microsoft.SharePoint.PowerShell -erroraction silentlycontinue 

$webapp = "intranet"
$log_file = "E:\Tools\WebReport\SC_Report"
$weburl = "http://intranet"
$listname = "SPWeb-Report"
$max_index = 1000


$web = Get-SPWeb -Identity $webUrl
$list = $web.Lists[$listname]
$date =get-date -format yyMMdd
$log_file_date= $log_file + "_" + $date + ".txt"

[array] $sc_output = 0..$max_index

$all_sc= Get-SPSite -WebApplication $webapp -Limit ALL
$i=0

foreach ($webApp in get-SPWebApplication) 
    {     
        foreach ($site in $webApp.Sites) 
        { 
            foreach ($web in get-SPWeb -site $site -limit ALL) 
            { 
                $sc_output[$i]=$web.URL 
  $i++
  $sc_output[$i]="<br>"
  $i++
            } 
       
        } 
    } 

for ($x=$i; $x -le $max_index; $x++)
 {

 $sc_output[$x]=""
 }
$sc_output > $log_file_date




Get-childItem "E:\Tools\WebReport\*.txt" | ForEach-Object {
 $filename = $_.Name
 $byteArray = [System.IO.File]::ReadAllBytes($_.Fullname)
 $item = $list.RootFolder.Files.Add( $filename,$byteArray)
 Start-Sleep -s 2
 }

remove-item $log_file_date



For SP2007 I haven't investigated some time to create such a script, but you can use
stsadm -o enumsites -url "webapplicationurl" --> Output is a simple XML File
If I've to create a Script with stsadm in the future, I'll provide this script as well.

No comments:

Post a Comment