Solved

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

Posted on 2013-06-28
2
347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

636 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