Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

Thursday, July 12, 2012

The same client browser session has made '6' requests in the last '11' seconds.

After the configuration of ADFS v2 to SharePoint 2010 and
when I tried to login, I found at myself that after I authenticate to ADFS, get caught up in this endless loop where go back and forth between SharePoint and ADFS.
In Fiddler it turns out that I are authenticating successfully to ADFS, I am coming back to SharePoint and it is successfully issuing the FedAuth cookie,
it redirects you to /_layouts/authenticate.aspx on the SharePoint site which clears out the FedAuth cookie and redirects me back to the ADFS site.
I basically ping pong back and forth until ADFS stops it .

In Event Viewer of ADFS Server :



I saw the exception:



Exception details:
Microsoft.IdentityServer.Web.InvalidRequestException: MSIS7042: The same client browser session has made '6' requests in the last '11' seconds. Contact your administrator for details.
at Microsoft.IdentityServer.Web.FederationPassiveAuthentication.UpdateLoopDetectionCookie()
at Microsoft.IdentityServer.Web.FederationPassiveAuthentication.SendSignInResponse(MSISSignInResponse response)



That’s because the default LogonTokenCacheExpirationWindow for the SharePoint STS is 10 minutes. In this case when I created my relying party by default it sets the token lifetime in ADFS to be 2 minutes, so as soon as it authenticated it knew the cookie was good for less time than the LogonTokenCacheExpirationWindow value. Therefore it went back to ADFS to authenticate again. And so it went, back and forth. So I needed to change the LogonTokenCacheExpirationWindow to be less than the SAML TokenLifetime.

The solution is PowerShell Script:







$sts = Get-SPSecurityTokenServiceConfig
$sts.LogonTokenCacheExpirationWindow = (New-TimeSpan –minutes 1)
$sts.Update()
iisreset

Tuesday, July 10, 2012

The workbook cannot be opened



This is error I received on any excel file, which I tried to open in browser by Office Web Apps.

The solution was granting permissions to the service account for Excel Services.
The PowerShell script, which invokes the SPWebApplication.GrantAccessToProcessIdentity method helps to solve it:



Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0

$webApp = Get-SPWebApplication "http://contoso.com"

$webApp.GrantAccessToProcessIdentity("CONTOSO\spExcelServiceApp")

Monday, June 18, 2012

SharePoint 2010 - Creating a Anonymous Web Applications By PowerShell

I found a blog, there are scripts for creating Farm, Web Application, Site Collection: http://blog.brianbeach.com (all credits to Brian). I want to write it here, like a reminder for myself. In addition, I think that the sharing knowledge is a best way to help to each other.

AnonymousState determines if anonymous users have access to the site collection as follows:

  • A "0" disables anonymous access. In other words, anonymous users have no access to a Web site.
  • A "1" allows default anonymous access. This specifies that anonymous users can access lists and libraries if the lists and libraries allow anonymous access.
  • A "2" specifies that anonymous users can access the entire Web site.
AnonymousPermMask allows you to control granular permissions. The values of the mask (taken directly from the source code) are:

  • ViewListItems = View items in lists, documents in document libraries, and view Web discussion
  • AddListItems = items to lists, add documents to document libraries, and add Web discussion
  • EditListItems = Edit items in lists, edit documents in document libraries, edit Web discussion comments in documents, and customize Web Part Pages in document libraries.
  • DeleteListItems = Delete items from a list, documents from a document library, and Web discussion comments in documents.
  • ApproveItems = Approve a minor version of a list item or document.
  • OpenItems = View the source of documents with server-side file handlers.
  • ViewVersions = View past versions of a list item or document.
  • DeleteVersions = Delete past versions of a list item or document.
  • CancelCheckout = Discard or check in a document which is checked out to another user.
  • ManagePersonalViews = Create, change, and delete personal views of lists.
  • ManageLists = Create and delete lists, add or remove columns in a list, and add or remove public views of a list.
  • ViewFormPages = View forms, views, and application pages, and enumerate lists.
  • Open = Allow users to open a Web site, list, or folder to access items inside that container.
  • ViewPages = View pages in a Web site.
  • AddAndCustomizePages = Add, change, or delete HTML pages or Web Part Pages, and edit the Web site using a Windows SharePoint Services–compatible editor.
  • ApplyThemeAndBorder = Apply a theme or borders to the entire Web site.
  • ApplyStyleSheets = Apply a style sheet (.css file) to the Web site.
  • ViewUsageData = View reports on Web site usage.
  • CreateSSCSite = Create a Web site using Self-Service Site Creation.
  • ManageSubwebs = Create subsites such as team sites, Meeting Workspace sites, and Document Workspace sites.
  • CreateGroups = Create a group of users that can be used anywhere within the site collection.
  • ManagePermissions = Create and change permission levels on the Web site and assign permissions to users and groups.
  • BrowseDirectories = Enumerate files and folders in a Web site using Microsoft Office SharePoint Designer 2007 and WebDAV interfaces.
  • BrowseUserInfo = View information about users of the Web site.
  • AddDelPrivateWebParts = Add or remove personal Web Parts on a Web Part Page.
  • UpdatePersonalWebParts = Update Web Parts to display personalized information.
  • ManageWeb = Grant the ability to perform all administration tasks for the Web site as well as manage content. Activate, deactivate, or edit properties of Web site features through the object model or through the user interface (UI). When granted on the root Web site of a site collection, activate, deactivate or edit properties of site collection scoped Features through the object model. To browse to the Site Collection Features page and activate or deactivate site collection scoped Features through the UI, you must be a site collection administrator.
  • UseClientIntegration = Use features that launch client applications; otherwise, users must work
  • UseRemoteAPIs = Use SOAP, WebDAV, or Microsoft Office SharePoint Designer 2007 interfaces to access the Web site.
  • ManageAlerts = Manage alerts for all users of the Web site.
  • CreateAlerts = Create e-mail alerts.
  • EditMyUserInfo = Allows a user to change his or her user information, such as adding a picture.
  • EnumeratePermissions = Enumerate permissions on the Web site, list, folder, document, or list item.




$WebAppURL = "http://www.brianbeach.com"
$HostHeader = "www.brianbeach.com"
$WebAppName = "Anonymous Web Application"
$ContentDatabase = "Content_Anonymous_Default"
$AppPoolName = "Anonymous Content"
$AppPoolUserName = "DOMAIN\USER_NAME"

Write-Host "Creating the anonymous web application"
$AppPoolCred = Get-Credential $AppPoolUserName
$AppPoolAccount = New-SPManagedAccount -Credential $AppPoolCred
$AuthProvider = New-SPAuthenticationProvider -AllowAnonymous
$WebApp = New-SPWebApplication -AllowAnonymousAccess -ApplicationPool $AppPoolName -ApplicationPoolAccount $AppPoolAccount -Name $WebAppName -URL $WebAppURL -HostHeader $HostHeader -Port 80 -AuthenticationProvider $AuthProvider -DatabaseName $ContentDatabase


$SiteName = "Anonymous Root Site"
$OwnerEmail = "USER_NAME@DOMAIN.com"
$OwnerAlias = "DOMAIN\USER_NAME"
$SiteURL = "http://www.brianbeach.com"

Write-Host "Creating a default site collection in the anonymous web application"
New-SPSite -Url $SiteURL -owneralias $OwnerAlias -ownerEmail $OwnerEmail -Template "STS#0"
$Web = Get-SPWeb $SiteURL
$Web.title = $SiteName
$Web.AnonymousState = 2;
$Web.AnonymousPermMask64 = "ViewListItems, ViewVersions, ViewFormPages, Open, ViewPages, UseClientIntegration, AddListItems"
$Web.update()

SharePoint 2010 - Creating a Site Collections By PowerShell

I found a blog, there are scripts for creating Farm, Web Application, Site Collection: http://blog.brianbeach.com (all credits to Brian). I want to write it here, like a reminder for myself. In addition, I think that the sharing knowledge is a best way to help to each other.

List of common templates:
  • STS#0 - Team Site
  • STS#1 - Blank Site
  • STS#2 - Document Workspace
  • MPS#0 - Basic Meeting Workspace
  • MPS#1 - Blank Meeting Workspace
  • MPS#2 - Decision Meeting Workspace
  • MPS#3 - Social Meeting Workspace
  • MPS#4 - Multipage Meeting Workspace
  • WIKI#0 - Wiki
  • BLOG#0 – Blog


  • $SiteName = "Human Resources Site"
    $OwnerEmail = "USER_NAME@DOMAIN.com"
    $OwnerAlias = "DOMAIN\USER_NAME"
    $SiteURL = "http://intranet.DOMAIN.com/sites/hr"
    $SiteTemplate = "STS#0"

    Write-Host "Creating a relative site collection in the intranet web application"
    New-SPSite -Url $SiteURL -owneralias $OwnerAlias -ownerEmail $OwnerEmail -Template $SiteTemplate
    $Web = Get-SPWeb $SiteURL
    $Web.title = $SiteName
    $Web.update()



    $WebAppURL = "http://intranet.DOMAIN.com"
    $ContentDatabase = "Content_Intranet_BLOG"

    Write-Host "Creating a new content database in the intranet web application"
    New-SPContentDatabase $ContentDatabase -WebApplication $WebAppURL

    $SiteName = "Intranet Blog"
    $OwnerEmail = "USER_NAME@DOMAIN.com"
    $OwnerAlias = "DOMAIN\USER_NAME"
    $SiteURL = "http://intranet.DOMAIN.com/sites/blog"
    $SiteTemplate = "BLOG#0"

    Write-Host "Creating a relative site collection in the intranet web application with a separate content database"
    New-SPSite -Url $SiteURL -owneralias $OwnerAlias -ownerEmail $OwnerEmail -ContentDatabase $ContentDatabase -Template $SiteTemplate
    $Web = Get-SPWeb $SiteURL
    $Web.title = $SiteName
    $Web.update()



    $SiteName = "Intranet WIKI"
    $OwnerEmail = "USER_NAME@DOMAIN.com"
    $OwnerAlias = "DOMAIN\USER_NAME"
    $WebAppURL = "http://intranet.DOMAIN.com"
    $SiteURL = "http://wiki.DOMAIN.com"
    $SiteTemplate = "WIKI#0"

    Write-Host "Creating a hostheader site collection in the intranet web application"
    $WebApp = Get-SPWebApplication $WebAppURL
    New-SPSite -url $SiteURL -HostHeaderWebApplication $WebApp -owneralias $OwnerAlias -ownerEmail $OwnerEmail -Template $SiteTemplate
    $Web = Get-SPWeb $SiteURL
    $Web.title = $SiteName
    $Web.update()

    $WebAppName = "Intranet Web Application"
    $HostHeader = "wiki.DOMAIN.com"

    Import-Module WebAdministration
    New-WebBinding -Name $WebAppName -Port 80 -Protocol "http" -HostHeader $HostHeader

    SharePoint 2010 - Creating a Web Application By PowerShell

    I found a blog, there are scripts for creating Farm, Web Application, Site Collection: http://blog.brianbeach.com (all credits to Brian). I want to write it here, like a reminder for myself. In addition, I think that the sharing knowledge is a best way to help to each other.

    $WebAppURL = "http://intranet.DOMAIN.com"
    $HostHeader = "intranet.DOMAIN.com"
    $ContentDatabase = "Content_Intranet_Default"
    $WebAppName = "Intranet Web Application"
    $AppPoolName = "Intranet Content"
    $AppPoolUserName = "DOMAIN\SERVICE_ACCOUNT"

    Write-Host "Creating the intranet web application"
    $AppPoolCred = Get-Credential $AppPoolUserName
    $AppPoolAccount = New-SPManagedAccount -Credential $AppPoolCred
    $AuthProvider = New-SPAuthenticationProvider
    $WebApp = New-SPWebApplication -ApplicationPool $AppPoolName -ApplicationPoolAccount $AppPoolAccount -Name $WebAppName -URL $WebAppURL -HostHeader $HostHeader -Port 80 -AuthenticationProvider $AuthProvider -DatabaseName $ContentDatabase


    $SiteName = "Intranet Root Site"
    $OwnerEmail = "USER_NAME@DOMAIN.com"
    $OwnerAlias = "DOMAIN\USER_NAME"
    $SiteURL = "http://intranet.DOMAIN.com"
    $SiteTemplate = "STS#1"

    Write-Host "Creating a default site collection in the intranet web application"
    New-SPSite -Url $SiteURL -owneralias $OwnerAlias -ownerEmail $OwnerEmail -Template $SiteTemplate
    $Web = Get-SPWeb $SiteURL
    $Web.title = $SiteName
    $Web.update()

    SharePoint 2010 - Creating the Farm By PowerShell

    I found a blog, there are scripts for creating Farm, Web Application, Site Collection: http://blog.brianbeach.com (all credits to Brian). I want to write it here, like a reminder for myself. In addition, I think that the sharing knowledge is a best way to help to each other.




    Add-PSSnapin Microsoft.SharePoint.Powershell -EA 0
    Clear-Host

    $FarmAccountName = "DOMAIN\SERVICE_ACCOUNT"
    $Passphrase = "PASSWORD"
    $DatabaseServer = "DATABASE_SERVER_NAME"
    $ConfigDatabase = "Config"
    $ContentDatabase = "Content_Admin"

    Write-Host "Creating Configuration Database"
    $FarmAccount = Get-Credential $FarmAccountName
    $Passphrase = (ConvertTo-SecureString $Passphrase -AsPlainText -force)
    New-SPConfigurationDatabase -DatabaseServer $DatabaseServer -DatabaseName $ConfigDatabase -AdministrationContentDatabaseName $ContentDatabase -Passphrase $Passphrase -FarmCredentials $FarmAccount

    Write-Host "Configuring Farm"
    Initialize-SPResourceSecurity
    Install-SPService
    Install-SPFeature -AllExistingFeatures

    Write-Host "Configuring Central Administration"
    New-SPCentralAdministration -Port 8080 -WindowsAuthProvider NTLM
    Install-SPHelpCollection -All
    Install-SPApplicationContent



    How to delete the deployed Event Receiver in Sharepoint server 2010 - PowerShell

    I took it from this article

    $spWeb = Get-SPWeb -Identity http://contoso.com

    $spList = $spWeb.Lists["My List Name"]
    $eventsCount = $spList.EventReceivers.Count
    $assembly = "Project.Name.Class, Version=1.0.0.0, Culture=neutral, PublicKeyToken=11111111111"
    $class = "Namespace.MyClass.ClassName"
    $type = 10002
    $name = "My Event Name"
    for ($i = 0; $i -lt $eventsCount; $i+=1)
    {
    if ($spList.EventReceivers[$i].Assembly -eq
    $assembly
    -and
    $spList.EventReceivers[$i].Class -eq $class
    -and
    $spList.EventReceivers[$i].Type -eq $type
    -and $spList.EventReceivers[$i].Name -eq
    $Name)
    {
    $spList.EventReceivers[$i].Delete()
    }
    }
    $spList.Update()

    Monday, March 26, 2012

    Delete all items from SPList - SharePoint 2010 PowerShell

    I found this script in the internet, but don't remember where. Therefore I just put it here as is(Of course with all respect points to the anonymous writer of the script) :



    [System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
    [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
    [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
    [System.Reflection.Assembly]::Load("System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")

    # "Enter the site URL here"
    $SITEURL = "http://contoso"

    $site = new-object Microsoft.SharePoint.SPSite ( $SITEURL )
    $web = $site.OpenWeb()
    "Web is : " + $web.Title

    # Enter name of the List below
    $oList = $web.Lists["MyList"];

    "List is :" + $oList.Title + " with item count " + $oList.ItemCount

    $collListItems = $oList.Items;
    $count = $collListItems.Count - 1

    for($intIndex = $count; $intIndex -gt -1; $intIndex--)
    {
    "Deleting : " + $intIndex
    $collListItems.Delete($intIndex);
    }

    Sunday, March 25, 2012

    Enable/Disable feature - SharePoint 2010 PowerShell

    Some times you need just enable /disable feature .
    So for me the good way is doing by PowerShell :

    1. Get all installed features to the text file:

    Get-SPFeature | Sort -Property Scope,DisplayName | FT -GroupBy Scope DisplayName,Id > c:\AllInstalledFeatures.txt

    2. Go to the c:\AllInstalledFeatures.txt and find the relevant feature. Copy the guid.

    3. Enable Feature:

    Enable-SPFeature -identity "cdd0d039-d2d2-40c8-81fc-0d5657fc2962" -URL http://contoso.com

    4. Disable Feature:

    Disable-SPFeature -identity "cdd0d039-d2d2-40c8-81fc-0d5657fc2962" -URL http://contoso.com

    Wednesday, March 21, 2012

    Backup - Restore Content Database to another farm SharePoint 2010 Power Shell

    We need few steps to do it:
    1. Backup data from source.
    For this we need check which database we use for this web application









    and backup the database:
    From the SQL Server that your SharePoint farm users and where the instance of DB resides, backup the database.





    2.Restore the database to the destination :
    Take the backup file to the target SharePoint Farm's SQL Server (where we want to restore it to) and restore the database









    Now we have a new content database, but we need to connect it to our SP.
    Therefore we open SP Powershell :
    3. Dismount old database:

    Dismount-SPContentDatabase "Contoso_PortalContent_Old"

    4. Mount new :
    Mount-SPContentDatabase " Contoso_PortalContent_New" -DatabaseServer "contoso_db" -WebApplication http://contoso.com

    Monday, March 19, 2012

    SharePoint Power Shell Commands for adding solutions

    Adding Solution:

    Add-SPSolution "C:\WebPart.wsp"

    Installing Solution:

    Install-SPSolution –Identity WebPart.wsp –WebApplication http://contoso.com -GACDeployment


    Update Solution if exists:

    Update-SPSolution –Identity WebPart .wsp –LiteralPath “C:\WebPart .wsp” –GACDeployment