Add Allowed Inline Downloaded MIME Types for one Web Application in Microsoft SharePoint Server 2010

Introduction

This script could be used to add allowed inline downloaded MIME types for one Web Application in Microsoft SharePoint Server 2010.

Scenarios

By default PDF files cannot open in browser. It is not listed as a safe MIME type. But for most companies, PDF files are widely used in their daily work, so it is necessary to add PDF to the allowed inline downloaded MIME types list.

Script

This script contains one advanced function, Get-OSCSPCheckoutFileList. You can use this script in following ways:

Method 1:

  1. Download the script and copy it to a Microsoft SharePoint 2010 server.
  2. Open the script file with Notepad or any other script editors.
  3. Scroll down to the end of the script file, and then add the example command which you want to run.
  4. Save the file then run the script in SharePoint 2010 Management Shell.

Method 2:

  1. Rename scriptname.ps1 to scriptname.psm1 (PowerShell Module file)
  2. Run Import-Module cmdlet to import this module file.
     Import-Module filepath\scriptname.psm1

 

PowerShell
Edit|Remove
Function Add-OSCSPWebAppMimeTypes 
{ 
    [CmdletBinding()] 
    Param 
    ( 
        #Define parameters 
        [Parameter(Mandatory=$true,Position=1)] 
        [string]$Identity, 
        [Parameter(Mandatory=$true,Position=2)] 
        [string[]]$MIMEType     
    ) 
    Process 
    { 
        #Display Information Message 
        $title = $Messages.SecurityWarningTitle 
        $message = $Messages.SecurityWarning 
        $message = $message -replace "Placeholder01",$MIMEType 
        $yes = New-Object System.Management.Automation.Host.ChoiceDescription $($Messages.ChoiceYes),$($Messages.ChoiceYesMsg01) 
        $no = New-Object System.Management.Automation.Host.ChoiceDescription $($Messages.ChoiceNo),$($Messages.ChoiceNoMsg01) 
        $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes$no) 
        $result = $host.ui.PromptForChoice($title$message$options, 1) 
        switch ($result) 
        { 
            0 {$userConfirmed = $true} 
            1 {$userConfirmed = $false} 
        }         
        if ($userConfirmed) { 
            Try 
            { 
                $spWebApplication = Get-SPWebApplication -Identity $Identity -Verbose:$false 
            } 
            Catch 
            { 
                $pscmdlet.WriteError($Error[0]) 
            } 
            foreach ($mimeTypeItem in $MIMEType) { 
                if ($spWebApplication.AllowedInlineDownloadedMimeTypes -notcontains $mimeTypeItem) { 
                    $verboseMsg = $Messages.AddMIMEType 
                    $verboseMsg = $verboseMsg -replace "Placeholder01",$mimeTypeItem 
                    $pscmdlet.WriteVerbose($verboseMsg) 
                    $spWebApplication.AllowedInlineDownloadedMimeTypes.Add($mimeTypeItem) 
                    $spWebApplication.Update() 
                } else { 
                    $warningMsg = $Messages.ExistedType 
                    $warningMsg = $warningMsg -replace "Placeholder01",$mimeTypeItem 
                    $pscmdlet.WriteWarning($warningMsg) 
                } 
            } 
        } else { 
            return $null 
        } 
    } 
} 
 
 

 

Examples

Example 01: Displays help about Get-OSCSPWebAppMimeTypes
Command: Get-Help Get-OSCSPWebAppMimeTypes -Full
Screenshot:

 

Example 02: Retrieve allowed inline downloaded MIME types from one web application.
Command:
 Get-OSCSPWebAppMimeTypes -Identity "http://sitename:8082"
Screenshot:

 

Example 03: Add MIME type application/pdf to allowed inline downloaded MIME types for one web application.
Command:
 Add-OSCSPWebAppMimeTypes -Identity "http://sitename:8082" -MIMEType "application/pdf" -Verbose
Screenshot:


Additional Resources

Technical Resource:

Windows PowerShell Advanced Function
http://technet.microsoft.com/en-us/library/dd315326.aspx

Microsoft.SharePoint.Administration.SPWebApplication Class
http://msdn.microsoft.com/en-us/library/ms463140.aspx

Forum Threads:

Permissive Browser File Handling Security Downfalls?
http://social.technet.microsoft.com/Forums/en-US/sharepoint2010customization/thread/576131e3-38c7-4d97-8699-b82d5b3d32b5