This script could be used to add allowed inline downloaded MIME types for one Web Application in Microsoft SharePoint Server 2010.
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.
This script contains one advanced function, Get-OSCSPCheckoutFileList. You can use this script in following ways:
Method 1:
Method 2:
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
}
}
}
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 } } }
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:

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