Thursday, 23 April 2015

Update-SPDistributedCacheSize : Cannot bind parameter 'CacheSizeInMB'. Cannot convert value "250 MB" to type "System.UInt32". Error: "Input string was not in a correct format."



Get Distributed Cache :

To check the existing memory allocation for the Distributed Cache service on a server, run the following command at the SharePoint Management Shell command prompt:


cls
asnp "*sh*"
Use-CacheCluster

Get-AFCacheHostConfiguration -ComputerName "spdev" -CachePort "22233" 



Update Cache :


  1. Stop the Distributed Cache service on all cache hosts. To stop the Distributed Cache service, go to Services on Server in Central Administration, and Stop the Distributed Cache service on all cache hosts in the farm.
  2. To reconfigure the cache size of the Distributed Cache service, run the following command one time only on any cache host at the SharePoint Management Shell command prompt:
    Update-SPDistributedCacheSize -CacheSizeInMB CacheSize 
    
    
    Where:
    • CacheSize is the cache size's memory allocation assignment in MB. In the previous example, the cache size was calculated at 7168 MB for a server with 16 GB of total memory.
  3. Restart the Distributed Cache service on all cache hosts. To restart the Distributed Cache service, go to Services on Server in Central Administration, and Start the Distributed Cache service on all cache hosts in the farm.
ex:

Update-SPDistributedCacheSize -CacheSizeInMB "250 MB" 

Update-SPDistributedCacheSize : Cannot bind parameter 'CacheSizeInMB'. Cannot 
convert value "250 MB" to type "System.UInt32". Error: "Input string was not in 
a correct format."
At line:1 char:46
+ Update-SPDistributedCacheSize -CacheSizeInMB "250 MB"
+                                              ~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Update-SPDistributedCacheSiz 
   e], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.SharePoin 
   t.PowerShell.SPCmdletConfigureDistributedCacheSize


In order to Fix the issue remove "MB" in string , pass only int value

Update-SPDistributedCacheSize -CacheSizeInMB  250

Again We will See updated Cache in the Server.

cls
asnp "*sh*"
Use-CacheCluster

Get-AFCacheHostConfiguration -ComputerName "spdev" -CachePort "22233" 

You can see Value increased to 250 MB.



Thursday, 16 October 2014

The content type “Document Collection Folder” at “…” is sealed.



 The content type “Document Collection Folder” at “…” is sealed - SharePoint 2013


In an Asset Library When user tries to upload a Video file below error pops up 

but this won't pop up if a user tries to upload image files


Solution to Above issue is We need to Activate "Video and Rich Media"  Feature at SiteCollection Level and he has to delete the existing Asset library and create the new Asset library.



Wednesday, 15 October 2014

Break List Item Permissions PowerShell


Break Permissions Item Level / Custom Permissions at item level


Blow PowerShell script will retain list permission and give unique permissions atitem level.

We had a requirement to break all item level permissions and remove all the Groups and individual permissions at the item level and Add Owners group and Approvers group  to all items and also it should retain the permissions of item created by.

At the  item level it will delete the all inherited Groups from List and Add specific groups to each item name called " Owners" with  "Full Control " and "Approvers" with "Design" Permissions.



 clear

asnp "*sh*"

$web=Get-SPWeb -Identity "http://weshare.sedwdev.local/sites/teste"

Write-Host " Author is " $web.Author.DisplayName

$list=$web.Lists.TryGetList("SourceList")

foreach($item in $list.Items)
{
    if(!$item.HasUniqueRoleAssignments)
 {
        $item.BreakRoleInheritance($false)

 for($i=0 ; $i -lt $item.RoleAssignments.Count;$i++)
    {

   if(!$item["Created By"])
{
     $item.RoleAssignments.remove($i)

    $item.Title + "permissions Removed "
  
  } }

  foreach( $grp in $web.Groups)
  {
    
     if ($grp.Name -match "teste Owners")
     {

     $rolAsgnmt=New-Object Microsoft.SharePoint.SPRoleAssignment($grp);

     $roldef=$web.RoleDefinitions["Full Control"]

     $rolAsgnmt.RoleDefinitionBindings.Add($roldef);

     $item.RoleAssignments.Add($rolAsgnmt);

     " Item title is  "+ $item.Title + "  Group Added is  " + $grp.Name

     $item.Update();
    
     }

    elseif ($grp.Name -match "Approvers")
     {

     $rolAsgnmt1=New-Object Microsoft.SharePoint.SPRoleAssignment($grp);

     $roldef1=$web.RoleDefinitions["Design"]

     $rolAsgnmt1.RoleDefinitionBindings.Add($roldef1);

     $item.RoleAssignments.Add($rolAsgnmt1);

     " Item title is  "+ $item.Title + "  Group Added is  " + $grp.Name

     $item.Update();
     }
     }  
 }
 }

OutPut:





Wednesday, 8 October 2014

Remove Duplicates in Search Results Webpart


Remove duplicates in Search Results Webpart


asnp "*sh*"


$resultsPage = "Pages/default.aspx"

$resultsUrl = "$siteUrl/$resultsPage"

$spweb = Get-SPWeb $siteUrl

$page = $spweb.GetFile($resultsPage)

# Check if the page is checked out to someone if so override the checkout

$bool=$page.CheckedOut

if($bool)
{
$page.UndoCheckOut();
}

# checkout the Page

$page.CheckOut()

# Get the web part manager for the page
$webPartManager = $spweb.GetLimitedWebPartManager($resultsUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

# And pull the web part we want to work on
$webpart = $webpartmanager.WebParts | ? { $_.Title -eq 'Latest News' }

$dataProvider = ConvertFrom-Json $webpart.DataProviderJSON

$dataProvider.TrimDuplicates = 'True'

$webpart.DataProviderJSON = ConvertTo-Json $dataProvider -Compress

$webpartmanager.SaveChanges($webpart)

$page.CheckIn('Setting the duplicates in LatestNews');

$page.Publish('Duplicates were set in Latest News Webpart');

$spweb.Dispose();


OutPut:


Tuesday, 7 October 2014

Increase Site Quota using PowerShell

PowerShell Script to Increase Storage Individual Quota


Increasing the SiteCollection Storage without Specifying Site Quota that is individual level,

Here we are increasing the site quota to 5 GB, and setting Warning to 4.5 GB



clear

asnp "*sh*"

$site=Get-SPSite -Identity "http://sedwdevrtm:432/sites/ProductsSite"

# Here We are setting Max storage to 5GB and Warning level to 4GB

Set-SPSite -Identity $site -MaxSize 5GB -WarningSize 4.75GB 

# we are seeing what is the maximum storage and warning level set for the site.

$site.Quota.StorageMaximumLevel/1GB


$site.Quota.StorageWarningLevel/1GB  


Output:




Monday, 4 August 2014

Rename a Site using Powershell/ Rename SiteCollection Powershell


PowerShell Script to rename a SiteCollection

Here are renaming the site from energimiljo to Energymill

cls

asnp "*sh*"

$site=Get-SPSite -Identity "http://SP2013dev.com/sites/energimiljo/"

$site.Rename("http://SP2013dev.com/sites/energymills")

$site.Dispose()

Tuesday, 29 July 2014

Add WebPart to Page using PowerShell


Below Powershell Script will add Webpart to a page , by reading the Site URL from text file , and 

here we are adding the Webpart to a page by exporting the webpart to our local drive and exported 

webpart will be in xml file and we are writing the xml file to a page.

To add a webpart to a page first we need to check if a page is checked out to any user, if so then act according to your requirement, here in our case we are overriding the checkout and adding the webpart and publishing the same to the page.

Here we are writing the output to textfile instead of writing it on powershell console.

Here "CollabrationURL" is the name of the column in the textfile for SiteURL

cls

asnp "*sh*"

$file=Import-Csv -Path "C:\Manju\SiteUrl.txt"

$web=Get-SPweb -Identity $file.CollabrationURL

[xml]$webpartxml= Get-Content -Path "C:\Manju\WPRequest.xml"

$SR = New-Object System.IO.StringReader($webpartxml.OuterXml)

$XTR = New-Object System.Xml.XmlTextReader($SR)

$err=$null

$WebPartZoneID = "Topzone"

$WebPartZoneIndex = 0

 try
   {

  $page=$web.GetFile("Pages/default.aspx");

  $bool=$page.CheckedOutBy

        if($bool)
        {
            Write-Host "Page is already Checkout to " $page.CheckedOutBy.UserLogin

            $page.UndoCheckOut()

            Write-Host "Page is Over ridded by " $web.CurrentUser.DisplayName
        }

    $page.CheckOut();

    $wmgr=$web.GetLimitedWebPartManager($page,[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared);

    $webpart=$wmgr.ImportWebPart($XTR,[ref]$err);

    $wmgr.AddWebPart($webpart,$WebPartZoneID,$WebPartZoneIndex);

    $page.CheckIn('dude');

    $page.Publish('Adding request Site Webpart')

    "Request Site WebPart SucessfullAdded" + (Get-Date -DisplayHint Date) | Out-File -Append "C:\OutPutLog.txt"
    
     $SR.Close();
     $XTR.Close();
     $web.Dispose()

    }
    catch
    {
        $ErrorMessage = $_.Exception.Message
   
        "Request Site WebPart Failure" + $ErrorMessage  +  (Get-Date -DisplayHint Date) | Out-File -Append "C:\ErrorLog.txt"
    }