Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Try
{
$webappURL = Read-Host -Prompt "Enter WebApplication URL"
$ssa = Get-SPEnterpriseSearchServiceApplication -Identity "Search Service Application Enterprise"
$allsite = Get-SPSite -WebApplication $webappURL -Limit all
$data = @()
foreach ($site in $allsite)
{
$owner = Get-SPEnterpriseSearchOwner -Level SPWeb -SPWeb $site.URL
$cval = $ssa.GetDefaultResultSource($owner)
$data+= $cval |Select-Object @{expression={$site.URL};label='URL'},@{expression={$cval.Name};label='Result Source Name'}
$subsites = ((Get-SPWeb $site.URL).Site).allwebs
foreach($subsite in $subsites)
{
$owners = Get-SPEnterpriseSearchOwner -Level SPWeb -SPWeb $subsite.URL
$cval1 = $ssa.GetDefaultResultSource($owners)
$data+= $cval1 |Select-Object @{expression={$subsite.URL};label='URL'},@{expression={$cval1.Name};label='Result Source Name'}
}
}
$data | Export-CSV c:\resultsource.csv -NoTypeInformation -Append
Write-Host "Result saved in c:\resultsource.csv" -foregroundcolor "Green"
}
Catch
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Host "Error Msg :$ErrorMessage"
Write-Host "Error Item :$FailedItem"
}
No comments:
Post a Comment