2. What we’re barking about
What is PowerShell?
PowerShell and SharePoint – the evolution
Scripts vs. code – comparison
Business case walk through
Code integration with PowerShell
Architectural discussions
#DogFoodCon
3. Meet the Mutts
Ryan Dennis
Ricardo Wilkins
Consultant, Blue Chip Consulting Group Consultant, Blue Chip Consulting Group
#DogFoodCon
5. What is PowerShell?
…is a task-based command-line shell and
scripting language designed especially for
Windows system administration
…has a task-based scripting language
…includes powerful object manipulation
capabilities
…is built on the .NET Framework
#DogFoodCon
6. PowerShell deals with Objects,
not Strings
• In order to find out what you can and cannot do or
see on an object, use the Get-Member cmdlet
• Get-Member will return all Methods and Properties
associated with whatever item you pass to it
• PowerShell uses a Verb-Noun syntax for its Cmdlets
• Get-Something
• Set-Something
• New-Something
#DogFoodCon
7. The Pipeline
• PowerShell passes objects, that is – when you do
something like Get-Process, you’re retrieving process
object(s) – you can then pipe that output, or that
process object to Stop-Process, Select-Object, WhereObject, etc.
• Use the built-in $_ variable to get values from the
current object in the pipeline…
• Let’s talk about this metaphorically…
#DogFoodCon
9. SharePoint 2010 Cmdlets
• 500+ Cmdlets…
• MUCH better than STSADM.exe…
• Can automate complete installations and
configurations…
• Still doesn’t answer every scenario, leaving
gaps in functionality…
• Example: Get, New and Remove SharePoint Groups –
no cmdlet, easy to write a custom function though…
#DogFoodCon
10. As a Developer, why do I
care?
• Not always necessary to write code
• Use PowerShell to handle things you could
do in C#
• Don’t write console apps, write PowerShell
Scripts!
• Some clients don’t allow managed code
deployments, but PowerShell is A-OK
#DogFoodCon
12. Retrieving SharePoint Objects
• Multiple ways to get a Site Object using
PowerShell…
• $Site = Get-SPSite
• $Site = New-Object Microsoft.SharePoint.SPSite($Url)
• Multiple ways to get a Web Object using
PowerShell…
• $Web = $Site.RootWeb
• $Web = $Site.OpenWeb()
• $Web = Get-SPWeb
#DogFoodCon
13. The Evolution of SP Scripting
• About 200 cmds
• Over 500
• Over 700
• No native support
PowerShell cmdlets
PowerShell cmdlets
for PowerShell*
• PowerShell Version • PowerShell Version
• STSADM was it
2.0
3.0
#DogFoodCon
*You could use PowerShell by loading the Microsoft.SharePoint Assembly…
14. Pros & Cons of Script vs.
Code
Script Pros
Quicker to write
Easier to edit (open a file,
edit it)
No need to install a DLL to
the server
Can access the hundreds
(thousands?) of other
PowerShell cmdlets
(Processes, Services, etc.)
#DogFoodCon
Code Cons
Requires more time to
develop& deploy
Editing requires
redeployment to server
Requires a DLL
installation
15. C# vs. PowerShell
// register controls
protected TextBox TextBoxMinutesPerSession;
protected LinkButton LinkButtonUpdate;
// Create a click event handler
LinkButtonUpdate.Click
+= new EventHandler(LinkButtonUpdate_Click);
void LinkButtonUpdate_Click(object sender, EventArgs e)
Both code snippets add or set the
{
// Grab the site and web Guid
“CurrentUserSessionDuration”
Guid sitedId = SPContext.Current.Site.ID;
property in a Web.
Guid webID = SPContext.Current.Web.ID;
//create and dispose of spweb and spsite objects
using (SPSite oSPSite = new SPSite(sitedId))
{
using (SPWeb oWeb = oSPSite.OpenWeb(webID))
{
//Set the custom web property to the textbox
value
oWeb.Properties["CurrentUserSessionDuration"]
= TextBoxMinutesPerSession.Text;
oWeb.Properties.Update();
}
$web = Get-SPWeb http://url
}
$web.Properties["CurrentUserSessionDuration"] = "60"
}
$web.Properties.Update()
$web.Dispose()
#DogFoodCon
23. -Files reside in e.g. C:Scripts
-Scripts calling scripts as functions
-Storing scripts in source control (TFS)
-BA/PM viewing scripts vs code
#DogFoodCon
26. Why is this worth chewing on?
Separation of Devs vs Ops
Devs maintain the UI
Ops maintains the Title Change process
Separation of Concerns / Single
Responsibility pattern
#DogFoodCon
27. Other things to chew on?
PS in Office 365
PS in Azure
PS Remoting
PS Workflow
#DogFoodCon
28. Barks from the Pack
Thoughts?
Would this model work for you?
Other ideas?
#DogFoodCon