{"id":17061,"date":"2010-09-20T00:01:00","date_gmt":"2010-09-20T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/09\/20\/get-started-managing-sharepoint-2010-with-powershell-cmdlets\/"},"modified":"2010-09-20T00:01:00","modified_gmt":"2010-09-20T00:01:00","slug":"get-started-managing-sharepoint-2010-with-powershell-cmdlets","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/get-started-managing-sharepoint-2010-with-powershell-cmdlets\/","title":{"rendered":"Get Started Managing SharePoint 2010 with PowerShell Cmdlets"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><strong>Summary<\/strong>: Scripting Guys guest blogger Niklas Goude shares essential how-to information about using the Windows PowerShell cmdlets to manage SharePoint 2010.<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Question\" border=\"0\" title=\"Hey, Scripting Guy! Question\" \/>Hey, Scripting Guy! I am interested in getting started with using Windows PowerShell cmdlets to manage SharePoint 2010. Do you have any words of wisdom?<\/p>\n<p>&#8212; GN<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Answer\" border=\"0\" title=\"Hey, Scripting Guy! Answer\" \/> Hello GN, <\/p>\n<p>Microsoft Scripting Guy Ed Wilson here. Yes I have words of wisdom: &ldquo;Ask the guy who wrote the book.&rdquo; We have Niklas Goude with us this week to share his wealth of knowledge. Niklas, we turn the blog over to you this week.<\/p>\n<p>Niklas Goude is a Windows PowerShell MVP working at Enfo Zipper in Stockholm, Sweden. Niklas has extensive experience in automating and implementing SharePoint environments using Windows PowerShell. He has written a Windows PowerShell book for Swedish IT pros, <a href=\"http:\/\/powershell.se\">powershell.se<\/a>, and is currently co-authoring a book with Mattias Karlsson titled, <i><a href=\"http:\/\/www.amazon.com\/PowerShell-Microsoft-SharePoint-2010-Administrators\/dp\/0071747974\">PowerShell for Microsoft SharePoint 2010 Administrators<\/a><\/i>, which will be published in English by McGraw-Hill in October 2010.&nbsp;Parts of this post are taken from Chapters 3 and 4 of that book.<\/p>\n<p>Niklas also runs the blog, <a href=\"http:\/\/powershell.nu\">powershell.nu<\/a>, where he shares scripts, examples, and solutions for administrative tasks in Windows environments through Windows PowerShell.<\/p>\n<p>&nbsp;<\/p>\n<h5>Getting Started<\/h5>\n<p>Windows SharePoint is one of the fastest growing Microsoft products in history, and it is quickly becoming mission critical for many companies around the world. Whereas SharePoint 2007 was a really cool product with an automation API, its use for automation purposes was a bit complicated for the average SharePoint administrator. This is where the inclusion of Windows PowerShell as a management tool for SharePoint 2010 comes in to play. <\/p>\n<p>In SharePoint 2010, you can start Windows PowerShell through the SharePoint 2010 Management Shell. The shell runs the SharePoint.ps1 script at startup and executes the following code:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #2b91af\">$ver<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$host<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">select<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">version<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$ver<\/span><span style=\"color: #000000\">.Version.Major<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">-gt<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">1<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #2b91af\">$Host<\/span><span style=\"color: #000000\">.Runspace.ThreadOptions<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;ReuseThread&#8221;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">Add-PsSnapin<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Microsoft.SharePoint.PowerShell<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">Set-location<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$home<\/span> <\/div>\n<\/blockquote>\n<p>The code in the preceding example stores the host&rsquo;s version in a variable, and if the major version is greater than one (if you are running Windows PowerShell 2.0), the <strong>ThreadOptions<\/strong> property is set to <strong>&ldquo;ReuseThread&rdquo;<\/strong>, which runs each line, function, or script on the same thread. When working with the SharePoint object model using Windows PowerShell, running code on separate threads can cause memory leaks, but commands running on the same thread have a smaller chance of doing so. This is not only because some SharePoint objects still use unmanaged code, but also the way memory is allocated to those objects. Next, the SharePoint snap-in is loaded (Microsoft .NET Framework assemblies that may contain custom Windows PowerShell cmdlets).<\/p>\n<h5>The SharePoint 2010 Cmdlets<\/h5>\n<p>The SharePoint 2010 snap-in for Windows PowerShell contains more than 500 cmdlets that you can use to perform a large variety of administrative tasks. Let&rsquo;s see how we can list all the SharePoint cmdlets using the <strong>Get-Command<\/strong> cmdlet. <strong>Get-Command<\/strong> returns basic information about cmdlets and other elements of Windows PowerShell commands, such as functions, aliases, filters, scripts, and applications. All nouns of the SharePoint 2010 cmdlets start with <strong>SP<\/strong>. Knowing this, we can use the &ndash;noun parameter of the Get-Command cmdlet followed by <strong>SP*<\/strong>:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">Get-Command<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-noun<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">SP<\/span><span style=\"color: #000000\">*<\/span> <\/div>\n<\/blockquote>\n<p>The results of this command are shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3678.HSG09201001_3DC3C8C3.jpg\"><img decoding=\"async\" height=\"279\" width=\"554\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5734.HSG09201001_thumb_634D4624.jpg\" alt=\"Image of results of this command\" border=\"0\" title=\"Image of results of this command\" style=\"border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" \/><\/a><\/p>\n<p>The list of cmdlets returned is pretty long. You can also use <strong>Get-Command<\/strong> to find specific SharePoint 2010 cmdlets. For example, if you want to find all cmdlets that are used to manage site collections, you can simply type:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">Get-Command<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Noun<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">SPSite<\/span> <\/div>\n<\/blockquote>\n<p>This will produce the following results: <\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #000000\">CommandType<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Name<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Definition<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">&#8212;&#8212;&#8211;<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">&#8212;&#8212;&#8212;&#8212;<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">Cmdlet<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Backup-SPSite<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Backup-SPSite<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[-Identity]<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&lt;SPSitePip<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">Cmdlet<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Get-SPSite<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Get-SPSite<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[-Limit<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&lt;String&gt;]<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[-WebAp<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">Cmdlet<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Move-SPSite<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Move-SPSite<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[-Identity]<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&lt;SPSitePipeB<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">Cmdlet<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">New-SPSite<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">New-SPSite<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[-Url]<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&lt;String&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[-Languag<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">Cmdlet<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Remove-SPSite<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Remove-SPSite<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[-Identity]<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&lt;SPSitePip<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">Cmdlet<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Restore-SPSite<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Restore-SPSite<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[-Identity]<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&lt;String&gt;<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">Cmdlet<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Set-SPSite<\/span><span style=\"color: #808080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Set-SPSite<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[-Identity]<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&lt;SPSitePipeBi<\/span><span style=\"color: #808080\"> <br \/><\/span><\/div>\n<\/blockquote>\n<h5>Working with SharePoint 2010 Cmdlets<\/h5>\n<p>Let&rsquo;s see what we can do with the <strong>Get-SPSite<\/strong> cmdlet. Typing the cmdlet in Windows PowerShell returns the site collections available:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Get-SPSite<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">Url<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">&#8212;<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">http:\/\/spserver<\/span> <\/div>\n<\/blockquote>\n<p>Notice how the command returns the site collections <strong>URL<\/strong> property, although the returned objects have a lot more properties. The properties displayed by default are controlled by a set of formatting files. Windows PowerShell includes 10 formatting files, and SharePoint 2010 comes with 13 additional formatting files that are used to generate a default display of various .NET Framework objects.<\/p>\n<p>We can display additional properties using the <strong>Select-Object<\/strong> cmdlet. In the example below, we use the <strong>&ndash;Identity<\/strong> parameter supported by the <strong>Get-SPSite<\/strong> cmdlet to retrieve a specific site collection and pipe the object to the <strong>Select-Object<\/strong> cmdlet:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Get-SPSite<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Identity<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">http:\/\/SPServer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">Select-Object<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Property<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Url,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Zone,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Port<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">Url<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Zone<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Port<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">&#8212;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&#8212;-<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&#8212;-<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">http:\/\/spserver<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Default<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">80<\/span> <\/div>\n<\/blockquote>\n<p>It&rsquo;s also possible to change specific properties of a site collection. First let&rsquo;s see how to we can add a secondary contact to the site collection using the <strong>Set-SPSite<\/strong> cmdlet:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Get-SPSite<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Identity<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">http:\/\/SPServer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #000000\">&gt;&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Set-SPSite<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-SecondaryOwnerAlias<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">domain\\user<\/span> <\/div>\n<\/blockquote>\n<p>If we use the <strong>Select-Object<\/strong> cmdlet again and display the <strong>SecondaryContact<\/strong> property, we&rsquo;ll see that a secondary contact is added to the site collection:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Get-SPSite<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Identity<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">http:\/\/SPServer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">Select<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">SecondaryContact<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">SecondaryContact<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">&#8212;&#8212;&#8212;&#8212;&#8212;-<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #000000\">Domain\\user<\/span> <\/div>\n<\/blockquote>\n<p>You can also store an object of the type <strong>SPSite<\/strong> in a variable and set the <strong>SecondaryContact<\/strong> property. The property requires an object of the type <strong>Microsoft.SharePoint.SPUser<\/strong>, which is just the type of object that the <strong>Get-SPUser<\/strong> cmdlet returns. Note that the user has to exist in the site collection:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$spSite<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Get-SPSite<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Identity<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">http:\/\/SPServer<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$spSite<\/span><span style=\"color: #000000\">.SecondaryContact<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #000000\">&gt;&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">(Get-SPUser<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Web<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">http:\/\/SPServer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Identity<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">domain\\user)<\/span> <\/div>\n<\/blockquote>\n<p>What if you want to add a user that exists in Active Directory but does not exist in the site collection? Simply use the <strong>New-SPUser<\/strong> cmdlet to add a user to a site collection and then add the object to the <strong>SecondaryContact<\/strong> property:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$spUser<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">New-SPUser<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Web<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">http:\/\/SPServer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-UserAlias<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">domain\\newuser<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$spSite<\/span><span style=\"color: #000000\">.SecondaryContact<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$spUser<\/span> <\/div>\n<\/blockquote>\n<p>When we are done with the object stored in the <strong>$spSite<\/strong> variable, it&rsquo;s important to dispose of it correctly. One way of doing this is by calling the <strong>Dispose()<\/strong> method:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$spSite<\/span><span style=\"color: #000000\">.Dispose()<\/span> <\/div>\n<\/blockquote>\n<p>Why do we have to dispose of the object? Well, <strong>SPWeb<\/strong>, <strong>SPSite<\/strong>, and <strong>SPSiteAdministration<\/strong> objects can sometimes take up large amounts of memory, so using any of these objects in Windows PowerShell requires proper memory management. Normally, instances of these objects obtained through cmdlets such as <strong>Get-SPSite<\/strong> are disposed of automatically at the end of the pipeline, but this does not happen to instances stored in variables. You can dispose of objects using the <strong>Dispose()<\/strong> method as demonstrated in the preceding example, or you can use the <strong>Start-SPAssignment<\/strong> and <strong>Stop-SPAssignment<\/strong> cmdlets that were introduced in SharePoint 2010 to spare scripters the need to dispose of such objects individually.<\/p>\n<h4><span style=\"font-size: x-small\"><span style=\"font-size: x-small\">Summary<\/span><\/span><\/h4>\n<p>In this post, we have seen examples about how to find and work with the SharePoint 2010 cmdlets. There is, of course, a lot more cool stuff that you can do when using Windows PowerShell to automate your SharePoint 2010 environment, such as managing content databases, web applications, and sites. We also took a brief look at how we can work with site collections in SharePoint 2010 with examples about retrieving and modifying site collections. It&rsquo;s also possible to create new site collections, back up and restore site collections, and move and remove site collections.<\/p>\n<p>GN, that is all there is to getting started with SharePoint 2010 and Windows PowerShell. Guest Blogger Week with Niklas Goude will continue tomorrow.<\/p>\n<p>We would love for you to follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to us at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Summary: Scripting Guys guest blogger Niklas Goude shares essential how-to information about using the Windows PowerShell cmdlets to manage SharePoint 2010. &nbsp; Hey, Scripting Guy! I am interested in getting started with using Windows PowerShell cmdlets to manage SharePoint 2010. Do you have any words of wisdom? &#8212; GN &nbsp; Hello GN, Microsoft Scripting [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[56,183,3,59,45],"class_list":["post-17061","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-niklas-goude","tag-scripting-guy","tag-sharepoint","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>&nbsp; Summary: Scripting Guys guest blogger Niklas Goude shares essential how-to information about using the Windows PowerShell cmdlets to manage SharePoint 2010. &nbsp; Hey, Scripting Guy! I am interested in getting started with using Windows PowerShell cmdlets to manage SharePoint 2010. Do you have any words of wisdom? &#8212; GN &nbsp; Hello GN, Microsoft Scripting [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/17061","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=17061"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/17061\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=17061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=17061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=17061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}