Wednesday, May 29, 2013

! ! ! MY NEW BLOG ON TECHNET ! ! !

Dear all,
due to I'm working for Microsoft Austria I have the possibility to create a TechNet Blog.

So all my new blogposts will be there

 
You also will find some German content on
 
This Is a Blog of the SharePoint ALPS Community, which means SharePoint PFE's from Switzerland and Austria.

very best regards for reading my blog and giving me some feedback.
best regards
Thomas


Tuesday, May 14, 2013

Clear SharePoint Config Cache with PowerShell


Add-PSSnapin -Name Microsoft.SharePoint.PowerShell –erroraction SilentlyContinue

Stop-Service SPTimerV4
$folders = Get-ChildItem C:\ProgramData\Microsoft\SharePoint\Config
foreach ($folder in $folders)
    {
    $items = Get-ChildItem $folder.FullName -Recurse
    foreach ($item in $items)
        {
            if ($item.Name.ToLower() -eq "cache.ini")
                {
                    $cachefolder = $folder.FullName
                }
               
        }
    }
$cachefolderitems = Get-ChildItem $cachefolder -Recurse
    foreach ($cachefolderitem in $cachefolderitems)
        {
            if ($cachefolderitem -like "*.xml")
                {
                   $cachefolderitem.Delete()
                }
       
        }
       
$a = Get-Content  $cachefolder\cache.ini
$a  = 1
Set-Content $a -Path $cachefolder\cache.ini

read-host "Do this on all your SharePoint Servers - and THEN press ENTER"
start-Service SPTimerV4

Add listitems with PowerShell

$weburl = "http://mysharepoint"
$listname = "TestList"
$a = "Text1"
$b = "Text2"
$c = "Text3"



Add-PsSnapin Microsoft.SharePoint.PowerShell -erroraction silentlycontinue 
$web = Get-SPWeb -Identity $webUrl
$list = $web.Lists[$listname]
$newItem = $list.items.add()
$newitem["Title"] = $a
$newitem["Custom_Column1"] = $b
$newitem["Custom_Column2"] = $c

$newitem.update()

Wednesday, May 8, 2013

List all Databases from your SQL Server via PowerShell

I've created this script, because some guys wanted to know which DBs are available.
It can be used to e.g. mount some unmounted contentdatabases.

-----------

function ListAllSQLDBs {param ( $DatabaseServer)
if ($DatabaseServer -eq $null)

    $DatabaseName=   "master"
    $QueryString = "EXEC sp_databases"

    $SQLDBs = New-Object system.Data.DataTable
    $col1 = New-Object system.Data.DataColumn DBName
    $SQLDBs.columns.add($col1)
    function ADD_TO_SQL_DB_TABLE
    {param ( $DBName)
        $newRow = $SQLDBs.NewRow()
     $newRow.DBName = $DBName
        $SQLDBs.rows.add($newRow)
     }

    [void][reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo")
    $conn = New-Object Microsoft.SqlServer.Management.Common.ServerConnection($DatabaseServer)
    $conn.DatabaseName = $DatabaseName
    $r = $conn.ExecuteReader($QueryString)
    While ($r.Read())
    {
       $Name = $r.GetValue(0);
       ADD_TO_SQL_DB_TABLE -DBName $Name
    }
    $r.Close()
    Write-Output $SQLDBs
}

#functioncall
ListAllSQLDBs -DatabaseServer "mydbserver"

Tuesday, May 7, 2013

SharePoint Crawl Log Error: “The SharePoint item being crawled returned an error when attempting to download the item” .. for eg. *.aspx files

After some research I found a solution for that problem

Open Regedit on your search server/s

Navigate to this registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\Search\Global\Gathering Manager

Change Value "UserAgent" from  "MSIE 4.01" to "MSIE 8.0"

Restart the SharePoint Search Service.

Open a SharePoint PowerShell

Get-SPSessionStateService

If this returns false then we need to deploy one

Enable-SPSessionStateService -DatabaseName “NameOfDatabase”

Monday, May 6, 2013

Delete Webs Recursive with PowerShell


$web = Get-SPWeb "http://localhost/sites/webwithsubwebs/"

function RemoveSPWebRecursively([Microsoft.SharePoint.SPWeb] $web)
{
 
    $subwebs = $web.GetSubwebsForCurrentUser()
   
    foreach($subweb in $subwebs)
    {
        RemoveSPWebRecursively($subweb)
        $subweb.Dispose()
    }
    Remove-SPWeb $web -Confirm:$false
}


RemoveSPWebRecursively $web

Partial "Index Reset"

This script will remove and re-add your content source's start addresses.
SharePoint will more or less rebuild the index for these sources, when a full crawl is started.


$sourceName = "Local SharePoint sites"

$SSA = Get-SPEnterpriseSearchServiceApplication
$source = Get-SPEnterpriseSearchCrawlContentSource -Identity $sourceName -SearchApplication $SSA
$startaddresses = $source.StartAddresses | ForEach-Object { $_.OriginalString }
$source.StartAddresses.Clear()
ForEach ($address in $startaddresses ){ $source.StartAddresses.Add($address) }