Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Powershell scripts not writing it to output file

$
0
0

Hi,

Below is my script which loops through all sites and web in a site collection and if the particular web part is added in a page, it will give the page URL and it should be written to a output file.

function enumerateWebParts($Url)
 {
 $webApp = Get-SPWebApplication $Url  #Get WebApplication URL
foreach($web in $webApp | Get-SPSite -Limit All | Get-SPWeb -Limit All) #foreach loop to iterate through all sites and webs of WebApplication
 {
 if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web)) #Check if site is a publishing site
 {
 $pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
 $pages = $pWeb.PagesList
 foreach ($item in $pages.Items)
 {
 $fileUrl = $webUrl + "/" + $item.File.Url

 $manager = $item.file.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared);
  
 $wps = $manager.webparts
 foreach ($type in $wps) #loop through each type found $wps
 {
#Write-Host " type searching";
Write-Host $type.GetType().Name;
 if ($type.GetType().Name -eq "RightMenu") #if webpart $type -like KWizCom select webpart object
 {
Write-Host "found";
 $wps | select-object @{Expression={$pWeb.Url};Label="Web URL"},@{Expression={$fileUrl};Label="Page URL"},DisplayTitle, IsVisible, @{Expression={$type};Label="Type"}
Write-Host $fileUrl;
$page=$pweb.Url+$fileUrl;
Write-Output $page;
 }
 }
 }
 }

 else #if web is not a publishing site
 {
 $pages = $null
 $pages = $web.Lists["Site Pages"]
 if ($pages)
 {
 foreach ($item in $pages.Items)
 {
 $fileUrl = $webUrl + "/" + $item.File.Url

 $manager = $item.file.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared);
 $wps = $manager.webparts
 foreach ($type in $wps)
 {
 if ($type.GetType().Name -eq "RightMenu")
 {
 $wps | select-object @{Expression={$Web.Url};Label="Web URL"},@{Expression={$fileUrl};Label="Page URL"},DisplayTitle, IsVisible, @{Expression={$type};Label="Type"}
Write-Host $fileUrl;
$page=$pweb.Url+$fileUrl;
Write-Output $page;
 }
 }
 }
 }
 else
 {
 }
 }
 # Write-Host “… completed processing” $web
 }
 }

$row = enumerateWebParts(‘http://sptest.danfoss.net’) #call the enumerateWebParts function pass it the URL for the web application



 
 

I run the command through D:\RightMenu.ps1 | Out-File D:\RightMenu.txt

Aruna


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>