Tuesday, February 4, 2014

Distributed Cache Powershell commands

From http://technet.microsoft.com/en-us/library/jj219613.aspx
Change the service account running the Distributed Cache
It is recommended to use a SharePoint managed account for this service.
$spfarm = Get-SPFarm
$spcacheService = $spfarm.Services | where {$_.Name -eq “AppFabricCachingService”}
$spaccount = Get-SPManagedAccount -Identity domain\spdistcache$spcacheService.ProcessIdentity.CurrentIdentityType = “SpecificUser”
$spcacheService.ProcessIdentity.ManagedAccount = $spaccount
$spcacheService.ProcessIdentity.Update()
$spcacheService.ProcessIdentity.Deploy()

Graceful stop and deattach local server (No lost cache data)
Stop-SPDistributedCacheServiceInstance -Graceful
Remove-SPDistributedCacheServiceInstance
Deattach local server from a cache cluster (Multiple Distributed Cache servers)
Remove-SPDistributedCacheServiceInstance
Reattach local server to a cache cluster (Multiple Distributed Cache servers)
Add-SPDistributedCacheServiceInstance
Delete the service
$instanceName =”SPDistributedCacheService Name=AppFabricCachingService”
$serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}
$serviceInstance.delete()
Verify in Central Admin, System Settings, Manage Services on Server. It should be gone from this list when it has been completely deleted.
In a multi server farm, you will have to select which server to show the services from in the top-right dropdown.
Create a new service
Add-SPDistributedCacheServiceInstance
Verify in Central Admin, System Settings, Manage Services on Server. It should appear in this list when it has been created. In a multi server farm, you will have to select which server to show the services from in the top-right dropdown.
Start the service on a server
$instanceName =”SPDistributedCacheService Name=AppFabricCachingService”
$serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}
$serviceInstance.Provision()
Stop the service on a server
$instanceName =”SPDistributedCacheService Name=AppFabricCachingService” $serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}
$serviceInstance.Unprovision()
Check current Cache memory allocation
Use-CacheCluster Get-AFCacheHostConfiguration -ComputerName $env:computername -CachePort “22233″
Change the Cache memory allocation
On all Cache servers in the farm stop the service
$instanceName =”SPDistributedCacheService Name=AppFabricCachingService” $serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}
$serviceInstance.Unprovision()
Update the memory allocation
Update-SPDistributedCacheSize -CacheSizeInMB CacheSize
Start the service on all Cache servers
$instanceName =”SPDistributedCacheService Name=AppFabricCachingService” $serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}
$serviceInstance.Provision()


Remove a host from the cluster: if all else failes
Stop-CacheHost -HostName <servername> -CachePort 22233


Unregister-CacheHost -HostName <servername> -RemoveServicePermissions -ProviderType SPDistributedCacheClusterProvider -ConnectionString 'Data Source=<dbservername>;Initial Catalog=<SharePoint_Config>;Integrated Security=True;Enlist=False'

Wednesday, January 29, 2014

SharePoint 2013 Global navigation: Wrap the menu items

In the master page, there needs to be three things added and one setting modified.  Then you'll have to add to your custom css file (this part is optional but after you see the menu, you'll want to add this).

The items to add to your master file in the SharePoint:AspMenu are:
ItemWrap="true"
RenderingMode="List"
cssClass="mycss-aspmenuclass"

The item to change in the master page setting UseSimpleRendering to false.

this is that it looks like out of the box:

------------------------------------------------------------
<SharePoint:AspMenu
   ID="TopNavigationMenu"
   Runat="server"
   EnableViewState="false"
   DataSourceID="topSiteMap"
   AccessKey="<%$Resources:wss,navigation_accesskey%>"
   UseSimpleRendering="true"
   UseSeparateCss="false"
   Orientation="Horizontal"
   StaticDisplayLevels="2"
   AdjustForShowStartingNode="true"
   MaximumDynamicDisplayLevels="2"
   SkipLinkText="" />
------------------------------------------------------------

this is what it should look like after your changes.
-------------------------------------------------------------
<SharePoint:AspMenu
   ID="TopNavigationMenu"
   Runat="server"
   EnableViewState="false"
   DataSourceID="topSiteMap"
   AccessKey="<%$Resources:wss,navigation_accesskey%>"
   UseSimpleRendering="false"
   UseSeparateCss="false"
   Orientation="Horizontal"
   StaticDisplayLevels="2"
   AdjustForShowStartingNode="true"
   MaximumDynamicDisplayLevels="2"
   SkipLinkText=""
   ItemWrap="true"
   RenderingMode="List"
   cssClass="mycss-aspmenuclass"/>

---------------------------------------------------------------
Now add to your custom css file three items so that there is some space between the menu items.

.mycss-aspmenuclass .level1   
{
 margin-left: 10px;
 margin-right: 20px;
}
.mycss-aspmenuclass .level2
{
 margin-left: 10px;
 margin-right: 20px;
}
.mycss-aspmenuclass .level3
{
 margin-left: 10px;
 margin-right: 20px;
}

 

Thursday, December 5, 2013

Fix a Secure Store service or any SharePoint service stuck on starting or stopping

change the "Server Name" in the script.  To stop change Provision() to UnProvision()

one thing to note is that if the status is provisioning, then you'll most likely need to Provision() then UnProvision().

Also all you need to do is get the service instance for other services by the type or name. 

--------------------------------------------------------------
add-pssnapin MIcrosoft.SharePoint.Powershell

Function MatchComputerName($computersList, $computerName)
{
                If ($computersList -like "*$computerName*") { Return $true; }
    foreach ($v in $computersList) {
      If ($v.Contains("*") -or $v.Contains("#")) {
            # wildcard processing
            foreach ($item in -split $v) {
                $item = $item -replace "#", "[\d]"
                $item = $item -replace "\*", "[\S]*"
                if ($computerName -match $item) {return $true;}
            }
        }
    }
}

           $secureStoreServiceInstances = Get-SPServiceInstance | ? {$_.GetType().Equals([Microsoft.Office.SecureStoreService.Server.SecureStoreServiceInstance])}
            $secureStoreServiceInstance = $secureStoreServiceInstances | ? {MatchComputerName $_.Server.Address "Server Name"}
           
            Write-HOst $secureStoreServiceInstance.Status

            $secureStoreServiceInstance.Provision()

Monday, November 25, 2013

Office Web App for SharePoint 2013 Cheat sheet

Run on the Office Web App server (can not have sharepoint installed, it is stand alone now).
---------------------------------------------------
1.Download KB2592525  to folder on your system
2.Create a new folder called “files”
3.Extract the MSU: expand Windows6.1-KB2592525-x64.msu –F:* .\files
4.go to files
5.Install using Pkgmgr: pkgmgr /ip /m:Windows6.1-KB2592525-x64.cab


Import-Module ServerManager

Add-WindowsFeature Web-Server,Web-WebServer,Web-Common-Http,Web-Static-Content,Web-App-Dev,Web-Asp-Net,Web-Net-Ext,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Includes,Web-Security,Web-Windows-Auth,Web-Filtering,Web-Stat-Compression,Web-Dyn-Compression,Web-Mgmt-Console,Ink-Handwriting,IH-Ink-Support

New-OfficeWebAppsFarm –InternalURL "http://url" -AllowHttp -EditingEnabled

Set-OfficeWebAppsFarm -LogLocation "D:\ULSLogs" -CacheLocation "D:\Cache" -RenderingLocalCacheLocation "D:\RenderCache"



On the sharepoint server, open powershell (if ISE, will need Add-pssnapin Microsoft.SharePoint.Powershell)
--------------------------------------
New-SPWOPIBinding -ServerName <WacServerName> -AllowHTTP
$WOPIzone = Get-SPWOPIZone
if($WOPIzone -neq "internal-http")
{
 Set-SPWOPIZone –zone "internal-http"
}

$AllowOAuth = (Get-SPSecurityTokenServiceConfig).AllowOAuthOverHttp
if($AllowOAuth -eq $false)
{
    $config = (Get-SPSecurityTokenServiceConfig)
    $config.AllowOAuthOverHttp = $true
    $config.Update()
}
(Get-SPSecurityTokenServiceConfig).AllowOAuthOverHttp

 

Thursday, October 31, 2013

Powershell to list all webs with UI version 3 for sharepoint 2013 upgrade purpose


Add-Pssnapin Microsoft.SharePoint.Powershell
 
$s | Get-SPSite -limit all | ForEach-Object {$site =$_;

$site | Get-SPWeb -limit all | ForEach-Object {

if($_.UIVersion -eq 3)

{

write-host "UI version : " $_.UIVersion  $_.Url

}

}}

SharePoint 2010 and Project Web app error provisioning

Had a strange error the other day with provisioning a Project Web Application (PWA).  

The errors didn't really say much except these three event log items.  Errors below. 

To resolve I have to create the PWA site on another environment and then do a back up and restore to a site collection in the environment that was breaking.   then run the provisioning on central admin.  Everything works great after. 


- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">

- <System>

<Provider Name="Microsoft-SharePoint Products-Project Server" Guid="{B2178104-...}" />

<EventID>7381</EventID>

<Version>14</Version>

<Level>2</Level>

<Task>20</Task>

<Opcode>0</Opcode>

<Keywords>0x4000000000000000</Keywords>

<TimeCreated SystemTime="2013-10-23T21:08:38.396865600Z" />

<EventRecordID>251151</EventRecordID>

<Correlation ActivityID="{DE39B42B...}" />

<Execution ProcessID="7972" ThreadID="4988" />

<Channel>Application</Channel>

<Computer>xxx.domain.com</Computer>

<Security UserID="S-1-5..." />

</System>

<EventData />

</Event>
-----------------------------------------------------------------
- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">

- <System>

<Provider Name="Microsoft-SharePoint Products-Project Server" Guid="{B2178104..}" />

<EventID>6966</EventID>

<Version>14</Version>

<Level>2</Level>

<Task>20</Task>

<Opcode>0</Opcode>

<Keywords>0x4000000000000000</Keywords>

<TimeCreated SystemTime="2013-10-23T21:08:39.100031100Z" />

<EventRecordID>251152</EventRecordID>

<Correlation ActivityID="{DE39B42B...}" />

<Execution ProcessID="7972" ThreadID="4988" />

<Channel>Application</Channel>

<Computer>xxx.domain.com</Computer>

<Security UserID="S-1-5..." />

</System>

- <EventData>

<Data Name="string0">PW</Data>

<Data Name="string1">Microsoft.Office.Project.Server.Administration.ProvisionException: Post provisioning setup failed. at Microsoft.Office.Project.Server.Administration.PsiServiceApplication.CreateSite(ProjectProvisionSettings provset)</Data>

</EventData>

</Event>
-------------------------------------------------------------------------------------------------
- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">

- <System>

<Provider Name="Microsoft-SharePoint Products-Project Server" Guid="{B2178104...}" />

<EventID>6971</EventID>

<Version>14</Version>

<Level>2</Level>

<Task>20</Task>

<Opcode>0</Opcode>

<Keywords>0x4000000000000000</Keywords>

<TimeCreated SystemTime="2013-10-25T18:11:34.919153600Z" />

<EventRecordID>252921</EventRecordID>

<Correlation ActivityID="{27BA856F...}" />

<Execution ProcessID="9040" ThreadID="2700" />

<Channel>Application</Channel>

<Computer>xxx.domain.com</Computer>

<Security UserID="S-1-5..." />

</System>

- <EventData>

<Data Name="string0">/PWA</Data>

<Data Name="string1">Microsoft.Office.Project.Server.Administration.ProvisionException: Post provisioning setup failed. at Microsoft.Office.Project.Server.Administration.PsiServiceApplication.CreateSite(ProjectProvisionSettings provset)</Data>

</EventData>

</Event>

Thursday, October 17, 2013

Simple powershell to set key/value pair in the web application properties

-Don't forget to add the snap in if not using the sharepoint ps console.

function SetPropertyBag ($webAppUrl, $key, $value) {

    $spwebApp=Get-SPWebApplication -Identity $webAppUrl
    Write $spwebApp

    if($spwebApp.AllProperties.ContainsKey($key) -eq $False)
    {
        $spwebApp.AllProperties.Add($key,$value);      
    }
    else
    {$spwebApp.AllProperties[$key]=$value; }

    Write-Host -foregroundcolor Green "value set in "  $key  " = "  $spwebApp.AllProperties[$key]  

    }

$webAppUrl= Read-Host 'Enter the web application url';

$keystring= Read-Host 'Enter the key string';
$valuestring= Read-Host 'Enter the value string';
SetPropertyBag $webAppUrl $keystring $valuestring;