Monday, August 5, 2013

SharePoint PowerShell basic tips or help

Here are some of the tips in PowerShell were you can use PowerShell with more efficient way.

PowerShell Intellisece :
Power will also provide intellisece like all the other micrsoft devlopment tools by using some of the external tools PowerGUI is one of them.

In Windows 8 this is inbuilt functionality no need to do any integration for this.

PowerShell to text file :
Powershell file will also all the resulted output to a local text file same like other tools. Here is the small example on how to do this.

Get-SPContentDatabase >"C:\Files\output.xml"

PowerShell to Gridview output : 
This is the other addition from PowerShell where you can get the result in Output gridview with filtering and search option. Her is the sample code to run this.
Get-SPContentDatabase | Out-GridView

Personally i am a big fan of this feature.

PowerShell help :
Here is the sample to get the help for any command in Powershell with example.
get-Help Get-SPContentDatabase -example 

Read inputs for PowerShell script file :
Scenario :
You have created a script file with a function named AddIntegers(). this function will take inputs from the input file in the script file location. This file placed in folder "D:\SourceCode\PowerShell\Test.ps1"
Input file is also placed in the same location.
Issue :
Usually PS script file will be executed from "C:\users\{Login account name}".
If you try to load the ps1 file by providing the location you will get an exception saying that the input file cannot be found in the "C:\users\{accountname}" location.
Solution :
First you need to traverse to the ps1 script file location in my case i need to traverse to "D:\SourceCode\PowerShell\Test.ps1" location then i can call ps1 file this time it should work without any errors.

Multiple PowerShell: 
We have multple PowerShell available for any 64 bit operating systems we have 2 PowerShell files available.one is for 32 bit and other is for 64 bit.
But interestingly, for both 64 bit or 32 bit operating systems by default PowerShell will locd from 32 bit setup file only.
Below are the paths for both the versions you can verify.
32 bit : C:\Windows\System32\WindowsPowerShell\v1.0
64 bit : C:\Windows\SysWOW64\WindowsPowerShell\v1.0
SharePoint PowerShell will be loaded from 32 bit only with the SP snap in PS file from C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration location.

Here are some of tips and i will keep update on this post further...



No comments:

Post a Comment