Showing posts with label Share Point. Show all posts
Showing posts with label Share Point. Show all posts

Friday, 24 March 2017

Troubleshoot PowerShell Add-Type Load Error [Tip]

In the last couple of days I am working with a client that has a DMS solution based on SharePoint Server 2010. We inherited the solution so it has it's specifics. One of those little things (that make life exciting) is that they have fields with custom data types. 
I had to do a powershell script that will edit some document metadata. I had to update standard SharePoint native data type fields, but after updating the item in powershell I lost the values of the custom data type fields. I realized that I need the custom data type loaded in the powershell session. So I started to import some DLLs, in the order that I thought it makes sense as we do not have the source code of the solutions.This was fine until I received the error below:

Add-Type : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

This error is completely generic and the only useful thing is that it tells us where we can find more useful information.
This simple error handling script turned out to be life saver for me as it showed exactly what the load error is and which dependent assembly I need to load first :)


The nice blue text is our LoaderExceptions property of the exception. I hope that you find it useful!
LoaderExceptions Powershell

Wednesday, 17 February 2016

Get a quick report of the SharePoint Databases with PowerShell [Tip]

Here comes another useful PowerShell one-liner I often use.
It will give you a quick overview of the SharePoint databases with properties like: Name, Server(Alias), TypeName, Web application name, Web application URL, Site collection count and the Size.
The size is actually the amount of disk space required for uncompressed backup. It might look something like a script, but actually it is a long and simple one-liner. You can see it below, I have used grave-accent(`) escape characters to fit it better in the blog. You can see it in one line here. Instead of piping to Format-Table you can generate CSV by piping to Export-CSV and later work with it in Excel.

Get-SPDatabase | Select-Object Name,@{Expression={$_.Server};Label="Server"},TypeName,@{Expression=`
{$_.WebApplication.Name};Label="WebAppLication"},@{Expression={$_.WebApplication.Url};Label="WebAppLicationUrl"}`
,@{Expression={($_.WebApplication.Sites | Measure).Count};Label="SC Count"},@{Label ="Size in MB";`
 Expression ={$_.disksizerequired/1024/1024}} |  Format-Table -AutoSize

Get SharePoint database report

Monday, 9 June 2014

SharePoint 2013 Quota Template creation script

As SharePoint administrator I frequently have requests for for setting up new site collection quotas and associating site collection with them.
For me, the process for this task is very annoying when it is done via the UI in the Central administration.
The problem is that we do not have OOB PowerShell functions to do this. So I created a script that can create new quota templates and can associate it with one or more site collections.
You just need to give a Name of the new quota template (the script will check first if there is a quota whit this name) Max Level of storage. Optionally you can give a Warning Level, but if it is not specified the script will set 80% from the Max value.

The script is creating the quota via the Object Model and assignment of the quota is done with the Set-SPSite cmdlet.


function CreateQuotaTemplate ($qName, $qMaxLevelMB, $qWarnLevelMB)
{
    $quotaTemplate = New-Object Microsoft.SharePoint.Administration.SPQuotaTemplate
    $quotaTemplate.Name = $qName
    $quotaTemplate.StorageMaximumLevel = ($qMaxLevelMB * 1024)*1024
    $quotaTemplate.StorageWarningLevel = ($qWarnLevelMB * 1024)*1024
    $contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
    $contentService.QuotaTemplates.Add($quotaTemplate)
    $contentService.Update()
}


Below you can see how the new quota is created. It may not appear immediately in the Central Admin page, but you can see it by listing all quotas with flowing line:


[Microsoft.SharePoint.Administration.SPWebService]::ContentService.QuotaTemplates



As I said above. You can create a quota and directly apply it to one or many site collection.



Feel free to use and modify the script to best suit your needs. I am working with it on SharePoint 2013 on PowerShell 4.0