Sunday, February 28, 2016

Warm up SharePoint - Vickers Style

There are about a million of these scripts on the Internet, but this one is mine.  Put it on a server, run it regularly in Task Scheduler, and forget about it.

The nice thing about this one is you don't have to change anything about it to run it on your farm.  It will query SharePoint to get the relevant web applications, search centers, mysites, etc.  

Add-PSSnapin Microsoft.SharePoint.PowerShell


try
{
    # Set Variables
    $MultiThreadSites = @()
    $SingleThreadSites = @()
    $WebServers = @()
    $SearchServers = @()
    $Servers = Get-SPServer | where {$_.Role -ne "Invalid"}
   

    # Get Web Applications
    $WebApps = Get-SPWebApplication

    # Get Global Search Center Url
    $SearchSvc = Get-SPEnterpriseSearchServiceApplication | Where {$_.Name -eq "Search Service Application"}
    $SrcCenterUrl = $SearchSvc.SearchCenterUrl -Replace "/default.aspx", ""

    # If search center is set
    if($SrcCenterUrl)
    {
        # Set Various Search Urls
        $SrcUrls = @("$($SrcCenterUrl)/default.aspx")
        $SrcUrls += ,@("$($SrcCenterUrl)/results.aspx")
        $SrcUrls += ,@("$($SrcCenterUrl)/peopleresults.aspx")
        $SrcUrls += ,@("$($SrcCenterUrl)/conversationresults.aspx")
        $SrcUrls += ,@("$($SrcCenterUrl)/results.aspx?k=test")
    }

    # Get Central Admin Url
    $CentralAdmin = [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]::Local
    $CentralAdminUrl = $CentralAdmin.Url
    $HealthReportUrl = "$($CentralAdminUrl)/Lists/HealthReports"
    $CAServer = $CentralAdmin.Url.split('//')[2].split('`:')[0]

    # Loop through all the servers in farm
    foreach($Server in $Servers)
    {
        # Create a variable of Server Name
        $ServerName = $Server.Name
       
        # Determine the farm Web Servers
        If ($ServerName -notlike "SRPAPPPW003") {
        $WebServiceIns = Get-SPServiceInstance -Server $ServerName | where {$_.TypeName -eq "Microsoft SharePoint Foundation Web Application"}
        if($WebServiceIns.Status -eq "Online")
        {
            $WebServers += ,@($ServerName)
        } }

        # Determine the farm Search Servers
        $SearchServiceIns = Get-SPServiceInstance -Server $ServerName | where {$_.TypeName -eq "SharePoint Server Search"}
        if($SearchServiceIns.Status -eq "Online")
        {
            $SearchServers += ,@($ServerName)
        }
    }

    # Loop through all the Web Applications
    foreach($WebApp in $WebApps)
    {
        # Get the first site collection Url
        $SiteCols = Get-SPSite -WebApplication $WebApp -Limit 5
       
        # If there are Site Collections in this Web Application
        if($SiteCols)
        {
            # Loop through all the Site Collections
            foreach($SiteCol in $SiteCols)
            {
                $MultiThreadSites += $SiteCol.Url | Where {$_ -notlike "*$CAServer*"}
            }
        }
    }

    # Add Central Admin and Helath Check to the Site Array
    #$SingleThreadSites += ,@($CentralAdminUrl)
    #$SingleThreadSites += ,@($HealthReportUrl)

    # Loop through all the Search Urls
    foreach($SrcUrl in $SrcUrls)
    {
        # Add Url to the Site Array
        $SingleThreadSites += ,@($SrcUrl)
    }

    # Loop through all Search Servers
    foreach($SearchServer in $SearchServers)
    {
        # Add Url to the Site Array
        $TopologyUrl = "http://$($SearchServer.ToLower()):32843/Topology/topology.svc"
        $SingleThreadSites += ,@($TopologyUrl)
    }

    # Loop through all urls
    foreach($Site in $SingleThreadSites)
    {
        Write-host "Loading $($Site)..." -NoNewline
        $Url =  "$($Site)"
        $Request = [System.Net.WebRequest]::Create($Url)
        $Request.UseDefaultCredentials = $true
       
        try
        {
            $Response = $Request.GetResponse()
        }
        catch [System.Net.WebException]
        {
            $Response = $_.Exception.Response
        }
       
        $Status = [int]$Response.StatusCode

        if($Status -eq 200)
        {
            $WebClient = New-Object Net.WebClient
            $WebClient.UseDefaultCredentials = $true
            $PageContents = $WebClient.DownloadString($Url)
            $WebClient.Dispose()
            Write-host "200 OK" -ForegroundColor Green
        }
        else
        {
            Write-host "Error: $Status" -ForegroundColor Red
        }
    }

    # Loop through all site collections
    foreach($Site in $MultiThreadSites)
    {
        # Loop through all web servers
        foreach($WebServer in $WebServers)
        {
            Write-host "Loading $($Site) on server $($WebServer)..." -NoNewline
            $Url = $($Site)
            $BypassLocal = $false
            $ProxyUri = "http://" + $WebServer
            $Proxy = New-Object System.Net.WebProxy($ProxyUri, $BypassLocal)
            $Request = [System.Net.WebRequest]::Create($Url)
            $Request.UseDefaultCredentials = $true
            $Request.Proxy = $Proxy
           
            try
            {
                $Response = $Request.GetResponse()
            }
            catch [System.Net.WebException]
            {
                $Response = $_.Exception.Response
            }
           
            $Status = [int]$Response.StatusCode

            if($Status -eq 200)
            {
                $WebClient = New-Object Net.WebClient
                $WebClient.UseDefaultCredentials = $true
                $WebClient.Proxy = $Proxy
                $PageContents = $WebClient.DownloadString($Url)
                $WebClient.Dispose()
                Write-host "200 OK" -ForegroundColor Green
            }
            else
            {
                Write-host "Error: $Status" -ForegroundColor Red
            }
        }
    }

            Write-host "Loading Central Admin on server $($CAServer)..." -NoNewline
            $Url = $($CentralAdminUrl)
            $BypassLocal = $false
            $ProxyUri = $CentralAdminUrl
            $Proxy = New-Object System.Net.WebProxy($ProxyUri, $BypassLocal)
            $Request = [System.Net.WebRequest]::Create($Url)
            $Request.UseDefaultCredentials = $true
            $Request.Proxy = $Proxy

            try
            {
                $Response = $Request.GetResponse()
            }
            catch [System.Net.WebException]
            {
                $Response = $_.Exception.Response
            }
           
            $Status = [int]$Response.StatusCode

            if($Status -eq 200)
            {
                $WebClient = New-Object Net.WebClient
                $WebClient.UseDefaultCredentials = $true
                $WebClient.Proxy = $Proxy
                $PageContents = $WebClient.DownloadString($Url)
                $WebClient.Dispose()
                Write-host "200 OK" -ForegroundColor Green
            }
            else
            {
                Write-host "Error: $Status" -ForegroundColor Red
            }

}
catch
{
    Write-host "Error" -ForegroundColor Red
    Write-host "Error at line $($_.InvocationInfo.ScriptLineNumber): $_" -ForegroundColor DarkGray
}

# Remove created variables
#Get-Variable -Exclude PWD,*Preference | Remove-Variable -EA 0

Thursday, February 25, 2016

Here's something you don't really want to see....ever

We ran into a unique error in Project Server 2013 a couple days ago.  In short, what we found was if you are running a Bulk Update of all Project sites, there's a possibility of putting locks on your database if you are running an instance of Project Server that is highly customized.

The error we were seeing in the SharePoint logs was this:  PWA:{PWA Url}, ServiceApp:Project Services Application, User:PROJECTSERVER\system, PSI: User {User Account} could not be authenticated because logon permission has not been granted.

In our case, the stored procedure for  pub.MSP_AUTH_AuthenticateUserByAccount could not fire, not because of an access or authentication issue, but because a lock had been placed on the tempdb's log file.  

In searching for the error, I saw something I've never seen before on Google.

Behold






You know you're having a bad day when even Google only has one idea.  



Monday, February 22, 2016

Enable that Cross-Domain People Picker, yo!

I'm writing this one definitely not as the first source on this subject, but mainly out of frustration.  Way too many Bing and Google searches looking for the right syntax, and way too many posts with the wrong string.

The following STSADM command will allow the People Picker to search for users in a situation where you have a one-way trust between domains.  This is especially useful if you're load testing your QA domain.

This command is all in one string.  Run this after you create a credential key.  Do that by entering this:
stsadm -o setapppassword -password <password> 



STSADM.exe -o setproperty -pn peoplepicker-searchadforests -pv "forest:QAFOREST.somecompany.com,AD\service-somesvcacct,thataccountpw; domain:ADFOREST.somecompany.com,AD\service-somesvcacct,thataccountpw" -url http://qa.somecompany.com

Explanations:

The service account used is the service account from the primary domain.  So in a one-way scenario, QA will trust it.

Once you run it, you can run the following to verify the setting was applied:

stsadm.exe -o getproperty -pn peoplepicker-searchadforests -url http://qa.somecompany.com

If you need to clear the property, you can run this:
 
stsadm.exe -o setproperty -pn peoplepicker-searchadforests -pv "" -url http://qa.somecompany.com  


Hope this helps someone.