<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PowerShell.nu &#187; Sharepoint</title>
	<atom:link href="http://www.powershell.nu/category/sharepoint/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.powershell.nu</link>
	<description></description>
	<lastBuildDate>Wed, 14 Jul 2010 22:17:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Australian &amp; New Zealand SharePoint Conference</title>
		<link>http://www.powershell.nu/2010/06/17/australian-new-zealand-sharepoint-conference/</link>
		<comments>http://www.powershell.nu/2010/06/17/australian-new-zealand-sharepoint-conference/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 05:47:17 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[SharePoint 2010]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Sessions]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=1012</guid>
		<description><![CDATA[I just finished my Australian/New Zealand SharePoint &#38; PowerShell tour with Mattias Karlsson where we had the honor to speak at both the New Zealand and the Australian SharePoint conference. In our session SharePoint 2010 and PowerShell – In real life we showed a couple of demos and promised to share them on this site. [...]]]></description>
			<content:encoded><![CDATA[<p>I just finished my Australian/New Zealand SharePoint &amp; PowerShell tour with Mattias Karlsson where we had the honor to speak at both the New Zealand and the Australian SharePoint conference. In our session SharePoint 2010 and PowerShell – In real life we showed a couple of demos and promised to share them on this site. So here they are.</p>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2010/06/DemoCode.zip">Click here to download the scripts</a></p>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2010/06/PowerShell-Presentation.ppt">Click here to download the PowerPoint presentation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2010/06/17/australian-new-zealand-sharepoint-conference/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MOSS 2007 Script Collection</title>
		<link>http://www.powershell.nu/2009/09/08/moss-2007-script-collection/</link>
		<comments>http://www.powershell.nu/2009/09/08/moss-2007-script-collection/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 16:54:14 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[MOSS]]></category>
		<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=857</guid>
		<description><![CDATA[I&#8217;ve been working with SharePoint and PowerShell for quite some time now and I would like to share a couple of Scripts that I use when scripting MOSS. Actually, it&#8217;s 44 Scripts, Loads of Coffee and alot of long nights so I hope you enjoy them. There are Links at the bottom of the Post [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working with SharePoint and PowerShell for quite some time now and I would like to share a couple of Scripts that I use when scripting MOSS. Actually, it&#8217;s 44 Scripts, Loads of Coffee and alot of long nights <img src='http://www.powershell.nu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  so I hope you enjoy them. There are Links at the bottom of the Post where you can Download all the scripts, or you can Download all scripts from the link below.</p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss-script-collection.zip">moss-script-collection.zip</a></p>
<p>Down to business then. I&#8217;ll put up a scenario based on the Session that I used at the SharePoint UserGroup meeting in Stockholm Sweden, explaining all Steps and how to use the Scripts.</p>
<p>First I set up a Folder where I keep all my scripts, I use C:\Scripts. Then I add the folder to the Windows Path.</p>
<pre><strong>
PS &gt; $env:path = $env:path + ";c:\scripts"
</strong></pre>
<p> </p>
<p>Adding the Script folder to the Environment Path let&#8217;s Us Call the script simply by typing it&#8217;s name. so instead of typing:</p>
<pre><strong>
PS &gt; .\Get-SPSite.ps1 -url http://moss
</strong></pre>
<p> </p>
<p>We can Type:</p>
<pre><strong>
PS &gt; Get-SPSite -url http://moss
</strong></pre>
<p> </p>
<p>Note, Don&#8217;t forget to set the Execution-Policy, otherwise, the scripts won&#8217;t run. <a href="http://www.microsoft.com/technet/scriptcenter/topics/winpsh/manual/run.mspx">Read more about it here</a></p>
<pre><strong>
PS &gt; Set-ExecutionPolicy RemoteSigned
</strong></pre>
<p> </p>
<p>All Scripts include a help text that explains how to use the Script. To access the helptext simply type the Script Name followed by -help.</p>
<pre><strong>
PS &gt; Get-SPSite -help
</strong></pre>
<p> </p>
<p>Now We can start Scripting MOSS!</p>
<h2>Loading SharePoint Assemblies</h2>
<p> </p>
<p>The first thing we have to do in order to Access the MOSS 2007 Assemblies is Loading them into PowerShell. Even though they Exist in our Windows Environment, PowerShell isn&#8217;t aware of them. By Loading them into our Global Assembly Cache, PowerShell can access and use the MOSS 2007 .NET Classes.</p>
<pre><strong>
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
</strong></pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Get-SPSite.ps1">Get-SPSite.ps1</a></h2>
<p> </p>
<p>First, We&#8217;ll Check out the Site Collection. Here&#8217;s how we can add our Site Collection to a variable using the Get-SPSite.ps1 script and retrieve information from it. When working with SPSite or OpenWeb objects in the PowerShell console you have to dispose of the object on the same row as the command, otherwise they will leak memory. This only applies when you create SharePoint objects directly in the PowerShell console. When run in functions and scripts, the commands are run in a single thread. <a href="http://blogs.msdn.com/sharepoint/archive/2009/02/11/sharepoint-and-powershell-knowledge.aspx">for more information click here</a></p>
<pre><strong>
PS &gt; $SPSite = Get-SPSite -url http://moss; $SPSite | Select Url, Port, Owner | Format-List; $SPSite.Dispose()
</strong>
Url   : http://moss
Port  : 80
Owner : POWERSHELL\administrator
</pre>
<p> <br />
We can also get usage Information:</p>
<pre><strong>
PS &gt;  $SPSite = Get-SPSite -url http://moss; $SPSite.Usage; $SPSite.Dispose()
</strong>

Storage           : 550113
Bandwidth         : 0
Visits            : 0
Hits              : 0
DiscussionStorage : 0</pre>
<p> </p>
<p>And even information from the WebApplication Pool </p>
<pre><strong>
PS &gt; $SPSite = Get-SPSite -url http://moss; $SPSite.WebApplication.ApplicationPool | Select DisplayName, Status | Format-List; $SPSite.Dispose()
</strong>

DisplayName : SharePoint - 80
Status      : Online</pre>
<p> </p>
<p>Try Pipe:ing the $SPSite object to Get-Mameber and check out all Available methods and properties available. </p>
<pre><strong>
PS &gt; $SPSite = Get-SPSite -url http://moss; $SPSite | Get-Member; $SPSite.Dispose()
</strong></pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Get-SPWeb.ps1">Get-SPWeb.ps1</a></h2>
<p> </p>
<p>The Get-SPWeb.ps1 Returns a Site instead of a Site Collection through the OpenWeb() method. Through it, we can modify the Title and description of a site, we can add Items, documents and lots more. Here&#8217;s an example on how you can change the Title and Descrition of a Site. </p>
<pre><strong>
PS &gt; $OpenWeb = Get-SPWeb http://moss; $OpenWeb.Title; $OpenWeb.Dispose()
</strong>
Home
<strong>
PS &gt; $OpenWeb = Get-SPWeb http://moss; $OpenWeb.Description; $OpenWeb.Dispose()
</strong>
Home
<strong>
PS &gt;  $OpenWeb = Get-SPWeb http://moss; $OpenWeb.Title = "PowerShell Home"; $OpenWeb.Description = "Demo From PowerShell.nu"; $OpenWeb.Update(); $OpenWeb.Dispose()
</strong></pre>
<p> </p>
<p>Here&#8217;s What happened to my MOSS RootWeb Site after running these simple commands. </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss01.jpg"><img class="alignnone size-large wp-image-865" title="moss01" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss01-499x357.jpg" alt="moss01" width="499" height="357" /></a> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Get-SPList.ps1">Get-SPList.ps1</a></h2>
<p> </p>
<p>We&#8217;ve accessed The Site Collection and a MOSS Site, Let&#8217;s look at how to access a List within a Site. We can do this through the Get-SPList.ps1 Script. We can use it to Get or Set List Information and even Get or Set Items and Fields in the List. </p>
<pre><strong>
PS &gt; $SPList = Get-SPList -url http://moss -List Announcements; $SPList.ItemCount; $SPList.Dispose()
</strong>
3
<strong>
PS &gt; $SPList = Get-SPList -url http://moss -List Announcements; $SPList.Items | ForEach { $_["Title"] }; $SPList.Dispose()
</strong>
Get Started with Windows SharePoint Services!
Announcement Added through PowerShell
Demo from PowerShell.nu</pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Get-SPField.ps1">Get-SPField.ps1</a></h2>
<p> </p>
<p>A List Contains Field which tell us what kind of information we can add to our Items. When Accessing a Field you can use the Get-SPField.ps1 script. The Field holds alot of information such as Type. </p>
<pre><strong>
PS &gt; $Field = Get-SPField -url http://moss -List Announcements -Field Expires
PS &gt; $Field.Type
</strong>
DateTime</pre>
<p> </p>
<p>You can even edit information in the Field. Here&#8217;s an Example on How to Hide the Field in Edit Form. When a User Tries to Edit an item in the Announcements List, he won&#8217;t see the Expires Field. </p>
<pre><strong>
PS &gt; $Field.ShowInEditForm = $False
PS &gt; $Field.Update()
</strong></pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Get-SPView.ps1">Get-SPView.ps1</a></h2>
<p> </p>
<p>A List Contains a Variaty of Views. Here&#8217;s how you Access a List View in MOSS 2007 using the Get-SPView.ps1 Script. </p>
<pre><strong>
PS &gt; $View = Get-SPView -url http://moss -List "Shared Documents" -View "All Documents"
</strong></pre>
<p> </p>
<p>The View contains alot of Methods and Properties. Let&#8217;s take a look at the Clone() Method. </p>
<pre><strong>
PS &gt; [void]$View.Clone("My Cloned View",100,$True,$False)
</strong></pre>
<p> </p>
<p>With this Simple Command, I&#8217;ve Created a new View Called &#8220;My Cloned View&#8221;. It&#8217;s basically a Copy of the &#8220;All Documents&#8221; View. </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Get-SPItem.ps1">Get-SPItem.ps1</a></h2>
<p> </p>
<p>When Accessing Items within a List, you can use the Get-SPItem.ps1 Script. Storing the Item in a Variable Allows us to Get And Modify it&#8217;s properties. The script includes an -All Switch that retrieves All Items in a List instead of just one item. </p>
<pre><strong>
PS &gt; $Item = Get-SPItem  -url http://moss -List Announcements -Item "Get Started with Windows SharePoint Services!"
</strong></pre>
<p> </p>
<p>Now That we have an Item stored in the $Item Variable, we can Modify it. </p>
<pre><strong>
PS &gt; $Item["Body"]
</strong>
<div class="ExternalClass62D33B59C0C94D40BBB3A216506575B1">Microsoft Windows SharePoint Services helps you to be more eff
ective by connecting people, information, and documents. For information on getting started, see Help.</div>

<strong>
PS &gt; $Item["Body"] = "New Text in Body"
PS &gt; $Item.Update()
</strong></pre>
<p> </p>
<p>Another Nice Trick is Looping through all Items. First let&#8217;s Store them in a variable: </p>
<pre><strong>
PS &gt; $AllItems = Get-SPItem -url http://moss -List Announcements -All
</strong></pre>
<p>Now Let&#8217;s Set the Body on All Announcements in the Announcements List.</p>
<pre><strong>
PS &gt; $AllItems | ForEach { $_["Body"] = "New Text"; $_.Update() }
</strong></pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPAnnouncement.ps1">Add-SPAnnouncement.ps1</a></h2>
<p> </p>
<p>Next, let&#8217;s add an Announcement to our RootWeb Site. Using the Add-SPAnnouncement.ps1 sript, we can add through a One-Liner in PowerShell. </p>
<pre><strong>
PS &gt; Add-SPAnnouncement -url http://moss -List "Announcements" -Title "Demo from PowerShell.nu" -Body "&lt;h1&gt;PowerShell&lt;/h1&gt;&lt;p /&gt;is Cool!" -Expires (Get-Date).AddHours(1)
</strong></pre>
<p> </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss02.jpg"><img class="alignnone size-large wp-image-866" title="moss02" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss02-500x356.jpg" alt="moss02" width="500" height="356" /></a> </p>
<p>Let&#8217;s say that you have multiple sites in your Site Collection and you want to add an Announcement on each site. This can be solved with a Simple ForEach: </p>
<pre><strong>
PS &gt; $Sites = "http://moss/HR","http:moss/IT","http://moss/Production","http://moss/Sales"
PS &gt; $Sites | ForEach {
&gt;&gt; Add-SPAnnouncement -url $_ -List "Announcements" -Title "Demo från PowerShell.nu" -Body "

is Coolt!" -Expires (Get-Date).AddHours(1)
</strong></pre>
<p> </p>
<p>This Code adds an announcement on each site in the $Sites Array. </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPCalendar.ps1">Add-SPCalendar.ps1</a></h2>
<p> </p>
<p>The Add-SPCalendar.ps1 script adds new Calendar Entries to a MOSS Calendar List. </p>
<pre><strong>
PS &gt; Add-SPCalendar -url http://moss -List "Calendar" -Title "SharePoint - PowerShell Demo" -Location "Stockholm" -Description "PowerShell Demo" -StartTime (Get-Date) -EndTime (Get-Date).AddHours(4)
</strong></pre>
<p> </p>
<p>The -StartTime and -EndTime Parameters accept an [DateTime] object, which means that we can use the Get-date CmdLet to Add Dates. </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss03.jpg"><img class="alignnone size-large wp-image-867" title="moss03" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss03-500x357.jpg" alt="moss03" width="500" height="357" /></a> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPLink.ps1">Add-SPLink.ps1</a></h2>
<p> </p>
<p>Here&#8217;s a Script that adds Links to a MOSS Links List. It sets the Link, the Description of the Link and the Notes Field. </p>
<pre><strong>
PS &gt; Add-SPLink -url http://moss -List "Links" -Link "http://www.powershell.nu" -Description "PowerShell.nu - Blog" -Notes "PowerShell Blog"
</strong></pre>
<p> </p>
<p>Here&#8217;s what our Newly created Link Item looks like: </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss04.jpg"><img class="alignnone size-large wp-image-868" title="moss04" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss04-500x357.jpg" alt="moss04" width="500" height="357" /></a> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Set-SPImageWebPart.ps1">Set-SPImageWebPart.ps1</a></h2>
<p> </p>
<p>On a Default installed MOSS, The Root Web uses the &#8220;Team Site&#8221; Template, which has an Image WebPart on the Right Displaying a SharePoint Services Image. Let&#8217; go ahead and change the image using the Set-SPImageWebPart.ps1 Script. </p>
<pre><strong>
PS &gt; Set-SPImageWebPart -url http://moss -WebPart "Site Image" -Image "C:\Demo\Files\PowerShell.jpg"
</strong></pre>
<p> </p>
<p>As you can see in the Image below, Our RootWeb Team Site looks a little PowerShelled. </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss05.jpg"><img class="alignnone size-large wp-image-869" title="moss05" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss05-499x357.jpg" alt="moss05" width="499" height="357" /></a> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Set-SPTheme.ps1">Set-SPTheme.ps1</a></h2>
<p>Now that we&#8217;ve customized our Site with a New &#8220;Site Image&#8221;, let&#8217;s go ahead and change the Theme. We&#8217;ll use the Set-SPTheme.ps1 script to achieve this.</p>
<pre><strong>
PS &gt; Set-SPTheme -Url http://moss -Theme obsidian
</strong></pre>
<p> </p>
<p>And with a simple One-Liner, we&#8217;ve changed the Theme on our Site. Doing without the script takes about two lines of code, but i Added the script since I think it&#8217;s pretty cool. </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss06.jpg"><img class="alignnone size-large wp-image-870" title="moss06" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss06-500x357.jpg" alt="moss06" width="500" height="357" /></a> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Upload-SPDocument.ps1">Upload-SPDocument.ps1</a></h2>
<p> </p>
<p>This Script lets you Upload Documents to a Document Library in MOSS. Here&#8217;s how it Works: </p>
<pre><strong>
PS &gt; Upload-SPDocument -url http://moss -Folder "Shared Documents" -Document "C:\Documents\Excel SpreadSheet.xlsx"
</strong></pre>
<p> </p>
<p>If we look in our &#8220;Shared Documents&#8221; List, We can see that the Document is uploaded there now. </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss07.jpg"><img class="alignnone size-large wp-image-871" title="moss07" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss07-499x356.jpg" alt="moss07" width="499" height="356" /></a> </p>
<p>But What it we want to Upload one hundred documents ? Well, since we are using PowerShell, we can do it with a One-Liner. </p>
<pre><strong>
PS &gt; gci C:\Documents | ForEach { Upload-SPDocument -url http://moss -Folder "Shared Documents" -Document $_.FullName }
</strong></pre>
<p> </p>
<p>This really shows the Power of Microsoft PowerShell </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPFolder.ps1">Add-SPFolder.ps1</a></h2>
<p> </p>
<p>Now That we&#8217;ve Uploaded a couple of Files, Let&#8217;s Add a New Folder to our &#8220;Shared Documents&#8221;. We can do this by using the Add-SPFolder.ps1 script. </p>
<pre><strong>
PS &gt; Add-SPFolder -Url http://moss -List "Shared Documents" -Name "New Folder"
</strong></pre>
<p> </p>
<p>If we want to Upload Documents Directly to our Folder we can use the Upload-SPDocument.ps1 Script again, we just point it to our New Folder. </p>
<pre><strong>
PS &gt; Upload-SPDocument -url http://moss -Folder "Shared Documents/New Folder" -Document "C:\Documents\Excel SpreadSheet.xlsx"
</strong></pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPTextField.ps1">Add-SPTextField.ps1</a></h2>
<p> </p>
<p>Let&#8217;s add a couple of Fields to our &#8220;Shared Documents&#8221; List. First, we&#8217;ll add a Document Owner Field. In this example we&#8217;ll use a simple Text field, but you could obviously use a User field instead. We&#8217;ll get back to the User field a little later in this post. </p>
<pre><strong>
PS &gt; Add-SPTextField -url http://moss -List "Shared Documents" -Name "Document Owner" -Description "Document Owner"
</strong></pre>
<p> </p>
<p>This Adds a TextField to our List named &#8220;Document Owner&#8221;, if you want the field to Require information, simply add -Required to the command above. </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss08.jpg"><img class="alignnone size-large wp-image-872" title="moss08" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss08-499x356.jpg" alt="moss08" width="499" height="356" /></a> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPChoiceField.ps1">Add-SPChoiceField.ps1</a></h2>
<p> </p>
<p>Next, We&#8217;ll add a Choice Field to our &#8220;Shared Document&#8221;. This can be done by using the Add-SPChoiceField.ps1 Script. Again, if you want the Field to Require information, just add -Required to the command. </p>
<pre><strong>
PS &gt; Add-SPChoiceField -url http://moss -List "Shared Documents" -Name "Document Type" -Description "Type of Document" -Choices $("Excel","Word","PowerPoint")
</strong></pre>
<p> </p>
<p>Note the -Choices Paramteter. It takes an Array of arguments and Sets each argument as a Choice in the Field. Typing $(&#8220;Argument1&#8243;,&#8221;Argument2&#8243;) is a quick way to create an array and passing it as an argument to the script. </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss09.jpg"><img class="alignnone size-large wp-image-873" title="moss09" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss09-500x356.jpg" alt="moss09" width="500" height="356" /></a> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPFieldToView.ps1">Add-SPFieldToView.ps1</a></h2>
<p> </p>
<p>Now that we have two new Fields in our &#8220;Shared Documents&#8221;, let&#8217;s add them to the &#8220;All Documents&#8221; View by using the Add-SPFieldToView.ps1 Script. </p>
<pre><strong>
PS &gt; Add-SPFieldToView -url http://moss -List "Shared Documents" -Field "Document Owner" -View "All Documents"
PS &gt; Add-SPFieldToView -url http://moss -List "Shared Documents" -Field "Document Type" -View "All Documents"
</strong></pre>
<p> </p>
<p>If we check out our &#8220;Shared Documents&#8221; list now, we can see that the Fields are Added to the &#8220;All Documents&#8221; View. You can, of course, use this on any type of List in MOSS 2007. </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss10.jpg"><img class="alignnone size-large wp-image-874" title="moss10" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss10-500x357.jpg" alt="moss10" width="500" height="357" /></a> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Set-SPItem.ps1">Set-SPItem.ps1</a></h2>
<p> </p>
<p>Here&#8217;s a Really Useful script when working with Items. The Set-SPItem.ps1 Script can either Create a New Item or Modify an existing Item. At first, Let&#8217;s take a look on how to Modify existing Items. By Default, the -field param is set to Title, but by changing it to Name, the script will check for a match in the Name Field and if it finds a match, it will update the Item, if it doesn&#8217;t find a match it will create a New Item. Note that when Creating Items in a Document Library you have to use the Upload-SPDocument.ps1 script. </p>
<p>Note that the -Values takes a HashTable Array of Values to Set on the Item. Let&#8217;s say a List has Two Fields. A Title field and a Description Field. If I want to Create a New Item Called &#8220;New Item&#8221; and with The Description &#8220;My New Item Description&#8221; I could Simply type: </p>
<pre><strong>
PS &gt; Set-SPItem -url http://moss -List "My List" -Name "New Item" -Values @{"Description" = "My New Item Description"}
</strong></pre>
<p> </p>
<p>If i Want to Edit the Item that i Created i Could reuse the Same Command, since it First looks for an Item Where the Title is Set to &#8220;New Item&#8221; </p>
<p>Let&#8217;s say i Don&#8217;t know the Title of the Item but i Do know It&#8217;s Description. By using the -Field paramter i Could get the Correct Item and Modify it. </p>
<pre><strong>
PS &gt; Set-SPItem -url http://moss -List "My List" -Name "My New Item Description" -Field Description -Values @{"Title" = "New Title"; "Description" = "Changed Title and Changed Description of Item"}
</strong></pre>
<p> </p>
<p>Let&#8217;s Take a Look at the Documents that we Added earlier. Here&#8217;s an example on adding MetaData on Documents in a Document Library:</p>
<pre><strong>
PS &gt; Set-SPItem -url http://moss -List "Shared Documents" -Name "Excel SpreadSheet.xlsx" -Field "Name" -Values @{"Document Type" = "Excel"; "Document Owner" = "Niklas Goude"}
PS &gt; Set-SPItem -url http://moss -List "Shared Documents" -Name "Word Document.docx" -Field "Name" -Values @{"Document Type" = "Word"; "Document Owner" = "Niklas Goude"}
PS &gt; Set-SPItem -url http://moss -List "Shared Documents" -Name "PowerPoint Presentation.pptx" -Field "Name" -Values @{"Document Type" = "PowerPoint"; "Document Owner" = "Niklas Goude"}
</strong></pre>
<p> </p>
<p>With these Commands I added information in the &#8220;Document Type&#8221; Field and the &#8220;Document Owner&#8221; Field on my three Documents, as the image below show. </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss11.jpg"><img class="alignnone size-large wp-image-875" title="moss11" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss11-500x357.jpg" alt="moss11" width="500" height="357" /></a> </p>
<p>Let&#8217;s Use this Script to Modify the Announcement That we Added Earlier. We&#8217;ll Change the Body of the Announcement. </p>
<pre><strong>
PS &gt; Set-SPItem -url http://moss -List Announcements -Name "Demo from PowerShell.nu" -Values @{"Body" = "&lt;h2&gt;Modified With Set-SPItem.ps1&lt;/h2&gt;"}
</strong></pre>
<p> </p>
<p>Here&#8217;s what the Announcemet looks like now: </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss12.jpg"><img class="alignnone size-large wp-image-876" title="moss12" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss12-500x356.jpg" alt="moss12" width="500" height="356" /></a> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPList.ps1">Add-SPList.ps1</a></h2>
<p> </p>
<p>Now Let&#8217;s create our own Custom List. We&#8217;ll use the Add-SPList.ps1 Script to do this. Specifying the Type to &#8220;Custom List&#8221; tells the script to create a &#8220;Custom List&#8221;. You can, of course create any type of list available in MOSS through this script. </p>
<pre><strong>
PS &gt; Add-SPList -url http://moss -Name "My List" -Description "My Custom Demo List" -Type "Custom List"
</strong></pre>
<p> </p>
<p>This Creates the List, but it doesn&#8217;t Add the List to the QuickLaunch Bar. Let&#8217;s check out how to Add a List to the QuickLaunchBar. </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPListToQuickLaunch.ps1">Add-SPListToQuickLaunch.ps1</a></h2>
<p> </p>
<p>This Script adds lists to the Quicklaunch Bar in MOSS 2007. The Command below shows how you can use the script. </p>
<pre><strong>
PS &gt; Add-SPListToQuickLaunch -url http://moss -List "My List"
</strong></pre>
<p> </p>
<p>This command adds the List to the QuickLaunch Bar. </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss13.jpg"><img class="alignnone size-large wp-image-877" title="moss13" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss13-499x358.jpg" alt="moss13" width="499" height="358" /></a> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Set-SPQuickLaunchOrder.ps1">Set-SPQuickLaunchOrder.ps1</a></h2>
<p> </p>
<p>Let&#8217;s Change the QuickLaunch Order. We&#8217;ll use the Set-SPQuickLaunchOrder.ps1 Script that moves a List to the Top of the QuickLaunch. </p>
<pre><strong>
PS &gt; Set-SPQuickLaunchOrder -url http://moss -List "My List"
</strong></pre>
<p> </p>
<p>If we look at our site now, We can see that our QuickLaunch Order has been Changed. The &#8220;My List&#8221; List is now on top. </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss14.jpg"><img class="alignnone size-large wp-image-878" title="moss14" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss14-500x358.jpg" alt="moss14" width="500" height="358" /></a> </p>
<p>Now That we have a Custom List, Let&#8217;s Add a couple of different Fields, We&#8217;ll also add them to the &#8220;All Items&#8221; View with the Add-SPFieldToView.ps1 script. </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPCurrencyField.ps1">Add-SPCurrencyField.ps1</a></h2>
<p> </p>
<p>You can Add a Currency Field by using the Add-SPCurrencyField.ps1 Script. </p>
<pre><strong>
PS &gt; Add-SPCurrencyField -url http://moss -List "My List" -Name Cash -Description "How much Money do you have?"
PS &gt; Add-SPFieldToView -url http://moss -List "My List" -Field Cash -View "All Items"
</strong></pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPDateTimeField.ps1">Add-SPDateTimeField.ps1</a></h2>
<p> </p>
<p>Here&#8217;s how we can add a DateTime Field to a List using the Add-SPDateTimeField.ps1 Script. </p>
<pre><strong>
PS &gt; Add-SPDateTimeField -url http://moss -List "My List" -Name "Birthday" -Description "When is Your Birthday?"
PS &gt; Add-SPFieldToView -url http://moss -List "My List" -Field Birthday -View "All Items"
</strong></pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPNoteField.ps1">Add-SPNoteField.ps1</a></h2>
<p> </p>
<p>The Note Field Accepts Text on Multiple Rows. Here we add a Note Field using the Add-SPNoteField.ps1 Script. </p>
<pre><strong>
PS &gt; Add-SPNoteField -url http://moss -List "My List" -Name Description -Description "About Me.."
PS &gt; Add-SPFieldToView -url http://moss -List "My List" -Field Description -View "All Items"
</strong></pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPNumberField.ps1">Add-SPNumberField.ps1</a></h2>
<p> </p>
<p>We can also Add Numeric Fields to MOSS. This example shows how  to do that using the Add-SPNumberField.ps1 Script. </p>
<pre><strong>
PS &gt; Add-SPNumberField -url http://moss -List "My List" -Name Age -Description "How Old Are You?"
PS &gt; Add-SPFieldToView -url http://moss -List "My List" -Field Age -View "All Items"
</strong></pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPYesNoField.ps1">Add-SPYesNoField.ps1</a></h2>
<p> </p>
<p>With the Add-SPYesNoField.ps1 script, We can add a Yes/No Checkbox Field to our List. </p>
<pre><strong>
PS &gt; Add-SPYesNoField -url http://moss -List "My List" -Name "Windows 7" -Description "Do You Have Windows 7 Installed?"
PS &gt; Add-SPFieldToView -url http://moss -List "My List" -Field "Windows 7" -View "All Items"
</strong></pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPUserField.ps1">Add-SPUserField.ps1</a></h2>
<p> </p>
<p>Adding User Fields that point to a Active-Directory User, Can be Added through the Add-SPUserField.ps1 Script. </p>
<pre><strong>
PS &gt; Add-SPUserField -url http://moss -List "My List" -Name User -Description "User"
PS &gt; Add-SPFieldToView -url http://moss -List "My List" -Field User -View "All Items"
</strong></pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPMultipleUserField.ps1">Add-SPMultipleUserField.ps1</a></h2>
<p> </p>
<p>A User Field can Allow Multiple Selections. Here&#8217;s how to add a multiple User Field using the Add-SPMultipleUserField.ps1 script. </p>
<pre><strong>
PS &gt; Add-SPMultipleUserField -url http://moss -List "My List" -Name "Multiple Users" -Description "Multiple Users"
PS &gt; Add-SPFieldToView -url http://moss -List "My List" -Field "Multiple Users" -View "All Items"
</strong></pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPMultiChoiceField.ps1">Add-SPMultiChoiceField.ps1</a></h2>
<p> </p>
<p>Choice Fields can also accept Multiple Choices. Here&#8217;s an example on how to add a Multiple Choice Field using the Add-SPMultiChoiceField.ps1 Script. </p>
<pre><strong>
PS &gt; Add-SPMultiChoiceField -url http://moss -List "My List" -Name "Favorite Music" -Description "Favorite Music" -Choices $("Country","Metal","Rock","Soul","Jazz")
PS &gt; Add-SPFieldToView -url http://moss -List "My List" -Field "Favorite Music" -View "All Items"
</strong></pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPLookupField.ps1">Add-SPLookupField.ps1</a></h2>
<p>The Lookup Field Points to an Item in another List. In this Example we&#8217;ll Point it to the &#8220;Tasks&#8221; List.</p>
<pre><strong>
PS &gt; Add-SPLookupField -url http://moss -List "My List" -Name "My Tasks" -Description "My Tasks" -LookupList Tasks
PS &gt; Add-SPFieldToView -url http://moss -List "My List" -Field "My Tasks" -View "All Items"
</strong></pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPMultiLookupField.ps1">Add-SPMultiLookupField.ps1</a></h2>
<p> </p>
<p>LookupFields Can also have multiple Values. We can add a Multiple LookupList through the Add-SPMultiLookupField.ps1 Script. Again, We&#8217;ll Use the Tasks List as Lookup. </p>
<pre><strong>
PS &gt; Add-SPMultiLookupField -url http://moss -List "My List" -Name "Multiple Tasks" -Description "Multiple Tasks" -LookupList Tasks
PS &gt; Add-SPFieldToView -url http://moss -List "My List" -Field "Multiple Tasks" -View "All Items"
</strong></pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPURLField.ps1">Add-SPURLField.ps1</a></h2>
<p> </p>
<p>Finally, Let&#8217;s Add an URL Field to our &#8220;Custom List&#8221;. </p>
<pre><strong>
PS &gt; Add-SPURLField -url http://moss -List "My List" -Name HomePage -Description "HomePage"
PS &gt; Add-SPFieldToView -url http://moss -List "My List" -Field HomePage -View "All Items"
</strong></pre>
<p> </p>
<p>Now, Let&#8217;s see what our List Looks like. </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss15.jpg"><img class="alignnone size-large wp-image-879" title="moss15" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss15-499x357.jpg" alt="moss15" width="499" height="357" /></a> </p>
<p>Let&#8217;s Add Two Task Items and then create a New Item in our &#8220;Custom List&#8221; using the <a href="http://www.powershell.nu/wp-content/uploads/2009/09/Set-SPItem.ps1">Set-SPItem.ps1</a> Script. </p>
<pre><strong>
PS &gt; Set-SPItem -url http://moss -List Tasks -Name "My First Task" -Values @{"Priority" = "(3) Low"; "Status" = "In Progress"; "% Complete" = "0.4"; "Assigned To" = "powershell\Administrator"; "Description" = "My First Task"; "Start Date" = "09/07/09"; "Due Date" = "09/08/09"}
PS &gt; Set-SPItem -url http://moss -List Tasks -Name "My Second Task" -Values @{"Priority" = "(1) High"; "Status" = "Not Started"; "% Complete" = "0"; "Assigned To" = "powershell\Administrator"; "Description" = "My Second Task"; "Start Date" = "09/07/09"; "Due Date" = "09/08/09"}
</strong></pre>
<p> </p>
<p>Here&#8217;s our New Tasks up and running. </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss16.jpg"><img class="alignnone size-large wp-image-880" title="moss16" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss16-499x357.jpg" alt="moss16" width="499" height="357" /></a> </p>
<p>Now Let&#8217;s Add a New Item in our &#8220;Custom List&#8221;. Note that Fields that Allow multiple Values are divided by a ; in the command below. For Instance, if I want to two values to a multiple Choice Field I would have to Type: @{&#8220;MultiChoiceField&#8221; = &#8220;Value1; Value2; Value3&#8243;}.</p>
<pre><strong>
PS &gt; Set-SPItem -url http://moss -List "My List" -Name "My First Item" -Values @{"Cash" = "10"; "Birthday" = "05/05/1982"; "Description" = "My First Entry"; "Age" = "27"; "Windows 7" = "Yes"; "User" = "powershell\administrator"; "Multiple Users" = "powershell\administrator; powershell\nigo"; "Favorite Music" = "Metal; Country"; "My Tasks" = "My First Task"; "Multiple Tasks" = "My First Task; My Second Task"; "HomePage" = "http://www.powershell.nu; My Blog" }
</strong></pre>
<p> </p>
<p>And Here&#8217;s what our Item Looks like in MOSS 2007. </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss17.jpg"><img class="alignnone size-large wp-image-881" title="moss17" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss17-500x358.jpg" alt="moss17" width="500" height="358" /></a> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Set-SPView.ps1">Set-SPView.ps1</a></h2>
<p>Let&#8217;s Modify the Apperance of the &#8220;All Tasks&#8221; View in the Tasks List so that it Groups By Status. When Modifying appearance of a View, We change the View Query. This can be Done by using the Set-SPView.ps1 Script.</p>
<pre><strong>
PS &gt; Set-SPView -url http://moss -List Tasks -View "All Tasks" -Query ''
</strong></pre>
<p> </p>
<p>Here&#8217;s what our Tasks Look like now. </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss18.jpg"><img class="alignnone size-large wp-image-882" title="moss18" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss18-499x357.jpg" alt="moss18" width="499" height="357" /></a> </p>
<p>Remember the &#8220;Shared Documents that We Added Fields to earlier ? Let&#8217;s Group the &#8220;All Documents&#8221; View by one of our New Fields. Note that the Name=&#8221;Document_x0020_Type&#8221; in the Query. It&#8217;s because the Field has Spaces in its Name. </p>
<pre><strong>
PS &gt; Set-SPView -url http://moss -List "Shared Documents" -View "All Documents" -Query ''
</strong></pre>
<p> </p>
<p>And now our Documents are Grouped by &#8220;Document Type&#8221;. </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss19.jpg"><img class="alignnone size-large wp-image-883" title="moss19" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss19-500x358.jpg" alt="moss19" width="500" height="358" /></a> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPSite.ps1">Add-SPSpite.ps1</a></h2>
<p> </p>
<p>With the Add-SPSite.ps1 Script, we can add New Sites to our Site Collection. There are a Couple of Different Templates that we can use. To get a list of all templates available, SImply type the following commands. </p>
<pre><strong>
PS &gt; $OpenWeb = Get-SPWeb http://moss; $OpenWeb.GetAvailableWebTemplates(1033) | Select Name; $OpenWeb.Dispose()
</strong></pre>
<p> </p>
<p>Let&#8217;s Create a New Site For our IT Department. </p>
<pre><strong>
PS &gt; Add-SPSite -url http://moss -weburl "IT" -Title "Information Technology" -Description "IT Department" -Template "STS#1"
</strong></pre>
<p> </p>
<p>Here&#8217;s What the Site looks like now. </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss20.jpg"><img class="alignnone size-large wp-image-884" title="moss20" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss20-500x358.jpg" alt="moss20" width="500" height="358" /></a> </p>
<p>Since we used a STS#0 Template, the Site doesn&#8217;t contain any Lists or information. </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPGroup.ps1">Add-SPGroup.ps1</a></h2>
<p> </p>
<p>If we want to Add a New Group to our Site Collection we can use the Add-SPGroup.ps1 Script. Here&#8217;s an example on using the Script. </p>
<pre><strong>
PS &gt; Add-SPGroup -url http://moss -Group "New Group" -Role Read -Owner "powershell\administrator"
</strong></pre>
<p> </p>
<p>Now our &#8220;New Group&#8221; is Added to our Site with &#8220;Read&#8221; Permissions </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss21.jpg"><img class="alignnone size-large wp-image-885" title="moss21" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss21-500x358.jpg" alt="moss21" width="500" height="358" /></a> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPUser.ps1">Add-SPUser.ps1</a></h2>
<p> </p>
<p>With our New Group set up, we can go ahead and add users to it. To accomplish this, we can use the Add-SPUser.ps1 Script. Here&#8217;s an example on adding a User to the &#8220;New Group&#8221;.</p>
<pre><strong>
PS &gt; Add-SPUser -url http://moss -Group "New Group" -Domain "powershell.nu" -sAMAccountName "goude" -mail "niklas.goude@zipper.se" -FullName "Niklas Goude"
</strong></pre>
<p> </p>
<p>If we look in the Group now, our User will be added. </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss22.jpg"><img class="alignnone size-large wp-image-886" title="moss22" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss22-500x357.jpg" alt="moss22" width="500" height="357" /></a> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPSitePermission.ps1">Add-SPSitePermission.ps1</a></h2>
<p> </p>
<p>Let&#8217;s Give our Group Full Permissions on The IT Site that we created earlier.</p>
<pre><strong>
PS &gt; Add-SPSitePermission -url "http://moss/IT" -Group "New Group" -Permission "FullMask"
</strong></pre>
<p> </p>
<p>Now all users in the Group have Full Permissions on the &#8220;IT&#8221; Site. On the RootWeb, they still have Read Permissions. </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPImageWebPart.ps1">Add-SPImageWebPart.ps1</a></h2>
<p> </p>
<p>Let&#8217;s Add a New Image WebPart to the IT Site that we just created. Here&#8217;s an example on how to do it using the Add-SPImageWebPart.ps1 Script.</p>
<pre><strong>
PS &gt; Add-SPImageWebPart -url http://moss/IT -Name "My Image" -Image "C:\Images\PowerShell.jpg" -ChromeType "None"
</strong></pre>
<p> </p>
<p>Now the Image WebPart is Added to the Site. There are a couple of parameters you can use with this script. simply type Add-SPImageWebPart -help to check out available parameters. </p>
<pre><strong>
PS &gt; Add-SPImageWebPart -help
</strong></pre>
<p> </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss23.jpg"><img class="alignnone size-large wp-image-887" title="moss23" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss23-499x357.jpg" alt="moss23" width="499" height="357" /></a> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPListViewWebPart.ps1">Add-SPListViewWebPart.ps1</a></h2>
<p> </p>
<p>The Add-SPListViewWebPart.ps1 let&#8217;s us Add list View WebParts to our Sites. The Script contains a couple of parameters that let&#8217;s you choose Chrome Type, Zone and a couple of other things. Here&#8217;s an example on Using the Script.</p>
<pre><strong>
PS &gt; Add-SPListViewWebPart -url http://moss -List "My List" -Name "Client Statistics" -ChromeType "None"
</strong></pre>
<p> </p>
<p>Here&#8217;s our New List WebPart in Action! </p>
<p><a href="http://www.powershell.nu/wp-content/uploads/2009/09/moss24.jpg"><img class="alignnone size-large wp-image-888" title="moss24" src="http://www.powershell.nu/wp-content/uploads/2009/09/moss24-500x358.jpg" alt="moss24" width="500" height="358" /></a> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Remove-SPField.ps1">Remove-SPField.ps1</a></h2>
<p> </p>
<p>If you want to Remove a Field From a List you can use the Remove-SPField.ps1 Script. Here&#8217;s an example on how to use the Script.</p>
<pre><strong>
PS &gt; Remove-SPField -url http://moss -List "Shared Documents" -Field "Document Type"
</strong></pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Remove-SPItem.ps1">Remove-SPItem.ps1</a></h2>
<p> </p>
<p>If you want to Remove a List Item you can use the Remove-SPItem.ps1 script. The -name parameter matches with the Title field by default. If you want to match the name with another field, simply use the -field parameter.</p>
<pre><strong>
PS &gt; Remove-SPItem -url http://moss -List Tasks -name "My First Task"
PS &gt; Remove-SPItem -url http://moss -List Tasks -name "Not Started" -Field Status
</strong></pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Remove-SPList.ps1">Remove-SPList.ps1</a></h2>
<p> </p>
<p>If you want to Remove an entire List you can use the Remove-SPList.ps1 script,</p>
<pre><strong>
PS &gt; Remove-SPList -url http://moss -List Tasks
</strong></pre>
<p> </p>
<p>This Command Removed the Tasks List from the RootWeb Site. </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Remove-SPSite.ps1">Remove-SPSite.ps1</a></h2>
<p> </p>
<p>When Removing a Site from MOSS 2007 You can use the Remove-SPSite.ps1 script. This exmaple shows how to remove the IT Site that we created earlier.</p>
<pre><strong>
PS &gt; Remove-SPSite -url http://moss/IT
</strong></pre>
<p> </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Export-SPSite.ps1">Export-SPSite.ps1</a></h2>
<p> </p>
<p>Let&#8217;s take a Backup of our Site Collection. We can either do this through Central Administration, through an STSADM Command or by Using PowerShell. This Example shows how to use a PowerShell Script to take a Backup of a Site Collection.</p>
<pre><strong>
PS &gt; Export-SPSite -url http://moss -file Backup.bak -Location C:\Backup\
</strong></pre>
<p> </p>
<p>The Command Places a Backup file in C:\Backup\Backup.bak. to automate this you could set up a Scheduled Task that takes a backup at specified weekdays. </p>
<h2><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Import-SPSite.ps1">Import-SPSite.ps1</a></h2>
<p> </p>
<p>Now That we have a Backup, Let&#8217;s restore our Site Collection from the Backup file. To achieve this, we can use the Import-SPSite.ps1 Script. Here&#8217;s an example on how to use the script.</p>
<pre><strong>
PS &gt; Import-SPSite -url http://moss -file Backup.bak -Location C:\Backup\
</strong></pre>
<p> </p>
<p>Here&#8217;s a List of All scripts from this Post. Enjoy! </p>
<p>Regards</p>
<p>Goude </p>
<ul>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Get-SPSite.ps1">Get-SPSite.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Get-SPWeb.ps1">Get-SPWeb.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Get-SPList.ps1">Get-SPList.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Get-SPField.ps1">Get-SPField.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Get-SPView.ps1">Get-SPView.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Get-SPItem.ps1">Get-SPItem.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPAnnouncement.ps1">Add-SPAnnouncement.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPCalendar.ps1">Add-SPCalendar.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPLink.ps1">Add-SPLink.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Set-SPImageWebPart.ps1">Set-SPImageWebPart.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Set-SPTheme.ps1">Set-SPTheme.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Upload-SPDocument.ps1">Upload-SPDocument.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPFolder.ps1">Add-SPFolder.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPTextField.ps1">Add-SPTextField.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPChoiceField.ps1">Add-SPChoiceField.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPFieldToView.ps1">Add-SPFieldToView.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Set-SPItem.ps1">Set-SPItem.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPList.ps1">Add-SPList.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPListToQuickLaunch.ps1">Add-SPListToQuickLaunch.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Set-SPQuickLaunchOrder.ps1">Set-SPQuickLaunchOrder.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPCurrencyField.ps1">Add-SPCurrencyField.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPDateTimeField.ps1">Add-SPDateTimeField.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPNoteField.ps1">Add-SPNoteField.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPNumberField.ps1">Add-SPNumberField.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPYesNoField.ps1">Add-SPYesNoField.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPUserField.ps1">Add-SPUserField.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPMultipleUserField.ps1">Add-SPMultipleUserField.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPMultiChoiceField.ps1">Add-SPMultiChoiceField.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPLookupField.ps1">Add-SPLookupField.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPMultiLookupField.ps1">Add-SPMultiLookupField.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPURLField.ps1">Add-SPURLField.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Set-SPView.ps1">Set-SPView.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPSite.ps1">Add-SPSpite.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPGroup.ps1">Add-SPGroup.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPUser.ps1">Add-SPUser.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPSitePermission.ps1">Add-SPSitePermission.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPImageWebPart.ps1">Add-SPImageWebPart.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Add-SPListViewWebPart.ps1">Add-SPListViewWebPart.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Remove-SPField.ps1">Remove-SPField.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Remove-SPItem.ps1">Remove-SPItem.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Remove-SPList.ps1">Remove-SPList.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Remove-SPSite.ps1">Remove-SPSite.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Export-SPSite.ps1">Export-SPSite.ps1</a></li>
<li><a href="http://www.powershell.nu/wp-content/uploads/2009/09/Import-SPSite.ps1">Import-SPSite.ps1</a></li>
</ul>
<p> </pre>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2009/09/08/moss-2007-script-collection/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>SharePoint and PowerShell &#8211; In real life</title>
		<link>http://www.powershell.nu/2009/03/15/sharepoint-and-powershell-in-real-life/</link>
		<comments>http://www.powershell.nu/2009/03/15/sharepoint-and-powershell-in-real-life/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 19:44:41 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[Book]]></category>
		<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=549</guid>
		<description><![CDATA[I&#8217;ve had PowerShell.nu for quite some time now, gathering information and writing posts on various ways of solving issues through PowerShell, tips and trix and How too&#8217;s that have been both fun and educational for me and hopefully for the people reading my blog. I think it&#8217;s a journey worth taking, not just for the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had PowerShell.nu for quite some time now, gathering information and writing posts on various ways of solving issues through PowerShell, tips and trix and How too&#8217;s that have been both fun and educational for me and hopefully for the people reading my blog.</p>
<p />
I think it&#8217;s a journey worth taking, not just for the fun of writing but for the people I get to meet and the experiences that we can share through blogs, forums and communities.</p>
<p />
One person I&#8217;ve met and shared ideas with is Mattias Karlsson. We work at the same company and we share a passion for SharePoint. Mattias is one of the best administrators i know and he&#8217;s amazing when it comes to SharePoint. We started of with an idea of sharing our SharePoint experience through cross-blogging, letting people around the world take part of our ideas and help us expand our knowledge through communities, meetings and comments.</p>
<p />
Our idea grew to realization and today, we are writing a book on the subject. A large portion of the book will evolve around hands on scenarios and examples that IT administrators will feel familiar with.</p>
<p />
We are currently in the beginning of the process so we can&#8217;t communicate a deadline yet. We have however set up a website where you can register your email address to get news and updates regarding the Book. This site will also act as our communication point which will develop along the way as our writing is progressing.</p>
<p />
We are both really exited about our new project and will of course keep you posted on our blogs, so drop by now and then and send a mail if you have any tips or recommendations in our progress.</p>
<p />
<a href="http://www.sharepointandpowershell.com">SharePoint and PowerShell &#8211; In real life</a></p>
<p />
<a href="http://mysharepointofview.com/">Mattias Karlsson</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2009/03/15/sharepoint-and-powershell-in-real-life/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create site with approval workflow using PowerShell Part 2</title>
		<link>http://www.powershell.nu/2009/03/09/create-site-with-approval-workflow-using-powershell-part-2/</link>
		<comments>http://www.powershell.nu/2009/03/09/create-site-with-approval-workflow-using-powershell-part-2/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 21:52:08 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=527</guid>
		<description><![CDATA[This is the fourth Cross Blog post that I&#8217;ve made with Mattias and they are getting better and better. Now, we are heading onto MOSS and the SiteDirectory. Scripting the SiteDirectory is basically the same as scripting a list with items. The fun part is checking the &#8220;Approved&#8221; value set by an administrator or by [...]]]></description>
			<content:encoded><![CDATA[<p>This is the fourth <a href="http://mysharepointofview.com/2009/03/create-site-with-approval-workflow-using-powershell-part-1/">Cross Blog post that I&#8217;ve made with Mattias</a> and they are getting better and better.</p>
<p />
Now, we are heading onto MOSS and the SiteDirectory. Scripting the SiteDirectory is basically the same as scripting a list with items. The fun part is checking the &#8220;Approved&#8221; value set by an administrator or by someone with the right credentials. The Approved Status can be set to: Approved, Rejected or Pending (default). In PowerShell, the values will be 0, 1, 2 (default). so if we want to check for items that are approved, we check for items that equal 0.</p>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2009/03/check-sitedirectory01.jpg"><img src="http://www.powershell.nu/wp-content/uploads/2009/03/check-sitedirectory01-499x293.jpg" alt="check-sitedirectory01" title="check-sitedirectory01" width="499" height="293" class="alignnone size-large wp-image-537" /></a></p>
<p />
I&#8217;ve included a couple of if else statements that check if the Site is Approved, if the New Site already exists, If the Parent Site Url is valid and so on. An example is if you approve a site that has the following Url:</p>
<p />
<p>http://Sharepoint/SiteThatDoesnExist/SiteToCreate</p>
<p />
The script won&#8217;t create the Site since it&#8217;s parent doesn&#8217;t exist and will instead prompt you with a recommendation to either create the Parent Site or change the item value.</p>
<p />
<strong>Script Parameters:</strong></p>
<p />
<pre>
<ul>
<li><strong>-Url</strong>         Url to SharePoint (Required)</li>
<li><strong>-Web</strong>         Relative Url to SiteDirectory (Required)</li>
<li><strong>-List</strong>        List containing information regarding Sites (Required)</li>
<li><strong>-Template</strong>    Template to use when creating New Sites (Required)</li>
<li><strong>-help</strong>        Prints the HelpFile (Optional)</li>
</pre>
<p />
If you are unsure of whitch Template to use, you can always run the following function to find out which templates are available on your SharePoint Server:</p>
<p />
<pre>
<strong>
function Get-Templates([string]`$Url) {

	$SPSite = New-Object Microsoft.SharePoint.SPSite($Url)
	$SPSite.GetWebTemplates(1033) | Select Name, Description
	$SPSite.Dispose()
}

PS > Get-Templates http://SharePoint
</strong>
</pre>
<p />
Now with the basic script procedure in place, we can start Approving sites and scripting them into SharePoint. Start by Approving a Site.</p>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2009/03/check-sitedirectory03.jpg"><img src="http://www.powershell.nu/wp-content/uploads/2009/03/check-sitedirectory03-499x293.jpg" alt="check-sitedirectory03" title="check-sitedirectory03" width="499" height="293" class="alignnone size-large wp-image-540" /></a></p>
<p />
Now if we check out the Sites list, the Item will be Approved.</p>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2009/03/check-sitedirectory04.jpg"><img src="http://www.powershell.nu/wp-content/uploads/2009/03/check-sitedirectory04-499x293.jpg" alt="check-sitedirectory04" title="check-sitedirectory04" width="499" height="293" class="alignnone size-large wp-image-541" /></a></p>
<p />
Next, start up PowerShell and trigger the script. Change the Arguments to fit your environment. Run the script.</p>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2009/03/check-sitedirectory05.jpg"><img src="http://www.powershell.nu/wp-content/uploads/2009/03/check-sitedirectory05-500x319.jpg" alt="check-sitedirectory05" title="check-sitedirectory05" width="500" height="319" class="alignnone size-large wp-image-542" /></a></p>
<p />
And if you check the Url specified in the Item thats Approved, the New Site will have been created.</p>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2009/03/check-sitedirectory06.jpg"><img src="http://www.powershell.nu/wp-content/uploads/2009/03/check-sitedirectory06-499x293.jpg" alt="check-sitedirectory06" title="check-sitedirectory06" width="499" height="293" class="alignnone size-large wp-image-544" /></a></p>
<p />
Here&#8217;s an example on running the script:</p>
<p />
<pre>
<strong>
PS > .\Check-SiteDirectory.ps1 -Url http://makanigo -Web SiteDirectory -List Sites -Template STS#0

PS >  .\Check-SiteDirectory.ps1 -help
</strong>
</pre>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2009/03/check-sitedirectory.ps1">Click here to Download the Script</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2009/03/09/create-site-with-approval-workflow-using-powershell-part-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Set-Theme.ps1, Set Theme in Sharepoint using PowerShell</title>
		<link>http://www.powershell.nu/2009/03/08/set-themeps1-set-theme-in-sharepoint-using-powershell/</link>
		<comments>http://www.powershell.nu/2009/03/08/set-themeps1-set-theme-in-sharepoint-using-powershell/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 20:45:36 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=516</guid>
		<description><![CDATA[I wrote a blog post about this a couple of months ago, so here&#8217;s an updated script version that let&#8217;s you change theme on your SharePoint sites. It&#8217;s pretty straight forward and it includes a help function that explains how to use the Script. Let&#8217;s say you have a site http://wss/Teams/TeamWiki. You get a request [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a blog post about this a couple of months ago, so here&#8217;s an updated script version that let&#8217;s you change theme on your SharePoint sites. It&#8217;s pretty straight forward and it includes a help function that explains how to use the Script.</p>
<p />
Let&#8217;s say you have a site http://wss/Teams/TeamWiki. You get a request from your collegues to change the theme to BELLTOWN, since they like it more than the Default SharePoint theme. as an admin, you can either start Internet Explorer, browse to the site in question and Change the Theme through Site Settings or you can fancy off with a PowerShell script that does the work for you.</p>
<p />
It might seem a little overkill to start up PowerShell and change the theme on a site when it&#8217;s almost as easy as browsing to the site and changing the theme manually.. But, what if you have 10 different TeamWikis on various locations and you have to change all of them?</p>
<p />
Here&#8217;s an example on running the script on a site. Below is a Screenshot of the site before the script is run.</p>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2009/03/sharepoint-20.jpg"><img src="http://www.powershell.nu/wp-content/uploads/2009/03/sharepoint-20-500x359.jpg" alt="sharepoint-20" title="sharepoint-20" width="500" height="359" class="alignnone size-large wp-image-517" /></a></p>
<p />
Running the following command:</p>
<p />
<pre>
<strong>
PS > Set-Theme.ps1 -Url http://wss -Web Teams/TeamWiki -Theme BELLTOWN
</strong>
</pre>
<p />
Changes the Theme to this:</p>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2009/03/sharepoint-21.jpg"><img src="http://www.powershell.nu/wp-content/uploads/2009/03/sharepoint-21-500x361.jpg" alt="sharepoint-21" title="sharepoint-21" width="500" height="361" class="alignnone size-large wp-image-519" /></a></p>
<p />
If you want to display the helpfile, simply type:</p>
<p />
<pre>
<strong>
PS > Set-Theme.ps1 -help
</strong>
</pre>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2009/03/set-theme.ps1">Click here to download the Script.</a></p>
<p />
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2009/03/08/set-themeps1-set-theme-in-sharepoint-using-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Export a list with all the sites in a site collection part 2</title>
		<link>http://www.powershell.nu/2009/02/23/export-a-list-with-all-the-sites-in-a-site-collection-part-2/</link>
		<comments>http://www.powershell.nu/2009/02/23/export-a-list-with-all-the-sites-in-a-site-collection-part-2/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 20:31:50 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=441</guid>
		<description><![CDATA[This is a follow-up on Part 1 by Mattias Karlssons As Mattias mentioned, generating a list with Site information is a feature that many people ask for. It&#8217;s possible to get the information from the Site Hierarchy or the Site Content and Structure, as Mattias shows in his post I&#8217;m going to show you how [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mysharepointofview.com/2009/02/23/export-a-list-with-all-the-sites-in-a-site-collection-part-1">This is a follow-up on Part 1 by Mattias Karlssons</a></p>
<p />
As Mattias mentioned, generating a list with Site information is a feature that many people ask for. It&#8217;s possible to get the information from the Site Hierarchy or the Site Content and Structure, as Mattias shows in <a href="http://mysharepointofview.com/2009/02/23/export-a-list-with-all-the-sites-in-a-site-collection-part-1">his post</a></p>
<p />
I&#8217;m going to show you how to retrieve the information through PowerShell and also provide a script that loops through each site and automates this.</p>
<p />
First off, PowerShell can retrieve a great amount of information about Sites. If you run a simple command such as:</p>
<p />
<pre>
<strong>
PS > $SPSite = New-Object Microsoft.SharePoint.SPSite("http://yoursite"); $SPSite.AllWebs; $SPSite.Dispose()
</strong>
</pre>
<p />
You will get tons of information from every Site in your collection. The scipt that I&#8217;ve made for this post gathers the following information from each site:</p>
<p />
<ul>
<li>Name</li>
<li>Title</li>
<li>Description</li>
<li>Theme</li>
<li>WebTemplate</li>
<li>Author</li>
<li>Created</li>
<li>Modified</li>
<li>Sites</li>
<li>Users</li>
<li>ParentWeb</li>
<li>Url</li>
<li>ServerRelativeUrl</li>
<li>ID</li>
</ul>
<p />
I&#8217;ve also added a switch -ToCsv, that lets you write the information to a Csv file instead of writing it to the PS Host.</p>
<p />
Running The Script:</p>
<p />
<pre>
<strong>
PS > ./Get-SiteInformation.ps1 -Url http://wss

PS > ./Get-SiteInformation.ps1 -Url http://wss -ToCsv

PS > ./Get-SiteInformation.ps1 -help
</strong>
</pre>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2009/02/get-siteinformation.ps1">Download the Script Here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2009/02/23/export-a-list-with-all-the-sites-in-a-site-collection-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remove Sharepoint Users Programmatically Part 2</title>
		<link>http://www.powershell.nu/2009/02/16/remove-sharepoint-users-programmatically-part-2/</link>
		<comments>http://www.powershell.nu/2009/02/16/remove-sharepoint-users-programmatically-part-2/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 18:45:06 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=437</guid>
		<description><![CDATA[Mattias Described the Scenario in part 1 of this post Following up on his blog post, I&#8217;m going to descrbibe how to script this through SharePoint. Starting off, we connect to the Site that we believe the User Object is in. Then we create a simple If Else statement that checks if the User Exists, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mysharepointofview.com/2009/02/16/remove-sharepoint-users-programmatically-part-1">Mattias Described the Scenario in part 1 of this post</a></p>
<p />
Following up on his blog post, I&#8217;m going to descrbibe how to script this through SharePoint.</p>
<p />
Starting off, we connect to the Site that we believe the User Object is in. Then we create a simple If Else statement that checks if the User Exists, and If so, delete the User.</p>
<p />
Here&#8217;s the function used in the script.</p>
<p />
<pre>
<strong>
function RemoveUser([string]$Site, [string]$SiteCollection, [string]$User) {

	# GAC

	[System.Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null
	[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null

	# Connect To Sharepoint

	$SPSite = New-Object Microsoft.SharePoint.SPSite($Site)
	$OpenWeb = $SPSite.OpenWeb($SiteCollection)

	# Check if User Exists in Site

	if ($OpenWeb.SiteUsers | Where {$_.LoginName -eq $User}) {
		$User = $OpenWeb.SiteUsers | Where {$_.LoginName -eq $User}
		$OpenWeb.SiteUsers.Remove($User)

		Write-Host "User: $User Successfully Removed from Site: $Site/$SiteCollection"
	} else {
	Write-Host "User: $User Does not exist on Site: $Site/$SiteCollection"
	}
	$SPSite.Dispose()
	$OpenWeb.Dispose()
}
</strong>
</pre>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2009/02/remove-spuser.ps1">Here&#8217;s a script that automates these steps.</a></p>
<p />
Usage:</p>
<p />
<pre>
<strong>
PS > Remove-SPUser.ps1 -Site http://wss -SiteCollection Test -User Domain\User

PS > Remove-SPUser.ps1 -help

</strong>
</pre>
<p />
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2009/02/16/remove-sharepoint-users-programmatically-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Batch Creation of Sharepoint Sites Part 2</title>
		<link>http://www.powershell.nu/2009/02/09/batch-creation-of-sharepoint-sites-part-2/</link>
		<comments>http://www.powershell.nu/2009/02/09/batch-creation-of-sharepoint-sites-part-2/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 20:03:50 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=419</guid>
		<description><![CDATA[This is the second part of a Post started by Mattias Karlsson. Click Here to See Part One Following on Mattias lead, I&#8217;m going to describe how to build a script that automates the creation of 700+ Sites in sharepoint. The scenario is well described by Mattias so I&#8217;m just going to dig directly into [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mysharepointofview.com/2009/02/09/batch-creation-of-sharepoint-sites-part-1/">This is the second part of a Post started by Mattias Karlsson. Click Here to See Part One</a></p>
<p />
Following on Mattias lead, I&#8217;m going to describe how to build a script that automates<br />
the creation of 700+ Sites in sharepoint.</p>
<p />
The scenario is well described by Mattias so I&#8217;m just going to dig directly into the code.</p>
<p />
The first thing we want to consider is the Csv file. Since we work in a Swedish / Finnish Company, there are alot of funny looking characters and non-friendly names that could cause a problem in sharepoint. So step one is getting rid of all funnies. This is a perfect job for the -replace operator.</p>
<p />
<img src="http://www.powershell.nu/wp-content/uploads/2009/02/sharepoint-19.jpg" alt="sharepoint-19" title="sharepoint-19" width="407" height="162" class="alignnone size-full wp-image-422" /></p>
<p />
Importing the csv File to PowerShell is done through the Import-Csv CmdLet, as soon as we have imported the Csv file, we can edit each line in it.</p>
<p />
There are basically 2 steps that we want to do in Sharepoint, Adding information to a Directory List and creating Sites. The Directory list can be treated in the same way as we <a href="http://www.powershell.nu/2009/01/08/add-items-to-a-list-in-sharepoint/">altered Custom Lists in this post.</a></p>
<p />
The only &#8220;new&#8221; item that we want to add now is the URL, which takes 2 arguments, URL and Description.</p>
<p />
The Connections to Sharepoint are done in the same way as in previous examples, just make sure to change which list you want to connect to and where your SiteDirectory is.</p>
<p />
Creating Sites is described in this post. What&#8217;s new in this example is the Template that we want to use. In order to tell SharePoint that we want to build our sites based on a template file, we have to add the template as an argument to the Add() method.</p>
<p />
Now that we have gone through all the techniques set and ready, let&#8217;s put it all togheter in a ps1 script. The script consists of 3 functions, one Help function that describes how to use the ps1 script, one Csv function that imports the csv file and prepares it and finally a function that adds all data to sharepoint.</p>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2009/02/create-sites.ps1">Click here to download the Script.</a></p>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2009/02/companylistexample.csv">Click here to download a template Csv File</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2009/02/09/batch-creation-of-sharepoint-sites-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hiding a ListField in NewForm/EditForm in Sharepoint</title>
		<link>http://www.powershell.nu/2009/01/13/hiding-a-listfield-in-newformeditform-in-sharepoint/</link>
		<comments>http://www.powershell.nu/2009/01/13/hiding-a-listfield-in-newformeditform-in-sharepoint/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 20:49:52 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=290</guid>
		<description><![CDATA[Hiding a Field can be useful if you don&#8217;t want your Users to be able to edit a specific field. Mattias Karlsson, a friend of mine, describes a step-by-step on achieving this on his blog. In this Post, I&#8217;m going to describe how to do it through PowerShell. First make a connection to the specific [...]]]></description>
			<content:encoded><![CDATA[<p>Hiding a Field can be useful if you don&#8217;t want your Users to be able to edit a specific field. Mattias Karlsson, a friend of mine, describes a step-by-step on achieving this on his <a href="http://mattiaskarlsson.wordpress.com/2009/01/16/hide-form-fields-in-sharepoint/">blog</a>. In this Post, I&#8217;m going to describe how to do it through PowerShell. First make a connection to the specific Field, then simply set the ShowInNewForm and ShowInEditForm properties to $false. This will hide the fields from the User when the user is trying to create or edit a List Item.</p>
<p />
The image below shows the list that I&#8217;m going to edit. I will remove the UserField so that Users editing Items in this List won&#8217;t be able to edit the UserField</p>
<p />
<img class="alignnone size-large wp-image-293" title="sharepoint-171" src="http://www.powershell.nu/wp-content/uploads/2009/01/sharepoint-171-500x91.jpg" alt="sharepoint-171" width="500" height="91" /></p>
<p />
We can hide the fields through a simple function.</p>
<p />
<pre>
<strong>
function Hide-SPField([string]$url, [string]$List, [string]$Field) {
  [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

  $SPSite = New-Object Microsoft.SharePoint.SPSite($url)
  $OpenWeb = $SPSite.OpenWeb()

  $OpenList = $OpenWeb.Lists[$List]

  $OpenField = $OpenList.Fields[$Field]
  $OpenField.ShowInNewForm = $False
  $OpenField.ShowInEditForm = $False
  $OpenField.Update()

  $SPSite.Dispose()
  $OpenWeb.Dispose()
}

Hide-SPField -url http://moss -List "My Custom List" -Field "UserField"
</strong>
</pre>
<p />
Now, when the user clicks on New Item or Edit Item, the UserField won&#8217;t be visible.</p>
<p />
<img class="alignnone size-large wp-image-295" title="sharepoint-18" src="http://www.powershell.nu/wp-content/uploads/2009/01/sharepoint-18-500x235.jpg" alt="sharepoint-18" width="500" height="235" /></p>
<p />
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2009/01/13/hiding-a-listfield-in-newformeditform-in-sharepoint/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Add Site to TopNavigationBar in Sharepoint</title>
		<link>http://www.powershell.nu/2009/01/08/add-site-to-topnavigationbar-in-sharepoint/</link>
		<comments>http://www.powershell.nu/2009/01/08/add-site-to-topnavigationbar-in-sharepoint/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 15:20:51 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=217</guid>
		<description><![CDATA[When Adding a site to the TopNavigationBar, we need to create a New-Object using Navigation.SPNavigationNode. Here’s an example on adding a site to the TopNavigationBar. This is basically the same as when adding the Site to the QuickLaunch. function Add-SPSiteToTopNav([string]$url,[string]$Site,[string]$SiteURL) { [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") $SPSite = New-Object Microsoft.SharePoint.SPSite($url) $OpenWeb = $SpSite.OpenWeb() $TopNavBar = $OpenWeb.Navigation.TopNavigationBar $Node = New-Object [...]]]></description>
			<content:encoded><![CDATA[<p>When Adding a site to the TopNavigationBar, we need to create a New-Object using Navigation.SPNavigationNode. Here’s an example on adding a site to the  TopNavigationBar. This is basically the same as when adding the Site to the QuickLaunch.</p>
<p />
<pre>
<strong>
function Add-SPSiteToTopNav([string]$url,[string]$Site,[string]$SiteURL) {

  [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

  $SPSite = New-Object Microsoft.SharePoint.SPSite($url)
  $OpenWeb = $SpSite.OpenWeb()

  $TopNavBar = $OpenWeb.Navigation.TopNavigationBar

  $Node = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode $Site, $SiteUrl, 1
  $TopNavBar.AddAsLast($Node)

  $SPSite.Dispose()
  $OpenWeb.Dispose()
}

Add-SPSiteToTopNav -url http://wss -Site TheBlog -SiteURL http://wss/TheBlog
</strong>
</pre>
<p />
<img class="alignnone size-large wp-image-218" title="sharepoint-16" src="http://www.powershell.nu/wp-content/uploads/2009/01/sharepoint-16-500x60.jpg" alt="sharepoint-16" width="500" height="60" /></p>
<p />
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2009/01/08/add-site-to-topnavigationbar-in-sharepoint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
