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.

Tuesday, January 29, 2013

Scripting Tips


Count of rows in Text File
$totalrows = Import-Csv C:\urls.csv | Measure-Object | Select-Object -expand count

Open/Read text File

    AccountNames.csv
         AccountName
         Domain\Name1
         Domain\Name2

$AcctFile="C:\AccountNames.csv"

ipcsv $AcctFile | foreach {
     $AName =$_.AccountName
}

Write-host
Write-host "Feature: " $AName -foregroundcolor yellow
Clear-Host


TimeStamp
$strTimestamp =  [string](Get-Date -format "yyyy-MM-dd_hh-mm-ss")
$strLogFile =  ($strFilePath + "FileName_" + $strTimestamp + ".log")

Log to File
$AName +",Blog-NotFound" | Out-File ($strLogFile) -append
Write-Output "$Class deleted on $CommunityList" | Out-File -Append $strLogFile
"Count  :"+$UrlsCount | Out-File -Append $DeletedReport

Log File Creation Prompt:
if ((Test-Path -path $FilePath) -ne $True) {
 $NewPathPrompt = "$FilePath does not exist! Would you like to create it?"
 $NewPathMessage = ""
 $NewPathYes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
  "Creates new directory at $FilePath"
 $NewPathNo = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
  "Do not create new directory and exit"
 $NewPathOptions = [System.Management.Automation.Host.ChoiceDescription[]]($NewPathYes, $NewPathNo)
 $NewPathResult = $host.ui.PromptForChoice($NewPathPrompt, $NewPathMessage, $NewPathOptions, 0)
 switch ($NewPathResult)
  {
   0 {New-Item $FilePath -type directory}
   1 {Write-Host "Cannot continue without valid directory to save output file, exiting..."
    Exit
    }
  }
}
 



Blog Sites


  • SharePoint Security
    http://www.sharepointsecurity.com/syndicated-content/first-steps-in-implementing-isa-server-with-sharepoint/
  • http://blog.sharepointsite.co.uk/
    Remote restart and auto-logon and PowerShell Script execution on remote server.



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