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*
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
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