Sunday, 3 January 2016

SharePoint and Powershell 3 step guide

Knowing little Powershell can make you feel very powerful in SharePoint. Below is a quick demo explaining 3 steps needed to run Powershell commands in SharePoint with ease.




Step 1:Find the Command(s) – Get-Command

Step 2:Get details of the Command(s) – Get-help

Step 3: Test the command with a Get operation and filter for a requirement to view data


Step 1:Get Command

žVerb-Noun format for Powershell commands
Possible žVerbs – Get,Set,New,Add,Remove
žNoun – All SharePoint commands Noun start with “SP”
žTo get all SharePoint commands:¡Get-command –Module “Microsoft.SharePoint.PowerShell”
žGet-Command *sp*,-verb,-noun
žExample you forget the name of the command to view log files,žType get-command *sp*log*
To iterate through the commands used TAB KEY

Step 2:get-help

Get-help [commandName]
žUpdate-help –force,žHelp about_*
žHelp [verb]*[searchterm]* –showwindow -detailed –examples –full –online
Note the parameters you need


Step 3:Test Command

žCommand -<ParameterName> <value1>.<value2>
žType any of the examples and test
žTAB through Parameters after – symbol
žTab through Paramater values
žView Members Get-Member
žFilter if needed -Where {$_.Parameter –like “”};Select param1,param2
žVariable assign (Eg)$wa = Get-SPWebApplication
žCurrent Variable $_;Foreach($w in $wa){$_.w.AlternateUrls}
žMeasure to get count of objects.Example, Get-SPWebApplication|Measure
žException Handling-Try{code}{ Write-Exception “Exception $_”}
To output Use Out-GridView;Export-csv;Format-list;Write-Host

The content has been pulled in after listening to creator of PowerShell and SharePoint Powershell gurus from Microsoft Virtual Academy site.

References:
žhttps://technet.microsoft.com/fr-fr/library/jj984298.aspx
žhttps://mva.microsoft.com/




No comments:

Post a Comment