About Me

SharePoint Architect with over 17 years of IT Experience in various roles as SharePoint Architect, Administrator, Technical Architect, IT Analyst, Application Developer, CRM Consultant, BI Developer, Microsoft Solution Architect in Client/Server, Web and Enterprise CRM Applications in E-Commerce, Financial, Healthcare, Insurance, Telecom, Outsourcing and Technology Services.
MCITP (Pro): Microsoft Certified IT Professional: SharePoint 2010 Administrator.
MCTS: Microsoft Certified Technology Specialist, SharePoint 2010 Configuration.

Thursday, October 18, 2012

Enumerate Crawl Properties using Powershell

1. Save the following script file as      Get-EnumCrawlProp.ps1
2. Create an input file for Content Sources (just one content source name in one line)
3. Run the script as      PS>Get-EnumCrawlProp.ps1 ProdContentSources.txt

param(
[String]$InputFile = ""
)
If ($InputFile)
{
$ContentSrc = Get-Content $InputFile
$searchapp = Get-SPEnterpriseSearchServiceApplication |where {$_.name -eq "ProdSearchSA1"};
ForEach ($c in $ContentSrc)
{
 $csource = Get-SPEnterpriseSearchCrawlContentSource $c -sea $searchapp;
 #Write-Host "Crawl State for $c " $csource.CrawlState
 $csource.IncrementalCrawlSchedule | select DaysOfWeek, DaysInterval,  StartHour, StartMinute, RepeatInterval, RepeatDuration
}
"Process complete."
}

Set Crawl Incremental/Full Properties using PowerShell

$ssaName="Search Service Application"
$context=[Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($ssaName)
 
$daily=New-Object Microsoft.Office.Server.Search.Administration.DailySchedule($context)
$daily.BeginDay="25"
$daily.BeginMonth = "1"
$daily.BeginYear = "2010"
$daily.StartHour = "2"
$daily.StartMinute = "30"
$daily.DaysInterval = "1"

$weekly=New-Object Microsoft.Office.Server.Search.Administration.WeeklySchedule($context)
$weekly.BeginDay="25"
$weekly.BeginMonth = "1"
$weekly.BeginYear = "2010"
$weekly.StartHour = "23"
$weekly.StartMinute = "15"
$weekly.WeeksInterval = "1"

 $contentsource = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $ssaName -Identity "Local SharePoint Sites"
$contentsource.IncrementalCrawlSchedule=$daily
$contentsource.FullCrawlSchedule=$weekly
$contentsource.Update()

Wednesday, October 17, 2012

Get connections on Server

netstat -ano | find /c /i "established"

Who logged into remote server?

qwinsta /server:SERVERNAME

it results details as below.

 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE

Bulk Deleting of User permissions from a given Web Application and from Site Collections in locked state

This is similar to the previous post but the logic is differently used in the code.
(http://sharepoint-powershell.blogspot.com/2012/10/bulk-deleting-of-user-permissions-from_17.html)

Since this script is only used for Read-only sites (in locked state), we will loop through each locked sites and enumerate users.

Purpose of the Script: If you have a requirement to cleanup permissions of Ex-Employees or Deleted Users, then you can use this PowerShell Script.
*Please understand that this script was developed for a specific requirement and it may not work exactly same for your environment. So, use script at your own risk.
http://sharepoint-powershell.blogspot.com/p/start-variables-uri-httpsubweb.html

This PowerShell script uses an input file and the path/file name are hard-coded in the code. You may have to change certain other hard-coded values of File Paths, Input Filename, Account Name of the user who will be replacing the permission role of the deleted user.

The script enumerates through each Site Collection, if Site is found in locked state, it will unlock and enumerates though each user and delete all users permissions and finally Locks the site. Every activity is logged into different log files of my interest. You can customize as per your requirement.

The input file for this PowerShell script file is ExEmployees.csv
Basically it contains, list of NT names under the column header NTName.

NTName
Domain\Vaddiv
Domain\Account1
Domain\Account2

Bulk Deleting of User permissions from a given Web Application and from Site Collections in Un-locked state

If you have a requirement to cleanup permissions of Ex-Employees or Deleted Users, then you can use this PowerShell Script.
*Please understand that this script was developed for a specific requirement and it may not work exactly same for your environment. So, use script at your own risk.
http://sharepoint-powershell.blogspot.com/p/start-variables-uri-httpwebapp.html

This PowerShell script uses an input file and the path/file name are hard-coded in the code. You may have to change certain other hard-coded values of File Paths, Input Filename, Account Name of the user who will be replacing the permission role of the deleted user.

The script, for each user, enumerates through each Site Collection, and if permission is found at different permissions level, (Owner/SiteCollectionAdmin/SecondaryUser/SiteUser) and if permission is found, then it first adds SubstituteUser we are supplying through the input parameters and then will delete user's permissions.

Every activity is logged into different log files of my interest. You can customize as per your requirement.

The input file for this PowerShell script file is ExEmployees.csv
Basically it contains, list of NT names under the column header NTName.

NTName
Domain\Vaddiv
Domain\NTName1
Domain\NTName2

Identifying which SharePoint WFE we are hitting.


There is another approach that I read in some forums, to add an Image file (Image with Server Name) in the Web Application's specific URL path and hitting that URL opens the image of respective server. There is a problem with this if the server files get synced. Usually they does if they are behind the load balancer and with specific configuration, the Inetpub and Hive files get synced with latest files in other servers.

The other approach I feel is more reliable. Simple way. There are many other ways too by using WMI Scripting and using other server methods with elivated previllages. But the following is pretty simple.

1. Create a text file in each Server and save in a path. Say, C:\support\server.txt
    Enter that particular server name in this text file

2. Create a server.aspx file with content as below.

<%@ Page Language="C#" %>
<html>
<head>
   <title>Which Web Frontend Server (WFE) ?</title>
</head>
<body>
<%
System.IO.StreamReader sr = new System.IO.StreamReader("C:\\Support\\server.txt");
string line;
while(sr.Peek() != -1)
{
   line = sr.ReadLine();
   Response.Write(Server.HtmlEncode(line) + "<br/>");
}
%>
</body>
</html>

3. Make sure the web application, where you are going to upload this aspx file, has following entry in the web.config fiile.
Following line is to be added to the web.config file in the    <SafeMode>  tag.

      <PageParserPaths>
       <PageParserPath VirtualPath="/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true" />
      </PageParserPaths>

other wise you will get the below error:




4. Then go to any Site Collection in the that Web Application, add aspx file you created, to any of Document Library, and then open the server.aspx file.

If everything works, then you will see the content in text file as below.