Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

Tuesday, 6 December 2016

Full and Incremental Content Deployment in SharePoint 2010




While working with content deployment I came to know that we can do the full and incremental deployment but I was unable to find the option to do the same through central administration in SharePoint 2010. I came to know there was an option to do the same in central admin of SharePoint 2007.

Then I searched and got hold of an old screen from 2007 where I saw the option to do the same as shown below.The same when I did from the central admin of SharePoint 2010 I did not find any option.


SharePoint 2007 Content Deployment


SharePoint 2010 Content Deployment

These option screen shown above are available when u “create a new Job” as show in the screen below



So how do we create a specific Job of type Incremental or Full? After doing surfing I found out that it can be done using PowerShell. Yes we can create Jobs with using PowerShell rather than the step show in figure 2(Above). Note this script should be run after you have already created the content deployment Path as in my case “Local Deploy”.

New-SPContentDeploymentJob -Name " Local Deploy - Incremental" -SPContentDeploymentPath
"Local Deploy" -IncrementalEnabled:$true

Now if we create a job through UI in central admin by default it will create Incremental Only. Yes and how do we find this out?

To do that, run Get-SPContentDeploymentJob "Local Deploy - Incremental". You should notice the following line in your output:



So how do we create a Job with “Full Content Deployment”

New-SPContentDeploymentJob -Name " Local Deploy - Full" -SPContentDeploymentPath
"Local Deploy" -IncrementalEnabled:$false



Reference Take by : http://sharepointlearningcurve.blogspot.sg/2010/05/sp2010-content-deployment-jobs-missing.html 

Wednesday, 6 July 2016

SharePoint 2013 Certificate Error Causes Performance Issues

Whilst working with a SharePoint 2013 environment I experienced slow page load times and poor search performance.  After initial page loads performance was fine for several minutes before the performance issue returned.

Opening the Application log within Event Viewer showed the following critical error with the text

“A certificate validation operation took 30015.2428 milliseconds and has exceeded the execution time threshold.  If this continues to occur, it may represent a configuration issue.  Please see http://go.microsoft.com/fwlink/?LinkId=246987 for more details.”

The fix for the problem is to export the SharePoint Root Authority certificate using PowerShell and import it into the Trusted Root Certificate store.  Open the SharePoint 2013 Management Shell as an administrator.

$SProotCert = (Get-SPCertificateAuthority).RootCertificate
$SProotCert.Export(“Cer”) | Set-Content C:\Test\SProotCert.cer –Encoding Byte

Open the Certificates MMC by opening a Run command and type MMC.  Choose File -> Add/Remove Snap-in.  Select the Certificates Snap-in and click Add.  On the next screen select Computer account and click Next followed by Local computer and Ok.



Right-click on Trusted Root Certificates and choose All Tasks -> Import



Complete the wizard by loading the certificate you exported using PowerShell.  Repeat the process on all SharePoint servers experiencing the issue.

These steps fixed the error on most of our SharePoint servers, but it remained on two.  In order to fix the error on the two remaining servers I configured proxy access through Internet Explorer, then from an elevated command prompt ran “netsh winhttp import proxy source=ie”  This configures Windows to use the IE proxy configuration as a default.  The servers were then able to access the internet and verify the certificates.

Thursday, 2 June 2016

Re-Create (Generate) SharePoint Root Authority "local" certificate

If your are looking to re-create (re-generate) your SharePoint Root Authority "local" certificate, here are the commands to do so...

I accidentally deleted mine, so I exported from other farm members

To Export:
-------------
$rootCert = (Get-SPCertificateAuthority).RootCertificate
$rootCert.Export("Cert") | Set-Content C:\Temp\FarmRoot.cer -Encoding byte

To Import:
-------------
$rootCert = Get-PfxCertificate C:\Temp\FarmRoot.cer
New-SPTrustedRootAuthority  -Certificate $rootCert

Wednesday, 11 May 2016

Delete all sites from a site collection

$url = "http://yourweb.com"
$subsites = ((Get-SPWeb $url).Site).allwebs | ?{$_.url -like $url +"/*"}

foreach($subsite in $subsites) { Remove-SPWeb $subsite.url }


Here you go, full script of deleting all subsites / webs under a site collection, you can also add your subsite to delete the childs of that subsite only.

Tuesday, 5 April 2016

SharePoint 2013: The number of Distributed Cache hosts in the farm exceeds the recommended value

  1. Verify that you have the following memberships:
    • securityadmin fixed server role on the SQL Server instance.
    • db_owner fixed database role on all databases that are to be updated.
    • Administrators group on the server on which you are running the Windows PowerShell cmdlets.
    • Farm Administrators group.
    An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint 2013 cmdlets.

  2. Start the SharePoint 2013 Management Shell.
    • For Windows Server 2008 R2:
      • On the Start menu, click All Programs, click Microsoft SharePoint 2013 Products, and then click SharePoint 2013 Management Shell.
    • For Windows Server 2012:
      1. On the Start screen, click SharePoint 2013 Management Shell.
        If SharePoint 2013 Management Shell is not on the Start screen:
      2. Right-click Computer, click All apps, and then click SharePoint 2013 Management Shell.

Tuesday, 19 January 2016

SharePoint Offline and Manual Prerequisite Procedures

Installing the Roles and Features for SharePoint 2013 on Windows Server 2012 Offline with PowerShell

To install the Roles/Features required by SharePoint 2013 on Windows Server 2012 in an offline environment, you need to have access to the Windows Server 2012 installation media.

For the purposes of example, assume you have mounted the Windows Server 2012 installation media (ISO) to the D: drive of the server. Please note that you can also copy the files locally or specify a UNC path where the installation files are stored. You need to specify

Open an elevated PowerShell prompt (i.e. Run as Administrator) and execute the following:

Import-Module ServerManager

Add-WindowsFeature Net-Framework-Features,Web-Server,Web-WebServer,Web-Common-Http,Web-Static-Content,Web-Default-Doc,Web-Dir-Browsing,Web-Http-Errors,Web-App-Dev,Web-Asp-Net,Web-Net-Ext,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Health,Web-Http-Logging,Web-Log-Libraries,Web-Request-Monitor,Web-Http-Tracing,Web-Security,Web-Basic-Auth,Web-Windows-Auth,Web-Filtering,Web-Digest-Auth,Web-Performance,Web-Stat-Compression,Web-Dyn-Compression,Web-Mgmt-Tools,Web-Mgmt-Console,Web-Mgmt-Compat,Web-Metabase,Application-Server,AS-Web-Support,AS-TCP-Port-Sharing,AS-WAS-Support, AS-HTTP-Activation,AS-TCP-Activation,AS-Named-Pipes,AS-Net-Framework,WAS,WAS-Process-Model,WAS-NET-Environment,WAS-Config-APIs,Web-Lgcy-Scripting,Windows-Identity-Foundation,Server-Media-Foundation,Xps-Viewer –Source D:\sources\sxs


Your server will require a reboot after running this PowerShell code.

Tuesday, 3 November 2015

Database is in compatibility range and upgrade is recommended

I had moved the SharePoint content databases from one farm to another recently. After the migration was completed I browsed to Central Adminitration -> Upgrade and Migration -> Review Database Status. The migrated Sharepoint content database had the Status as "Database is in compatibility range and upgrade is recommended".

This indicated I had to manually upgrade these content databases.



This was because I moved the content databases from SharePoint 2010 SP1 to SharePoint 2010 SP2.

This is how it should be solved if I am not wrong:

Test-SPContentDatabase -Name ContentDBName -WebApplication http://webapp/ > c:\result1.txt (to confirm that there are no Upgrade Blocking categories that equal true)

Upgrade-SPContentDatabase -Name ContentDBName (Depending on the size of the database, this process could take long time)



Once completed 100% the database upgrade, browse to Central Administration -> Upgrade and Migration -> Review Database Status. Confirm that the content database now has Status as "No action required".




Thursday, 1 October 2015

How to: Change the Distributed Cache Service managed account 2013

When you get the annoying pink marker in CA and one of the issues it warns you about, is that ‘the farm account should not be used for other services’ In my case, the scripted install had set the ‘Distributed Cache Service (Windows Service)’ to use the  farm account as managed account. As the 2013 Central Admin is (or tries to be) helpful, it gives you the direct link to the: ‘Security’ – ‘General Security’ – ‘Configure Service Accounts’ and tells you to change it there.

To fix it, just click the link, find the service in the dropdown and select another Managed account in the lower dropdown. Then click ok…..but nooo…that one wont fly.
Changing the service account on this service cannot be done this way and has to be done using PowerShell…thats what you get back.

Well…after some short researching I found this to work ok: (first load the snapin, add-pssnapin microsoft.sharepoint.powershell)

$farm = Get-SPFarm
$cacheService = $farm.Services | where {$_.Name -eq "AppFabricCachingService"}
$accnt = Get-SPManagedAccount -Identity <domain\user>
$cacheService.ProcessIdentity.CurrentIdentityType = "SpecificUser"
$cacheService.ProcessIdentity.ManagedAccount = $accnt
$cacheService.ProcessIdentity.Update()
$cacheService.ProcessIdentity.Deploy()

(Where <domain\user> is the domain name and user name of the managed account you want to use instead.)

Note: Beware of the doublequotes if you copy the code…

Wednesday, 5 August 2015

Getting more than 30 Days of SharePoint Usage Report Data

One of the clients that I was working with needed some extensibility to the out of the box SharePoint Usage Reports.

The data displayed on the reports didn’t meet their requirements, first, they needed to match the data with the user data in SAP in order to get the reports by Region and other parameters, and second, they needed historical data, and not only the last 30 days of information.

The first requirement was not a problem, and at the beginning we didn’t think the second would be a problem either, but oh we were wrong.

Using the out of the box usage reports provided by SharePoint was of course not even an option, we needed a way to get the data and create our own reports.

I spent some time doing research and this is what I found:
  • Using the Object Model. The SPWeb object contains the method GetUsageData(). This is the method called by the Usage Repor pages in sharePoint. It Returns a table that contains information about the usage of a Web site, based on a time interval. Unfurtunately there are only two options for the time interval, either today or last month. So, no way to get more than 30 days of information using the Object model.
  • Web Services. No web service exposes usage report data, so I thought about using owssvr.dll, but again, you can only get the last 30 days of data.

Usage Report data is stored in log files in the IIS and also in the Shared Services database, and not only for the last 30 days, but for all the time since the usage reports were activated, so how is it possible that SharePoint doesn’t have a way to expose this data? Well, that’s how the world works.

Working directly with the SharePoint Databases is not supported by Microsoft, so it seemed that my only option was to create a program to read the IIS files. Have you taken a look at those files? Well, they are quite a mess and I didn’t want to have to do anything with them. So I consulted one of my closest friends: “Reflector”, and once again he gave me the solution I was looking for :)

I found out that the PortalContext object contains a reference to the Shared Services Database through the property “AnalyticsSqlSession”, using this property you get a connection to the database without having to worry about server name, database name, etc.

Since all the usage data is stored in the Shared Services database this was definitely helpful, but let’s not forget that working directly with the databases is not supported, and although I was not accessing directly the database using SQL server, I was however connecting to it and making some queries (READ ONLY).

We presented our solution to Microsoft, and to our surprise, the solution was accepted because somehow we were using the Object Model to get the data, nice!

Having the solution and Microsoft approval, everything got easier. These are the tables in the database that are related to the usage reports:



As you can see, everything is in there! We can do the queries we want and get the data we are looking for.

Going back to the AnalyticsSqlSession property of the PortalContext object, this is how I got it:




Worked like a charm!

Wednesday, 1 July 2015

SharePoint 2010: Create new Search Services with Custom DB names Powershell

When you try to create Search services in SharePoint 2010 using the wizard, it gives you nightmare with the Database names with horrible GUIDs...

here is a simple script to ease your life:

## Parameters used

## change the variables below to your own servers and naming conventions



$databaseServerName = "shrpt-db-server"

$searchServerName = "shrpt-apps-server"

$searchSAName = "Search Service Application"

$saAppPoolName = "SharePoint Web Services Default"

$searchDBName = "Search_Services_Application_DB"



## First remove the old search

## This will require an id - namely a guid so get the service guid before doing this



$spapp = Get-SPServiceApplication -Name $searchSAName

Remove-SPServiceApplication $spapp -RemoveData



##START SEARCH

Write-Host "Creating Search Service and Proxy..."

Write-Host "  Starting Services..."

Start-SPEnterpriseSearchServiceInstance $searchServerName

Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $searchServerName



Write-Host "  Creating Search Application..."

$searchApp = New-SPEnterpriseSearchServiceApplication -Name $searchSAName -ApplicationPool $saAppPoolName -DatabaseServer $databaseServerName -DatabaseName $searchDBName

$searchInstance = Get-SPEnterpriseSearchServiceInstance $searchServerName



Write-Host "  Creating Administration Component..."

$searchApp | Get-SPEnterpriseSearchAdministrationComponent | Set-SPEnterpriseSearchAdministrationComponent -SearchServiceInstance $searchInstance



##Crawl



Write-Host "  Creating Crawl Component..."

$InitialCrawlTopology = $searchApp | Get-SPEnterpriseSearchCrawlTopology -Active

$CrawlTopology = $searchApp | New-SPEnterpriseSearchCrawlTopology

$CrawlDatabase = ([array]($searchApp | Get-SPEnterpriseSearchCrawlDatabase))[0]

$CrawlComponent = New-SPEnterpriseSearchCrawlComponent -CrawlTopology $CrawlTopology -CrawlDatabase $CrawlDatabase -SearchServiceInstance $searchInstance

$CrawlTopology | Set-SPEnterpriseSearchCrawlTopology -Active



Write-Host -ForegroundColor white "  Waiting for the old crawl topology to become inactive" -NoNewline

do {write-host -NoNewline .;Start-Sleep 6;} while ($InitialCrawlTopology.State -ne "Inactive")

$InitialCrawlTopology | Remove-SPEnterpriseSearchCrawlTopology -Confirm:$false

Write-Host  



##Query



Write-Host "  Creating Query Component..."

$InitialQueryTopology = $searchApp | Get-SPEnterpriseSearchQueryTopology -Active

$QueryTopology = $searchApp | New-SPEnterpriseSearchQueryTopology -Partitions 1

$IndexPartition= (Get-SPEnterpriseSearchIndexPartition -QueryTopology $QueryTopology)

$QueryComponent = New-SPEnterpriseSearchQuerycomponent -QueryTopology $QueryTopology -IndexPartition $IndexPartition -SearchServiceInstance $searchInstance

$PropertyDatabase = ([array]($searchApp | Get-SPEnterpriseSearchPropertyDatabase))[0]

$IndexPartition | Set-SPEnterpriseSearchIndexPartition -PropertyDatabase $PropertyDatabase

$QueryTopology | Set-SPEnterpriseSearchQueryTopology -Active

## Proxy



Write-Host "  Creating Proxy..."

$searchAppProxy = New-SPEnterpriseSearchServiceApplicationProxy -Name "$searchSAName Proxy" -SearchApplication $searchSAName > $null



#####END SEARCH   

Wednesday, 15 April 2015

SharePoint 2010: Remove the My Site Host Location URL





So if you have seen the above screen and wondering if it is ever possible to remove my site host location follow simple power-shell to remove it.

$site = Get-SPSite "http://<url of your admin site>"

$context = Get-SPServiceContext($site)

$upm = New-Object -TypeName Microsoft.Office.Server.UserProfiles.UserProfileManager -ArgumentList $context

$upm.MySiteHostURL="";

Wednesday, 1 October 2014

SharePoint MIME types for a web application

Find all the MIME types for a web application.


Get-SPWebApplication "http://ecdc.europa.eu" | Foreach-Object {$_.AllowedInlineDownloadedMimeTypes}

Tuesday, 30 September 2014

SharePoint Default Trusted file (MIME) types

Each Web Application in SharePoint 2010 and 2013 has an AllowedInlineDownloadedMimeTypes property within which a list of trusted file (MIME) types exists. Firstly, there is no “untrusted” list, only a “trusted” list. It is safe to assume that if a MIME type is not included in this list, it is untrusted by default and is subject to the “X-Download-Options: noopen” HTTP Response header. The most common example of this is PDF documents, MIME type “application/pdf”. 


In the SharePoint 2010 Management Shell, you can easily find out which types are trusted out of the box by executing the following PowerShell snippet:


Get-SPWebApplication "http://yourwebapplicationurl" | Foreach-Object {$_.AllowedInlineDownloadedMimeTypes}


You could also use the following snippet to achieve the same output: 



$webApplication = Get-SPWebApplication "http://yourwebapplicationurl"            
$webApplication.AllowedInlineDownloadedMimeTypes


Again, it is important to note that each web application has its own AllowedInlineDownloadedMimeTypes property. 

Force Browser to save office files locally

if you are stuck like me and trying to find a solution to force browsers to only save office documents (word and excel) locally and not try to open in browser follow the steps below:


$webApplication = Get-SPWebApplication "http://localhost"
$webApplication.AllowedInlineDownloadedMimeTypes.Remove("application/vnd.openxmlformats-officedocument.wordprocessingml.document")
$webApplication.AllowedInlineDownloadedMimeTypes.Remove("application/msword")
$webApplication.AllowedInlineDownloadedMimeTypes.Remove("application/vnd.ms-word.document.12")
$webApplication.AllowedInlineDownloadedMimeTypes.Remove("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
$webApplication.Update()

Friday, 8 August 2014

Sharepoint 2010 Content Deployment Failing (cannot find feature)

So my content deployment kept of failing giving error

Could not find Feature <My Feature Name>.

I did everything and Feature was correctly deployed etc.

Turns out the features were not in the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES folder on the central admin server... only on the web server. Once I copied them over it worked like a charm. Weird that when you install them with stsadm it doesn't put them everywhere. 

Friday, 1 August 2014

Remove SharePoint DB without having SQL Management Studio access

Just a quick tip that can help a lot in some situations, when in the situation when you for example have deleted a service application and the DB’s are still there, the DBA’s have all left and you have no way of connecting to SQL with a management tool…

This is what you can do, given that you have the permissions…(high?)

Get-SPDatabase
 (Will list all databases used by SharePoint, Name and GUID and Type.)

$DatabaseToDelete = Get-SPDatabase <GUID of the database you need to get rid of>
 (Load the database as a SPDatabase object)

$DatabaseToDelete.Delete()
 (It’s now gone…)

Wednesday, 18 June 2014

Office Web Access PreRequisites Install on Windows 2012 Powershell

If you are stuck like installing an old Office Web Access 2010 on a Windows 2012 and thinking how to install Prerequisites here is the powershell command:

Add-WindowsFeature Web-Server,Web-Mgmt-Tools,Web-Mgmt-Console,Web-WebServer,Web-Common-Http,Web-Default-Doc,Web-Static-Content,Web-Performance,Web-Stat-Compression,Web-Dyn-Compression,Web-Security,Web-Filtering,Web-Windows-Auth,Web-App-Dev,Web-Net-Ext45,Web-Asp-Net45,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Includes,InkandHandwritingServices