Updated 31-07-2012: Increased performance by using the .AllWebs property instead of using Get-SPWeb for each SPSite object.

When do you use it?

The script provides a solution when it comes to the very common "I cannot open the PDF without saving it first" problem.

In some scenario's, the General Settings in the Web Application Management does not work.
This can be the case when you work with templates. This was my reason for creating the script.

Make sure you start PowerShell as administrator, run the script and then you can use the function provided by the script.

Check My blog article for a detailed step-by-step problem / solution description.

 

PowerShell
Edit|Remove
param  
( 
[string] $URL, 
[boolean] $writeToFile = $true 
) 
#Change Browser File Handling for all lists and libraries in SharePoint 2010 farm 
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 
 
#Counter variables 
$webcount = 0 
$listcount = 0 
 
if($writeToFile -eq $true) 
{ 
$outputPath = Read-Host "Outputpath (e.g. C:\directory\filename.txt)" 
} 
 
if(!$URL) 
{ 
#Grab all webs 
Get-SPSite -Limit All | % {$webs += $_.Allwebs} 
} 
else 
{ 
$webs = Get-SPWeb $URL 
} 
     
if($webs.count -ge 1 -OR $webs.count -eq $null) 
{ 
    foreach($web in $webs) 
    { 
    #Grab all lists in the current web that have the "Strict" Browser file handling 
    $lists = $web.Lists | ?{$_.BrowserFileHandling -eq "Strict"} 
    #If there are lists that have the strict browserfilehandling 
        if(-not(!$lists)) 
        { 
        Write-Host "Website"$web.url -ForegroundColor Green   
        if($writeToFile -eq $true){Add-Content -Path $outputPath -Value "Website $($web.url)"} 
            foreach($list in $lists) 
            {  
            #Change the browser file handling to permissive 
            $list.BrowserFileHandling = "Permissive"  
            $list.Update() 
            $listcount +=1 
            Write-Host " - "$list.Title updated           
            if($WriteToFile -eq $true){Add-Content -Path $outputPath -Value " - $($list.Title) updated"} 
            } 
    $webcount +=1 
    $web.Dispose() 
        } 
    } 
#Show total counter for checked webs & lists 
Write-Host "Amount of webs that were updated:"$webcount 
Write-Host "Amount of lists updated:"$listcount 
if($WriteToFile -eq $true){Add-Content -Path $outputPath -Value "Amount of webs updated:$($webcount)"Add-Content -Path $outputPath -Value "Amount of lists updated: $($listcount)"} 
} 
else 
{ 
Write-Host "No webs retrieved, please check your permissions" -ForegroundColor Red -BackgroundColor Black 
}
 You can run the script by navigating to the folder where you saved the script, and run the following command:
.\Change-BrowserFileHandling.ps1
The parameters are not mandatory, so you can leave those out, or you can explicitly add them to fit your needs.
For example, you could run .\Change-BrowserFileHandling.ps1 -writeToFile $false. Now you will not get a output file with the results, just visual confirmation from the PowerShell console.