Un-Provision Search Service Application in SharePoint 2013

sometimes it gets tricky when you want to remove Search Service Application (SP2013) from your farm. Especially, when you have multiple servers that service your search platform. 

Before you remove the search services from your farm, I highly recommend you stop all timer jobs and then use STSADM command to remove the search service application. Sometimes, when you request to delete the databases of search as well, it may get a little complicated if the database gets removed but the service application still remains. 

First, make sure you are patient enough : don’t try to stop your commands. Sometimes it takes a while to unprovision search. But in case you loose your patience, just do the followings:

Step 1) Stop all active timer jobs, how? easy: 

Get-spTimerJob | where { !$_.IsDisabled } | SELECT ID | out-file enabledjobs.txt

Step 2) clean up this text file so there will be only the Guids of the enabled timer jobs.

Step 3) Then disable all timer jobs listed in the .txt file: 

Get-Content EnabledJobs.txt | Foreach-Object {Disable-SPTimerJob $_ }

Step 5) Now, simply run this command to get the list of all of the service applications:

Get-SPServiceApplication

Step 6) copy the GUID for the service application and paste it in the following command

stsadm -o deleteconfigurationobject -id <GUID>

Step 7) Then, as soon as you see “Operation completed successfully”, run this command to get the GUID for the search svc proxy:

Get-SPServiceApplicationProxy

Step 8) Copy the guid and use it in the following cmdlet:

Remove-SPServiceApplicationProxy <GUID>

Step 9) now it’s time to enable all the timer jobs you disabled: 

Get-Content EnabledJobs.txt | Foreach-Object {Enable-SPTimerJob $_ }

Step 10) Share your experience with others !

Posted in Uncategorized | Tagged | Leave a comment

How to find all Search Scopes in SharePoint 2010

$SsaNames = @(“your ssa1”, “your SSA2”)
foreach($SsaName in $SsaNames){
$SearchServiceApplication = Get-SPEnterpriseSearchServiceApplication -Identity $SsaName -ErrorAction SilentlyContinue
$scopes = Get-SPEnterpriseSearchQueryScope -SearchApplication $SsaName
“Scopes for $SsaName”
“———————————-“
$scopes
}

Posted in Uncategorized | Leave a comment

How to find the content source and Start Address of your search Service Applications (SP 2010)

$SsaNames = @(“your SSA1”, “Your SSA2, “…”)
foreach($SsaName in $SsaNames){
“————–$SsaName————————–“
$SearchServiceApplication = Get-SPEnterpriseSearchServiceApplication -Identity $SsaName -ErrorAction SilentlyContinue
$ContentSources = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $SearchServiceApplication
$ContentSources | ForEach-Object {
Write-Host ” ContentSource:\>” $_.Name
foreach ($address in $_.StartAddresses){
Write-Host “$address”
}

}
}

Posted in Uncategorized | Leave a comment

Multiple User Profile Services in your Farm?

Before spending too much time on fixing issues related to creating new user profile services in a farm that already has a user profile service, you’d better to remember this:

“There should be a one to one relationship between Servers and User Profile Services”. It means you can only associate one service instance to a server in your farm. If you try to create more services on the same server, then you will have issues to create new connections and the service will complain of lack of a UP Sync Service on the server. 

Posted in Uncategorized | Leave a comment

PowerShell to record the General Settings of a SharePoint Web Application

This simple PowerShell script saves a lot of time for getting or setting properties of web applications in a farm. In order to have an easier access to individual properties, We have created a key,expression combination to facilitate exporting to CSV files or to use Format-List. It’s also comes so handy to filter based on any properties. I have encapsulated the key,value creation into “Export-WebApp” function:

function Export-WebAppInfo
{
PARAM
(
$arrWebApps
)

$arrWebApps | Select-Object -Property `
@{Name=”DefaultTimeZone”;Expression={
$_.DefaultTimeZone
}},`
@{Name=”PresenceEnabled”;Expression={
$_.PresenceEnabled
}},`
@{Name=”AlertsEnabled”;Expression={
$_.AlertsEnabled

         }}| Sort-Object -Property Name

}

 

This time saver function can be extended to include any number of property of your object (SPWebApplicatoin in our case):

#define the Array to hold all SPWebApplication objects within the farm
[array]$arrWebApps = @()
#Assign the web applications to the array
$arrWebApps = Get-SPWebApplication
#define the variable to get the exported array of web applications
$webAppOutExportOutput = @()

#Call Export-WebAppInfo to export the settings of web applications to our parameter
#Don’t forget to pass in the array to which we stored the SPWebApplication objects
$webAppOutExportOutput += Export-WebAppInfo $arrWebApps

#enjoy your new object. use it as you wish:
#I needed to store it to a csv file for later comparisons
$webAppOutExportOutput|Export-Csv “WebAppStatus.txt”

you may use this sort of PowerShell scripts when you need to compare your environment before and after an update or an upgrade. 

 

 

 

 

Posted in Uncategorized | Leave a comment

Get Permission of a Directory /Path in PowerShell

 

 

function Get-PathPermissions {

param ( [Parameter(Mandatory=$true)] [System.String]${Path} )

    begin {

    $root = Get-Item $Path

    ($root | Get-Acl).Access | Add-Member -MemberType NoteProperty -Name “Path” -Value $($root.fullname).ToString() -PassThru

    }

    process {     #make sure the children we are targetting is a folder not a file.     $containers = Get-ChildItem -path $Path -recurse | ? {$_.psIscontainer -eq $true}

    if ($containers -eq $null) {break}

        foreach ($container in $containers)

        {         #Capture the folders that have individual permissions rather than inherriting from the parent         (Get-ACL $container.fullname).Access | ? { $_.IsInherited -eq $false } | Add-Member -MemberType NoteProperty -Name “Path” -Value $($container.fullname).ToString() -PassThru

        }                                                                                                                   }

}

Get-PathPermissions “c:\IT\” | Select-Object Path, IdentityReference, IsInherited | Export-Csv “c:\DirectoryInfo\permissions_test.csv”

Posted in Uncategorized | Tagged | Leave a comment

Begin-Process-End Sample in PowerShell

 

 

Function Calculate
 {
  Param ($Param1)
  Begin{
  Clear-Host
  write-host “adding numbers”
  Write-Host “————————————-“
  $total = 0
  }
  Process{
  write-host $Param1 : $_
 
  $total = $total + ($_ -as [Int32])
  }
  End{write-host “the total is : ” $total}
 }
 Echo Testing1, Testing2 | Test-Demo Sample
 echo 1,2,3,5,6 | Calculate Adding
 
 

Posted in Uncategorized | Tagged | Leave a comment

Recursion on Childrent in PowerShell

this little scipt finds all non-exe files within a file system:

# PowerShell script to find executables in the Windows\System32 folder
Clear-Host
$Path = “C:\Windows\System32”
 Get-Childitem $Path -Recurse -ErrorAction SilentlyContinue |`
 where {$_.Extension -NotMatch “exe”} | ft -group {$_.Path} Directory, Name -auto

Posted in Uncategorized | Tagged , | Leave a comment

Parsing html in C#

I was trying to figure out a simple way to parse a HTML response in C#. I had to submit a request to a website on which there was no REST or any other API and then extract some values within the HTML tags. 

I had some custom development First, then I came across some posts that redirected me to CodePlex  Html Agility Pack. This Pack can be installed to you visual Studio Solution by running: 

PM> Install-Package HtmlAgilityPack

in VS2010 (or VS2012) Pakcage Manager Console window. It saved me a lot to extract the properties I needed as shown in this code; the code, directly connects to a server and upon receiving the response document, tries to parse all “td” tag childs within element with ID of ProfileHtml. then it can navigate to sibling to extract the innerText or innerHtml or anything else. you may extract attributes as well. just replace “td” with “a” and extract all the links within the element with the id of “profilehtml”! (replace it with your html tag)

HtmlWeb htmlWeb = new HtmlWeb();

// Creates an HtmlDocument object from an URL

HtmlAgilityPack.HtmlDocument document = htmlWeb.Load(“https://some.server.com/person/007&#8221;);

// Targets a specific node

HtmlNode someNode = document.GetElementbyId(“profilehtml”);

// If there is no node with that Id, someNode will be null

if (someNode != null)

{

// Extracts all links within that node

IEnumerable<HtmlNode> allLinks = someNode.Descendants(“td”);

// Outputs the href for external links

foreach (HtmlNode link in allLinks)

{

// Checks whether the link contains an HREF attribute

//if (link.Attributes.Contains(“href”))

//{

// // Simple check: if the href begins with “http://&#8221;, prints it out

// if (link.Attributes[“href”].Value.StartsWith(“http://&#8221;))

// Console.WriteLine(link.Attributes[“href”].Value);

//}

if (link.InnerText.Contains(“Physical Address”))

{

Console.WriteLine(link.NextSibling.NextSibling.InnerText);

}

 

}

Posted in Uncategorized | Leave a comment

Creating Objects from Properties in Powershell

$Contact = @{
                    “webAddress”=”seyedketabchi.wordpress.com”;
                    “Email”=”Seyed.ketabchi@gmail.com”;
                    “Name”=”Seyed Ketabchi”;
                }
                New-Object PSObject -Property $Contact
                
               $Contact.Name
              

Posted in Uncategorized | Tagged | Leave a comment