Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
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...
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
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…

739 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