Search/Identify blocked file types in SharePoint

In SharePoint 2016 On-Prem, Microsoft has reduced the number of blocked file types from previous versions of SharePoint. It is totally different than the SharePoint 2010 / 2013. In SharePoint 2013, there are 105 default file types that are blocked by default but in SharePoint 2016, this number goes all the way down to 6. Interestingly, there is no blocked file type in SharePoint Online.

Self-Note:

Block type references:

Small Script to find all blocked file types:

$path = "C:\DRIVERS";
$extensitons = @("*.ade","*.adp","*.asa","*.ashx","*.asmx","*.asp","*.bas","*.bat","*.cdx","*.cer",`
                "*.chm","*.class","*.cmd","*.cnt","*.com","*.config","*.cpl","*.crt","*.csh","*.der",`
                "*.dll","*.exe","*.fxp","*.gadget","*.grp","*.hlp","*.hpj","*.hta","*.htr","*.htw","*.ida",`
                "*.idc","*.idq","*.ins","*.isp","*.its","*.jse","*.json","*.ksh","*.lnk","*.mad","*.maf","*.mag",`
                "*.mam","*.maq","*.mar","*.mas","*.mat","*.mau","*.mav","*.maw","*.mcf","*.mda","*.mdb",`
                "*.mde","*.mdt","*.mdw","*.mdz","*.ms-one-stub","*.msc","*.msh","*.msh1","*.msh1xml",`
                "*.msh2","*.msh2xml","*.mshxml","*.msi","*.msp","*.mst","*.ops","*.pcd","*.pif","*.pl",`
                "*.prf","*.prg","*.printer","*.ps1","*.ps1xml","*.ps2","*.ps2xml","*.psc1","*.psc2","*.pst",`
                "*.reg","*.rem","*.scf","*.scr","*.sct","*.shb","*.shs","*.shtm","*.shtml","*.soap",`
                "*.stm","*.svc","*.url","*.vb","*.vbe","*.vbs","*.vsix","*.ws","*.wsc","*.wsf","*.wsh","*.xamlx");

Get-Childitem -r -path $path\* -include $extensitons | %{$_.fullname}

#Optionally push results to a text file
#Get-Childitem -r -path $path\* -include $extensions | %{$_.fullname} > C:\File_Extensions.txt

image

Powershell – SharePoint Deployment Standard Init Call

In a typical SharePoint deployment script, I would have the following part to make sure that all required ammunitions are there:

# Load SharePoint PS snap-in. # Nothing will occur if the Add-Type cmdlet tries to load an assembly multiple times, because .NET Framework assemblies only load once. Add-Type -AssemblyName "Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Function WriteLine { Write-Host -ForegroundColor White "--------------------------------------------------------------" } Function Confirm-LocalSession { If ($Host.Name -eq "ServerRemoteHost") {Return $false} Else {Return $true} } Function Load-SharePoint-PowerShell { If ((Get-PsSnapin |?{$_.Name -eq "Microsoft.SharePoint.PowerShell"})-eq $null) { WriteLine Write-Host -ForegroundColor White " - Loading SharePoint PowerShell Snapin..." # Added the line below to match what the SharePoint.ps1 file implements (normally called via the SharePoint Management Shell Start Menu shortcut) If (Confirm-LocalSession) {$Host.Runspace.ThreadOptions = "ReuseThread"} Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction Stop | Out-Null WriteLine } } Write-Host -ForegroundColor White " - Re-importing SP PowerShell Snapin to enable new cmdlets..." Remove-PSSnapin Microsoft.SharePoint.PowerShell Load-SharePoint-PowerShell

Double quote in PowerShell – backtick (`) & here-string approach

Favourite is to use the double quotation marks to create an expanding string. I then escape the required internal quotation marks by using the backtick (`) character, as shown here:

PS C:\> $c = "My name is `"$env:UserName`""
PS C:\> $c
My name is "ed"
PS C:\>

Another way to get double quotation marks into the string is to use a here-string. Just like regular strings, there are the literal and the expanding variety. The advantage of a here-string is that it ignores things such as quotation marks and other special characters. Essentially, what you type in a here-string is exactly what you get. But with the expanding variety of here-string, you also have the opportunity to bring in the value of variables. This is shown here:

PS C:\> $c = @"
>> My name is "$($env:UserName)"
>> "@
>>
PS C:\> $c
My name is "ed"
PS C:\>

Developer productivity–script to deploy an assembly quickly to Global Assembly Cache (GAC)

Very often we want to deploy the assembly to GAC and test our work, without having to follow a quick deployment process. here is a script which does the assembly deployment (uninstall the old one and install a new version).

$ProgamFiles_x86 = "$env:ProgramFiles (x86)"

#configure GacUtil environment
set-alias gacutil "$ProgamFiles_x86\Microsoft SDKs\Windows\v7.0A\bin\GacUtil.exe"

# un-install the old version of the assembly
Gacutil /u "DirectEnergy.OAM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b6a416a3e4d1c768"

# Install new version of the assembly
Gacutil /i "C:\mywork\scm\DirectEnergy.OAM\Development\R1\DirectEnergy.OAM\bin\Debug\DirectEnergy.OAM.dll"
Also, you could create a shortcut in your desktop with the following attribute:
Target: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe "C:\mywork\ps\DirectEnergy.OAM\Deploy-DE_OAM_DLL.ps1"
Start In: C:\Windows\System32\WindowsPowerShell\v1.0

PowerShell script to file browse, change file attribute, restore SharePoint site backup

Here is a nice little utility (written using PowerShell script) which I use to restore a site backup time to time.

Some features of this script are:

1. Displays a file browse dialog to select a file (see – Invoke-FileBrowser)

2. Removes the read-only attribute on the file (see – Remove-Readonly), this is required as the backup file is stored in TFS.

3. Restore a given backup file, without asking for confirmation (see – Restore-SPBackup)

——————————————————————————————————————————

$ErrorActionPreference = "Stop"

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0

# Example:
# $file = Invoke-FileBrowser -Title "Select a file" -Directory "D:\backups" -Filter "Powershell Scripts|(*.ps1)"
function Invoke-FileBrowser
{
      param([string]$Title,[string]$Directory,[string]$Filter="All Files (*.*)|*.*")
      [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
      $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog
      $FileBrowser.InitialDirectory = $Directory
      $FileBrowser.Filter = $Filter
      $FileBrowser.Title = $Title
      $Show = $FileBrowser.ShowDialog()
      If ($Show -eq "OK")
      {
            Return $FileBrowser.FileName
      }
      Else
      {
            Write-Error "Restore cancelled by user."
      }
}

# Example:
# Remove-Readonly -FilePath "D:\backups\filename.txt"
function Remove-Readonly
{
    param([string]$FilePath)
    #Remove read-only attribute, otherwise access denied error.
    Set-ItemProperty -Path $FilePath -name IsReadOnly -value $false
}

# Example:
# Restore-SPBackup -FilePath "D:\backups\backupfile.bak"
function Restore-SPBackup
{
    param([string]$BackupFilePath, [string]$WebUrl)
    #Restore the backup without asking for confirmation.
    Restore-SPSite -Identity $WebUrl -Path $BackupFilePath -Confirm:$false
}

$backupLocation = "C:\mywork\scm\JRCP.Internet\JRCP.Internet\JRCP Data Structures\Site Backups"
$SiteUrl = "http://sp2010riyaz:4040"

$file = Invoke-FileBrowser -Title "Browse" -Directory $backupLocation -Filter "All Files (*.*)|*.*"
Remove-Readonly -FilePath $file
Restore-SPBackup -BackupFilePath $file -WebUrl $SiteUrl
--------------------------------------------------------------------

Wait for more useful utilities…