AutomatingSharePointTasksWithPowerShell
Download
Report
Transcript AutomatingSharePointTasksWithPowerShell
Automating SharePoint Tasks with
PowerShell
Rick Toner MCSD, MCPD, MCITP
[email protected]
Blog: http://www.getsharepoint.com/blog
Prior Version of SharePoint
Stsadm and PsConfig
Command line driven text results only
SharePoint 2010+
Welcome to Automation!
PowerShell + SharePoint = time savings and
validation!
What is Windows PowerShell?
Dynamic scripting language
Next generation commandline/scripting
environment from Microsoft.
General purpose programming language
What can it do?
Automate complex, repetitive tasks
Build command line utilities
.NET Interactive Prompt
Windows Server management
SharePoint 2010+
IIS 7.0+
Getting Started
How do I get it?
If you're using Windows 7 or Windows Server 2008 R2,
you have nothing to do - it's already there.
All other versions can download it at
http://support.microsoft.com/kb/968929
Some gotchas!
Adjust PowerShell to allow script execution.
PS> Set-ExecutionPolicy Unrestricted
What if it just won't run?
http://technet.microsoft.com/en-
us/library/ee176949.aspx
Cmdlets
Standardized naming scheme for cmdlets
<Verb>-<Noun> where the verb specifies the
action and the noun specifies the object to
operate on.
Examples
Get-Help, Remove-Item
Scripting Language: Variables
Variables are always prefixed with $ except:
gps -OutVariable Procs –ErrorVariable Err
Set-Variable FirstName 'John'
Can be loosely or strongly typed:
$a = 5
$a = "hi"
[int]$b = 5
$b = "hi" # Errors since $b is type int
$c = [int]"7" # Coerce string to int
Automatic variables
$null, $true, $false, $error, $?, $LastExitCode, $OFS,
$MyInvocation
Scripting Language: Variables
Type of Operation
Operators
Arithmetic: Numeric
+ - * / () %
Arithmetic: String
+ to concatenate, * to repeat "-" * 72, -f formatting
Assignment
= += -= *= /= %= ++ --
Negation
! -not
Comparison: General
-eq -lt -gt -le -ge -ne -and -or
Comparison: String
-ceq -clt -cgt -cle -cge -cne -like –notlike
-match -notmatch -clike -cnotlike -cmatch -cnotmatch
String Manipulation
-replace
Array
-contains -ccontains
Bitwise
-band -bor -bnot
Type test/conversion
-is -isnot -as
“c” indicates case
sensitive
Remember: Many operators start
with hyphens
A better way to script!
PowerGUI Script Editor
Debugging
Variable watch (local window)
Superior scripting UI
Intellisense (Auto complete)
Snippets
Commenting out blocks
Other demo scripts
and tools!
Any good resources?
First and foremost in PowerShell; of course!
PS> Get-Help (Any command)
PS> Get-Help about_Windows_PowerShell_2.0
Resources continued
Name
URL
MSDN PS Blog
blogs.msdn.com/powershell
Technet SP PS Blog
technet.microsoft.com/enus/sharepoint/ee518673
Get-PSScripts
get-spscripts.com
PowerShell Code Repository
poshcode.org
PowerShell Scripts, Tips
powershell.com
Resources continued
Name
URL
PowerGUI
powergui.org
Free Powershell Books
Effective Windows PowerShell
keithhill.spaces.live.com/blog/cns!5A8D2641E0
963A97!6930.entry
Master-PowerShell
powershell.com/cs/blogs/ebook
SharePoint PowerShell Books
A++ Book!
Automating SharePoint
2010 with Windows
PowerShell 2.0
http://www.wiley.com/Wil
eyCDA/WileyTitle/product
Cd-0470939206.html
Books continued
PowerShell for Microsoft
SharePoint 2010
Administrators
http://www.mhprofessional.c
om/product.php?isbn=007174
7974
PowerShell for SharePoint
2010 How-To
http://www.informit.com/stor
e/product.aspx?isbn=0672335
59X
Questions?
Rick’s blog - http://www.getsharepoint.com/blog
email: [email protected]
Twitter ID: rtonerii
Western Carolina SharePoint Users Group
Arden, March 8th, 2012
http://www.GetSharePoint.com