Solved

PowerShell - Can't capture this output to a text file

Posted on 2013-06-28
2
338 Views
Last Modified: 2013-06-28
I have the following script that allows me to get all sites in a SharePoint 2007 farm.  I know my mind isn't working right or something.

Clear-Host
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null

$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local 
$websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]} 
$webapps = @()

foreach ($websvc in $websvcs) { 
    foreach ($webapp in $websvc.WebApplications) { 
    foreach ($site in $webapp.Sites) { 

    foreach ($web in $site.AllWebs) { 
        write-host $web.URL 
    }
    }
    }
    } 

Open in new window


Any help is appreciated.

Hank
0
Comment
Question by:Hankinater
2 Comments
 
LVL 1

Accepted Solution

by:
Sunny_2009 earned 500 total points
ID: 39285543
Just add below line within your script
$web.URL | out-file E:\temp\sites.txt -append -width 1000


Note that the path should be changed as per your local file system . For above line to work you should have temp folder in E: drive

Check this Out :
Clear-Host
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null

$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
$webapps = @()

foreach ($websvc in $websvcs) {
    foreach ($webapp in $websvc.WebApplications) {
    foreach ($site in $webapp.Sites) {

    foreach ($web in $site.AllWebs) {
##        write-host $web.URL
$web.URL | out-file E:\temp\sites.txt -append -width 1000
    }
    }
    }
    }
0
 
LVL 2

Author Closing Comment

by:Hankinater
ID: 39285555
That did it!  Thanks Sunny!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
A procedure for exporting installed hotfix details of remote computers using powershell
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now