Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-06-28
2
Medium Priority
?
349 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 2000 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

721 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