Add PDF mimetype for all Web Applications one-liner

By default, PDF files cannot be opened directly from SharePoint 2010/SharePoint 2013.

To add the PDF mimetype to all Web Applications (Instead of doing it seperately for each Web Application), you can use the following one-liner:

Get-SPWebApplication | %{$_.AllowedInlineDownloadedMimeTypes.Add("application/pdf");$_.Update()}
Advertisements

When were my site collections created?

Have you ever wondered when your site collections were created?
Try the following one liner to get all the information you need:

Get-SPSite -Limit All | %{$root = $_.rootweb; $date = $root.created.toShortDateString(); Write-Host "$($root.url) was created on $($date)"}

image

Get Content Databases per Web Application one-liner

Another one in the series of one-liners. This one will show you all Web Applications, and all associated Content Databses for these Web Applications:

Get-SPWebApplication | %{Write-Output "`n- $($_.url)"; foreach($cd in $_.contentdatabases){Write-Output $cd.name}}

The output will look similar to this:

image

You can output this to a text file by running the following:

Get-SPWebApplication | %{Write-Output "`n- $($_.url)"; foreach($cd in $_.contentdatabases){Write-Output $cd.name}} >> D:\filename.txt

Get current superuser/superreader accounts PowerShell One-liner

This one-liner wil show you the currently configured superuser and superreader accounts for each of your Web Applications.Just paste this line of code in your SharePoint 2010 Management Shell:

Get-SPWebApplication | %{Write-Host “Web Application: ” $_.url “`nSuper user: ” $_.properties[“portalsuperuseraccount”] “`nSuper reader: ” $_.properties[“portalsuperreaderaccount”] “`n”}

This is the output for the above command in my test environment:

image

In my case, I have not properly configured the super user accounts for all my Web Applications.

Be aware that misconfigured super user accounts can lead to access problems. You may not be able to access your SharePoint Web Application!

Get Site Collections per Content Database one-liner

This will be a very short post, as it contains only 1 line of PowerShell code, and is not very hard to understand. It shows you all content databases, and for each of the content databases, it will show you the site collections within this content database.

Get-SPContentDatabase | %{Write-Output "- $($_.Name)”; foreach($site in $_.sites){write-Output $site.url}}

That wasn’t so bad right? Just copy and paste this code into your SharePoint 2010 Management Shell (As administrator), and let PowerShell do your work for you!

image

Now let’s say you want to save this output to a .txt file, you can add “> C:\sitecollections.txt”.

The full command would be:

Get-SPContentDatabase | %{Write-Output "- $($_.Name)”; foreach($site in $_.sites){write-Output $site.url}} > C:\sitecollections.txt

This would create a .txt file with the same information:

image

That’s all there is to it!