Documents
Resources
Learning Center
Upload
Plans & pricing Sign in
Sign Out

Intro to PowerShell

VIEWS: 8 PAGES: 24

  • pg 1
									Intro to PowerShell



                   Adam Preston
                Senior Consultant
               December 4th, 2010
                Who is this guy?

Adam Preston – Senior Consultant (TCSC)
Born in Richmond, VA
Certified:
–   MCITP: SharePoint 2010, Administrator
–   MCTS: SharePoint 2010, Configuration
–   MCTS: Microsoft Office SharePoint Server 2007, Configuration
–   MCTS: Microsoft Windows SharePoint Services 3.0,
    Configuration
Contact Information:
– Email: dap@tcsc.com
– Twitter: @_apreston
– Blog: http://www.tcscblog.com
The Computer Solution Company (TCSC)

Founded in 1981
Based in Richmond, VA
Consulting Services and Software Product Development
Consulting Services has been specializing in SharePoint
services for over 6 years (since v1)
Consistently recognized for quality of technical services
– Microsoft Worldwide Partner Conference Technology Innovation
  Award Finalist
– Microsoft Mid-Atlantic Teamwork Award
– Microsoft Mid-Atlantic Loyalty Award
– Infineon Technologies’ Technology Innovation Award
Providing Microsoft-centric consulting, application
development and work management solutions
                    Agenda

What is PowerShell?
Where do I find it?
What are the benefits of PowerShell?
Wait, what happened to STSADM?
What commands will get me started?
Who has permission to SharePoint 2010 w/PowerShell?
Demos, Demos, and Demos!
References
Questions
                       PowerShell

Windows PowerShell is
Microsoft's task automation
framework, consisting of a
command-line shell and
associated scripting language built
on top of, and integrated with the
.NET Framework.
PowerShell provides full access to
COM and WMI, enabling
administrators to perform
administrative tasks on both local
and remote Windows systems.
DOS on Steroids!
A modern replacement for the
DOS command-line shell
                                  PowerShell

PowerShell 2.0 is built into
Windows 7 and Windows Server
2008 R2
For older OS’s, need to download
Windows Management
Framework to get PS 2.0
Start > Accessories > Windows
PowerShell
SharePoint 2010 Management
Shell
 –   Simply a shortcut to a profile that loads the
     SP2010 Provider Snapin
                              STSADM?

Still there and still works
 – Remains for backwards compatibility
 – Allows for portability of existing STSADM batch files and scripts
 – Some commands have been removed (ex. all SSP related commands)
Don’t use this as a crutch! You should start to do everything in PowerShell.
Remember that it’s the “14 Hive” now
 – C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN
PowerShell > STSADM
 – Newly created cmdlets were developed for enhanced performance
 – PowerShell has full access to the SharePoint API from the command line
STSADM to Windows PowerShell Mapping:
 – http://technet.microsoft.com/en-us/library/ff621081.aspx
                   PowerShell ISE

Windows PowerShell Integrated
Scripting Environment (ISE)
Host application for PS
Can run commands, write, test,
and debug scripts
Uses color-coding
Only available with PS 2.0
Server Manager > Add Features >
Windows PowerShell ISE
Needs to be installed in order to
use Out-GridView
               Benefits of PowerShell

Interact with .NET objects directly
Remoting interface
 – SharePoint PowerShell Remoting Requirements
 – SharePoint Remoting with PowerShell 2.0
Reduction in the need of some 3rd party solutions
Perform administrative functions in bulk, reducing time and effort.
 – Will show an example of this in a later demo
Some SharePoint 2010 functions require the use of PowerShell:
 – Resetting the Farm Passphrase
      •   How to Reset the Farm Passphrase in SharePoint 2010
 – Configuring the State Service Application
 – Configuring the Publishing Feature’s Super User Accounts
Performance benefits for batch operations
                          Get-Command

Used to find all the commands
available to PowerShell
Cmdlets generally have a verb-
noun naming convention
 –   Get-ChildItem, Get-Member, Add-
     SPSolution, Backup-SPFarm, Export-SPWeb
Get-Command -noun *infopath*
Get-Command -noun *solution*
List all available SP2010 cmdlets:
 –   Get-Command -PSSnapin
     “Microsoft.SharePoint.PowerShell”
                                         Get-Help

Used to show Synopsis, Syntax,
Description, Parameters, and
Examples
Several ways to get help information
on cmdlets:
 –   Get-Help <cmdlet>
       •   Get-Help Get-SPSite -full
       •   Get-Help Get-SPSite -examples
       •   Get-Help Get-SPSite –detailed
       •   Get-Help *-SPSite
 –   <cmdlet> -?
 –   Help <name>
       •   Ex. Help database, Help Get-SPSite, etc.
Paging
 –   Some results will only show a subset
     ending with “-- More --”
 –   <ENTER> = show next line or row
 –   <SPACE> = show next page or subset
 –   Can create paging by piping results to
     “more”
       •   Get-SPSite | more
           Aliases and Get-Member

Aliases
 –   A way of calling a command using a
     keyword or abbreviation
 –   Most cmdlets have an associated alias to
     allow for shortcutting
       •   Get-Command = gcm
       •   Format-List = fl
       •   Set-Location = cd
       •   Get-ChildItem = dir
 –   Use Get-Alias to get a list of aliases
     available for your current session
 –   Use Set-Alias to create your own!
Get-Member
 –   Gets the properties and methods of objects
       •   Get-SPSite | Get-Member
 –   Useful for when trying to determine what
     property you want to output
Navigating PowerShell




      Demo
Pipeline, Select, Where, and Sorting

Pipeline
 –   Allows output of one cmdlet to be the input of another cmdlet
 –   Examples
       •   Get-Process | Format-Table Name, CPU
       •   Get-SPWebApplication | Get-SPSite | Get-SPWeb

Select-Object
 –   Allows you to pick available properties instead of grabbing all properties
 –   Get-SPSite | Get-SPWeb | Select URL, WebTemplate, LastItemModifiedDate
Where-Object
 –   Only display results which meet a certain condition
 –   Get-SPLogEvent -StartTime (Get-Date).AddMinutes(-5) | Where-Object {$_.Level -eq “High”}
Sort-Object
 –   Sort the result set by one or more property
       •   Get-SPSite | Sort Owner, URL
 –   Sort ascending (default) or descending
       •   Get-SPSite | Select URL, Owner, LastContentModifiedDate | Sort LastContentModifiedDate -Descending
                     Ways to Output

Write-Host
 – Outputs to PowerShell session
   window
Write-Warning
Write-Error
Write-EventLog
Out-File
 – Outputs to provided path
   location
 – Can use “>” as alias
Out-GridView
 – Requires PS ISE
Out-Printer
 – Sends to default printer
Export-CSV
Export-XML
                           Formatting

Get-Command Format-*
Format-List
– Results are:
     • Property1: Result
     • Property2: Result
     • Property3: Result

Format-Table
– Results are:
     • Property1           Property2   Property3
     • Result              Result      Result

Format-Wide
– Only displays one property and puts it into multiple columns
Result Filtering, Output, and Formatting




              Demo
PowerShell Providers and Scripting

 Most Microsoft products expose their management interface through providers
  –   Windows, SharePoint, Exchange, IIS, SQL, Forefront, etc.
  –   IIS Example:
        •   Import-Module WebAdministration
        •   Set-ItemProperty ‘IIS:\Sites\SharePoint – 80’ -Name LogFile.directory -Value ‘C:\Logs\IIS’
  –   Windows Example:
        •   New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa\MSV1_0 -Name
            “BackConnectionHostNames” -Value “intranet.contoso.com”,”mysites.contoso.com” -PropertyType multistring

 This means that you could have your script or command interact with multiple
 applications at once.
 Scripting
  –   PowerShell allows for complex scripting, which include functions, loops, parameters, branching, and
      much more!
  –   Scripts are saved using the .PS1 file extension
  –   Restricted by default, can change using Set-ExecutionPolicy
  –   Best Practice is to have your scripts signed, don’t leave your environment in an unrestricted state
SP2010 PowerShell Permissions

Out-of-the-box only the Farm Account has permission to interact with
SharePoint 2010 via PowerShell. This does not include additional Farm
Administrators.
Get-SPShellAdmin
 –   Lists who has rights to run PowerShell commands against the databases
Add-SPShellAdmin
 –   Must be local admin, db_owner, and securityadmin to run this command properly
 –   User is added to WSS_Admin_WPG group on all WFEs and is added to the SharePoint_Shell_Access
     role on the database you specified
 –   Add-SPShellAdmin -username tcsc\dap -database Portal_Content_DB
       •   If the database switch is not used, then the user is added access to the configuration database

Remove-SPShellAdmin
 –   Remove-SPShellAdmin -username tcsc\dap
Be Careful!
Permissions and SP2010 Commands




           Demo
 Bing Visual Search




Search Bing for “PowerShell”, click top tab “Visual Search”
                           References

Windows PowerShell for SP2010 Resource Center
Windows PowerShell for SP2010 References
TechNet Script Center Repository
Getting Started with Windows PowerShell for SharePoint Administrators
PowerShell Videos on Channel9
Gary Lapointe’s Custom SharePoint 2010 PowerShell Cmdlets and STSADM
Commands
Mastering PowerShell (Free eBook - Over 560 Pages!)
PowerShell Book(s)
 – PowerShell for Microsoft SharePoint 2010 Administrators
 – Windows PowerShell 2.0 Administrator’s Pocket Consultant
    TCSC Office 2010 Giveaway

TCSC is giving away copies of Microsoft Office 2010
Professional Plus
3 Ways To Win (One copy max per person overall)
1. Visit the new TCSC Blog www.tcscblog.com
     Make a comment on the SharePoint Saturday post with the words
      “SharePoint Saturday Rocks” in it
2. Follow @TCSC on Twitter
     Tweet “Rocking out with @TCSC at #SharePoint Saturday Richmond
      #spsric”
3. Visit our booth and provide us your business card
Questions?

								
To top