Solved

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

Posted on 2013-06-28
2
342 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article will help you understand what HashTables are and how to use them in PowerShell.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

831 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