Posted by: R Manimaran | December 22, 2010

SharePoint Blocked FileType using PowerShell

I have just started Hello World in PowerShell and SharePoint. I have created some three functions which will
• List all Blocked File Types in a Web Application
• Add a new Blocked File Type
• Remove-Blocked File Type

Here are the functions.
First Load Reference to Microsoft.SharePoint.Administration as

[Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration")
function Get-BlockedFileTypes()
{
  param($url=$(throw "Url is required"))
   $webApp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($url)
   
   foreach($str in $webApp.BlockedFileExtensions)
   {
     Write-Host $str
   }
}
function Add-BlockedFileTypes([string]$url,[string] $ext)
{
  $webApp =[Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($url)
  $webApp.BlockedFileExtensions.Add($ext)
  $webApp.Update()
}
function Remove-BlockedFileTypes([string]$url,[string]$filetype)
{
 $webApp =[Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($url)
 $isDeleted = $webApp.BlockedFileExtensions.Remove($filetype)
 if($isDeleted -eq $true)
  {
    Write-Host "FileType Deleted"
	
  }
  else
  {
    Write-Host "Unable to delete the FileType"
  }  
  $webApp.Update()  
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: