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

BAT SCRIPT TO OPEN SQL SERVER PORTS IN THE FIREWALL

rem ******************code start******************************
 
@echo off 
sc config MpsSvc start= demand 
sc start MpsSvc
 
echo. *** OPENING SQL SERVER PORTS IN THE FIREWALL *** 
echo. source Mohamed Riyaz.
echo. 
echo. Note for Named Instances – SQL mirroring – Dynamic Ports and the firewall 
echo. see http://msdn.microsoft.com/en-us/library/cc646023(v=SQL.100).aspx#BKMK_programs 
echo. You will need to open firewall ports for your mirroring endpoints and possibly dynamic ports 
echo. 
echo. 
echo. Opening SQL Server TCP 1433 
netsh advfirewall firewall add rule name=”SQL Server (TCP 1432)” dir=in action=allow protocol=TCP localport=1433 profile=domain 
echo. 
echo. Opening SQL Admin Connection TCP 1434 
netsh advfirewall firewall add rule name=”SQL Admin Connection (TCP 1434)” dir=in action=allow protocol=TCP localport=1434 profile=domain 
echo. 
echo. Opening SQL Service Broker TCP 4022 
netsh advfirewall firewall add rule name=”SQL Service Broker (TCP 4022)” dir=in action=allow protocol=TCP localport=4022 profile=domain 
echo. 
echo. Port 135 
netsh advfirewall firewall add rule name=”SQL Debugger/RPC (TCP 135)” dir=in action=allow protocol=TCP localport=135 profile=domain 
echo. 
echo. Opening SQL Browser UDP 1434 
netsh advfirewall firewall add rule name=”SQL Browser (UDP 1434)” dir=in action=allow protocol=UDP localport=1434 profile=domain 
echo. 
echo. Opening Analysis Services TCP 2383 
netsh advfirewall firewall add rule name=”Analysis Services (TCP 2383)” dir=in action=allow protocol=TCP localport=2383 profile=domain 
echo. 
echo. Opening SQL Browser TCP 2382 
netsh advfirewall firewall add rule name=”SQL Browser (TCP 2382)” dir=in action=allow protocol=TCP localport=2382 profile=domain 
echo. 
echo. ***Done ***
 
sc stop MpsSvc 
sc config MpsSvc start= disabled
 
rem ******************code end******************************

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