<?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</title>
	<atom:link href="http://www.powershell.nu/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>PowerShell MVP</title>
		<link>http://www.powershell.nu/2010/07/04/powershell-mvp/</link>
		<comments>http://www.powershell.nu/2010/07/04/powershell-mvp/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 15:22:08 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[Community]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=1016</guid>
		<description><![CDATA[Got back from a vacation in Australia today and found out that I had an e-mail from Microsoft in my inbox containing the following: Dear Niklas Goude, Congratulations! We are pleased to present you with the 2010 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, [...]]]></description>
			<content:encoded><![CDATA[<p>Got back from a vacation in Australia today and found out that I had an e-mail from Microsoft in my inbox containing the following:</p>
<p><em>Dear Niklas Goude,</em></p>
<p><em>Congratulations! We are pleased to present you with the 2010 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions in PowerShell technical communities during the past year.</em></p>
<p>It feels amazing receiving this award and Im really happy to be a part of the PowerShell MVP&#8217;s.</p>
<p>Thank You!</p>
<p><img class="alignnone size-full wp-image-1017" title="image_3" src="http://www.powershell.nu/wp-content/uploads/2010/07/image_3.png" alt="" width="579" height="81" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2010/07/04/powershell-mvp/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<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>Swedish PowerShell book release</title>
		<link>http://www.powershell.nu/2010/04/04/swedish-powershell-book-release/</link>
		<comments>http://www.powershell.nu/2010/04/04/swedish-powershell-book-release/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 14:02:05 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[Book]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=997</guid>
		<description><![CDATA[I&#8217;ve finally completed the first Swedish PowerShell book. I released it on TechDays Sweden, where we gave it away for free and now I&#8217;ve released the book as an e-book. You can download the book at www.powershell.se or at www.powershell.nu. The book focuses on getting started with Windows PowerShell and includes: Basic cmdlets, parameters, pipelines, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve finally completed the first Swedish PowerShell book. I released it on TechDays Sweden, where we gave it away for free and now I&#8217;ve released the book as an e-book. You can download the book at <a href="http://www.powershell.se">www.powershell.se</a> or at <a href="http://www.powershell.nu/swedish-e-book/">www.powershell.nu</a>.</p>
<p />
The book focuses on getting started with Windows PowerShell and includes: Basic cmdlets, parameters, pipelines, functions, filters, security, writing scripts, learning .NET, WMI, COM and much more. The last chapter in the book focuses on how to administrate Windows environments through PowerShell which includes: managing folders and files, acl, services, eventlogs, processes, the registry, windows forms, Active Directory, Microsoft SQL Server, New functionality in Windows 7 and much more.</p>
<p />
Note that the book is written in Swedish, so you might want to run it through google translator.. <img src='http://www.powershell.nu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p />
Happy Reading.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2010/04/04/swedish-powershell-book-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Announcements to SharePoint 2010 through PowerShell</title>
		<link>http://www.powershell.nu/2010/01/27/adding-announcements-to-sharepoint-2010-through-powershell/</link>
		<comments>http://www.powershell.nu/2010/01/27/adding-announcements-to-sharepoint-2010-through-powershell/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 21:59:07 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[SharePoint 2010]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=969</guid>
		<description><![CDATA[SharePoint 2010 is on it&#8217;s way and it&#8217;s way cool. Lots of great CmdLets that simplify the SharePoint administrators life. In this post we are going to check out how to add Announcements to an Announcements list in SharePoint through PowerShell. First we&#8217;ll do it step-by-step in the &#8220;SharePoint 2010 Management Shell&#8221; (PowerShell shell that [...]]]></description>
			<content:encoded><![CDATA[<p>SharePoint 2010 is on it&#8217;s way and it&#8217;s way cool. Lots of great CmdLets that simplify the SharePoint administrators life. In this post we are going to check out how to add Announcements to an Announcements list in SharePoint through PowerShell. First we&#8217;ll do it step-by-step in the &#8220;SharePoint 2010 Management Shell&#8221; (PowerShell shell that registers SharePoint CmdLets) and then we&#8217;ll look at a script that automates the task.</p>
<p />
First, start the SharePoint 2010 Management Shell.</p>
<p />
Now we can get fancy with SharePoint administration. Adding a new announcement is done basically in the same way as in MOSS, though it&#8217;s alot simpler since Microsoft added tons of new great SharePoint CmdLets. Below is an example on adding a new announcement to a SharePoint list.</p>
<p />
<pre>
<strong>
PS > $siteScope = Start-SPAssignment
PS > $Announcement = ($siteScope | Get-SPWeb -identity http://sharepoint).Lists["Announcements"]
PS > $NewItem = $Announcement.Items.Add()
PS > $NewItem["Title"] = "My First Announcement"
PS > $NewItem["Body"] = "&lt;h2&gt;PowerShell Magic&lt;/h2&gt;"
PS > $NewItem["Expires"] = "1/28/2010"
PS > $NewItem.Update()
PS > Stop-SPAssignment $siteScope
</strong>
</pre>
<p />
The Start-SPAssignment and Stop-SPAssignment should be used with certain objects such as SPSite, SPWeb and SPSiteAdministration, since they need to be disposed. You can read more about the CmdLets at the <a href="http://cglessner.blogspot.com/2009/11/sharepoint-2010-powershell-and.html">I Love SharePoint blog.</a></p>
<p />
The rest of the code is pretty straightforward, Get the Web through Get-SPWeb, create an object holding the List, use the Add() method, add the information and finally update the new item using the Update() method.</p>
<p />
Here&#8217;s what it looks like in the Shell.</p>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2010/01/Announcement.jpg"><img src="http://www.powershell.nu/wp-content/uploads/2010/01/Announcement-500x140.jpg" alt="Announcement" title="Announcement" width="500" height="140" class="alignnone size-large wp-image-971" /></a></p>
<p />
And here&#8217;s our new Item in SharePoint.</p>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2010/01/Announcement2.jpg"><img src="http://www.powershell.nu/wp-content/uploads/2010/01/Announcement2-499x311.jpg" alt="Announcement2" title="Announcement2" width="499" height="311" class="alignnone size-large wp-image-972" /></a></p>
<p />
When put in a script, we can simply add a new announcement on a single line.</p>
<p />
<pre>
<strong>
PS > Add-SharePointAnnouncement.ps1 -identity http://sharepoint -List Announcements -Title "Added From Script" `
>> -Body "&lt;h2&gt;PowerShell Scripts Rock&lt;/h2&gt;" -Expires 1/28/2010
</strong>
</pre>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2010/01/Add-SharePointAnnouncement.ps1">Click here to download the script.</a></p>
<p />
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2010/01/27/adding-announcements-to-sharepoint-2010-through-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running Scripts with arguments in PowerShell</title>
		<link>http://www.powershell.nu/2009/12/16/running-scripts-with-arguments-in-powershell/</link>
		<comments>http://www.powershell.nu/2009/12/16/running-scripts-with-arguments-in-powershell/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 16:34:19 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[Basics]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=924</guid>
		<description><![CDATA[Here&#8217;s a short guide on running scripts in powershell. The guide is divided into three parts: Running Scripts from the Console Running Scripts from Start/Run Running Scripts as Backgournd Jobs in PowerShell First, let&#8217;s look at the script examples that we want to run. Here&#8217;s the first script: ################## # # Script 1 # ################## [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a short guide on running scripts in powershell. </p>
<p />
The guide is divided into three parts:</p>
<ul>
<li>Running Scripts from the Console</li>
<li>Running Scripts from Start/Run</li>
<li>Running Scripts as Backgournd Jobs in PowerShell</li>
</ul>
<p />
First, let&#8217;s look at the script examples that we want to run.</p>
<p />
Here&#8217;s the first script:</p>
<p />
<pre>
##################
#
# Script 1
#
##################

"Arguments: $($args.count)"
$args
</pre>
<p />
And here&#8217;s the second script:</p>
<p />
<pre>
##################
#
# Script 2
#
##################

param($Argument1,$Argument2)

"Argument1 is: $Argument1"
"Argument2 is: $Argument2"
</pre>
<p />
Script 1 uses $args variable to handle arguments. This is a automatic Variable created by PowerShell. It will handle any arguments that are passed to the script.<br />
<br />
Script 2 uses a param statement. the param statement let&#8217;s us define variables that hold our arguments. The variables are available throughout the script.</p>
<p />
<h2>Running Scripts from the Console</h2>
<p />
Now, let&#8217;s look at a couple of different ways of running scripts from the PowerShell console.</p>
<p />
<pre>
<strong>
PS > C:\temp\Scripts\script1.ps1 Hello World
</strong>
Arguments: 2
Hello
World
</pre>
<p />
In the example, we triggered the script with two arguments, Hello and World. If we instead want Hello World to pass as a single argument, we can use quotation marks:</p>
<p />
<strong><br />
PS > C:\temp\Scripts\script1.ps1 &#8220;Hello World&#8221;<br />
</strong><br />
Arguments: 1<br />
Hello World
</pre>
<p />
In this example, There's only one argument passed to the script since "Hello World" is within quotation marks.</p>
<p />
Obviously, we can use variables as arguments.</p>
<p />
<pre>
<strong>
PS > $HelloWorld = "Hello World"
PS > $Hello = "Hello"
PS > $World = "World"

PS > C:\temp\Scripts\script1.ps1 $HelloWorld
</strong>
Arguments: 1
Hello World
</pre>
<p />
When we enter $HelloWorld, the value of the $HelloWorld variable is passed on as one argument to the script.</p>
<p />
If we instead use the Variables $Hello and $World, they will be handled as two different arguments.</p>
<pre>
<strong>
PS > C:\temp\Scripts\script1.ps1 $Hello $World
</strong>
Arguments: 2
Hello
World
</pre>
<p />
If we put the variables within quotation marks, they will be passed on to the script as one single argument.</p>
<pre>
<strong>
PS > C:\temp\Scripts\script1.ps1 "$Hello $World"
</strong>
Arguments: 1
Hello World
</pre>
<p />
Using Single Quotation takes passes the argument exactly as written, in other words, the Argument will be $Hello $World and not the values of the variables.</p>
<p />
<pre>
<strong>
PS > C:\temp\Scripts\script1.ps1 '$Hello $World'
</strong>
Arguments: 1
$Hello $World
</pre>
<p />
It's possible to achieve this when using Double Quotation marks. Just add a backtrick character in front of the variables.</p>
<p />
<pre>
<strong>
PS > C:\temp\Scripts\script1.ps1 "`$Hello `$World"
</strong>
Arguments: 1
$Hello $World
</pre>
<p />
Let's look at a few examples on running Script 2 from the console. Script 2 uses the param statement.</p>
<p />
<pre>
<strong>
PS > C:\temp\Scripts\script2.ps1 Hello World
</strong>
Argument1 is: Hello
Argument2 is: World
</pre>
<p />
In this example, Hello is assigned to $Argument1 and World is Assigned to $Argument2</p>
<p />
<pre>
<strong>
PS > C:\temp\Scripts\script2.ps1 "Hello World"
</strong>
Argument1 is: Hello World
Argument2 is:
</pre>
<p />
If we put Hello World in double quotation marks, both Hello and World are assigned to $Argument1. $Argument2 is empty.</p>
<p />
It's also possible to use the param variables as parameters to the script as the examples below show.</p>
<p />
<pre>
<strong>
PS > C:\temp\Scripts\script2.ps1 -Argument1 Hello -Argument2 World
</strong>
Argument1 is: Hello
Argument2 is: World
</pre>
<p />
If we only specify one parameter the second will automatically be assigned to the first variable in the param that doesn't have a value.</p>
<p />
<pre>
<strong>
PS > C:\temp\Scripts\script2.ps1 -Argument1 Hello World
</strong>
Argument1 is: Hello
Argument2 is: World
<strong>
PS > C:\temp\Scripts\script2.ps1 -Argument2 World Hello
</strong>
Argument1 is: Hello
Argument2 is: World
</pre>
<p />
You can, of course, use quotation marks here as well.</p>
<p />
<pre>
<strong>
PS > C:\temp\Scripts\script2.ps1 -Argument1 "Hello World"
</strong>
Argument1 is: Hello World
Argument2 is:
</pre>
<p />
What if the Path to the script contains spaces ?. Let's see what happens. in these examples I've changed the path to the scripts to C:\Temp\Example Scripts\</p>
<p />
<pre>
<strong>
PS > C:\temp\Example Scripts\script1.ps1 "Hello World"
</strong>
The term 'C:\temp\Example' is not recognized as the name..
</pre>
<p />
so this didn't work. It's because PowerShell separates commands with a space, so it tries to run the command C:\Temp\Example. You can solve this by using quotation marks and a Call Operator. without the Call Operator, PowerShell will handle the script path as a string value.</p>
<p />
<pre>
<strong>
PS > &#038; "C:\temp\Example Scripts\script1.ps1" "Hello World"
</strong>
Arguments: 1
Hello World
</pre>
<p />
Script2 can be triggered in the same way, note that the arguments are after the scriptpath and not within quotation marks.</p>
<p />
<pre>
<strong>
PS > &#038; "C:\temp\Example Scripts\script2.ps1" -Argument1 Hello -Argument2 World
</strong>
Argument1 is: Hello
Argument2 is: World
</pre>
<p />
Another way of running scripts is if you're in the same directory as the scripts are located. Then you can simply use the .\ notation in front of the script.</p>
<p />
<pre>
<strong>
PS > cd 'C:\temp\Example Scripts\'
PS > .\script1.ps1 "Hello World"
</strong>
Arguments: 1
Hello World
</pre>
<p />
The easist way to run scripts is if you include the scriptpath in the environment PATH.</p>
<p />
<pre>
<strong>
$Env:PATH = $Env:PATH + ";C:\Temp\Example Scripts"
</strong>
</pre>
<p />
Now we can simply type the name of the script to run it.</p>
<p />
<pre>
<strong>
PS > script2.ps1 -Argument1 Hello -Argument2 World
</strong>
Argument1 is: Hello
Argument2 is: World
</pre>
<p />
You don't even have to type the script extension when running the scripts.</p>
<p />
<pre>
<strong>
PS > script2 -Argument1 Hello -Argument2 World
</strong>
Argument1 is: Hello
Argument2 is: World
</pre>
<p />
<h2>Running Scripts from Start/Run</h2>
<p />
You can also trigger scripts from Start / Run in Windows. Here are a couple of examples on how we can run our scripts from Start / Run. The NoExit switch is used in these examples so that we can check the result easily. </p>
<p />
<pre>
<strong>
powershell.exe -noexit C:\temp\Scripts\script1.ps1 Hello World
</strong>
</pre>
<p />
When running Scripts that are in a path that doesn't include spaces you can simply type the scripts FullPath followed by the arguments as shown in the example above. But what if you want "Hello World" to be handled as just one argument?</p>
<p />
<pre>
<strong>
powershell.exe -noexit C:\temp\Scripts\script1.ps1 "Hello World"
</strong>
</pre>
<p />
If we type "Hello World" inside double quotation marks it's still handled as two different arguments. We can solve this by using Single Quotation Marks.</p>
<p />
<pre>
<strong>
powershell.exe -noexit C:\temp\Scripts\script1.ps1 'Hello World'
</strong>
</pre>
<p />
Let's see how this works with the script that uses a param.</p>
<p />
<pre>
<strong>
powershell.exe -noexit C:\temp\Scripts\script2.ps1 Hello World
</strong>
</pre>
<p />
This works just fine, lets specify the parameters in the script as well.</p>
<p />
<pre>
<strong>
powershell.exe -noexit C:\temp\Scripts\script2.ps1 -Argument1 Hello -Argument2 World
</strong>
</pre>
<p />
And, as you can see, this works fine as well. Now let's see what happens if we double quote on of the arguments.</p>
<p />
<pre>
<strong>
powershell.exe -noexit C:\temp\Scripts\script2.ps1 -Argument1 "Hello World" -Argument2 Monkey
</strong>
</pre>
<p />
This returns Hello as Argument1 and Monkey as Argument2. World is not in the script ouput. Now let's do the same example with single quotation marks.</p>
<p />
<pre>
<strong>
powershell.exe -noexit C:\temp\Scripts\script2.ps1 -Argument1 'Hello World' -Argument2 Monkey
</strong>
</pre>
<p />
Now we got the result that we wanted. So lesson learned from this is: use single quotation marks when passing arguments containing spaces.</p>
<p />
Now let's test this with the scripts containing spaces in the script path.</p>
<p />
<pre>
<strong>
powershell.exe -noexit C:\temp\Example Scripts\script1.ps1 "Hello World"
</strong>
</pre>
<p />
This didn't work since the path contains spaces, now let's try it with double quotes at first.</p>
<p />
<pre>
<strong>
powershell.exe -noexit "C:\temp\Example Scripts\script1.ps1" "Hello World"
</strong>
</pre>
<p />
Still no luck, lets try adding the Call Operator.</p>
<p />
<pre>
<strong>
powershell.exe -noexit &#038; "C:\temp\Example Scripts\script1.ps1" "Hello World"
</strong>
</pre>
<p />
In order to get it right, we have to use single quotation marks.</p>
<p />
<pre>
<strong>
powershell.exe -noexit &#038; 'C:\temp\Example Scripts\script1.ps1' "Hello World"
</strong>
</pre>
<p />
Note that Hello World is handled as two different arguments. Whe can solve this by typing Hello World within single quotation marks.</p>
<p />
<pre>
<strong>
powershell.exe -noexit &#038; 'C:\temp\Example Scripts\script1.ps1' 'Hello World'
</strong>
</pre>
<p />
Script 2, that uses the param statement works in the same way.</p>
<p />
<pre>
<strong>
powershell.exe -noexit &#038; 'C:\temp\Example Scripts\script2.ps1' -Argument1 Hello -Argument2 World

powershell.exe -noexit &#038; 'C:\temp\Example Scripts\script2.ps1' -Argument1 'Hello World'  -Argument2 Monkey
</strong>
</pre>
<p />
Finally, let's see what happens if we run scripts included in the $Env:PATH variable.</p>
<p />
First, we should add the script path to our profile so that it's loaded when powershell starts. Just Add $Env:PATH = $Env:PATH + ";C:\Temp\Example Scripts" into your profile.ps1 file.</p>
<p />
<pre>
<strong>
powershell.exe -noexit script1.ps1 'Hello World'

powershell.exe -noexit script2.ps1 -Argument1 Hello -Argument2 World
</strong>
</pre>
<p />
We can even run the scripts without the extension.</p>
<p />
<pre>
<strong>
powershell.exe -noexit script1 'Hello World'

powershell.exe -noexit script2 -Argument1 Hello -Argument2 World
</strong>
</pre>
<p />
Adding a script path to the $Env:PATH variable makes it alot more simple to run scripts in PowerShell.</p>
<p />
<h2>Running Scripts as Backgournd Jobs in PowerShell</h2>
<p />
Let's take a look on how to run scripts as background Jobs. PowerShell v2 includes a great cmdlet callet Start-Job. It let's us run Jobs in the background. We can use this to run our scripts as background jobs.</p>
<p />
Let's take a look on How to Run Scripts witth Start-Job.</p>
<pre>
<strong>
PS > $Job1 = Start-Job .\script1.ps1 -ArgumentList Hello,World
</strong>
</pre>
<p />
By placing the command in a variable, we can easily access the Job informationm, check for status and use it to retrieve the output of the command. Start-Job Doesn't return the Job Result when completed so we have to use Receive-Job to get the Result from the Script.</p>
<p />
<pre>
<strong>
PS > Receive-Job $Job1.ID
Arguments: 2
Hello
World
PS > Receive-Job $Job1.ID
PS >
</strong>
</pre>
<p />
When we run the Receive-Job CmdLet and use the Jobs ID as argument, we get the Result from the Job Returned. Note that if we run the same command again, we don't get anything returned. This is becauese Receive-Job, by default, deletes the Returned information after it's accessed. We can bypass this with the -Keep switch.</p>
<p />
<pre>
<strong>
PS > $Job1 = Start-Job .\script1.ps1 -ArgumentList Hello,World
PS > Receive-Job $Job1.ID -Keep
Arguments: 2
Hello
World
PS > Receive-Job $Job1.ID -Keep
Arguments: 2
Hello
World
</strong>
</pre>
<p />
To Close the Session, run the Receive-Job command without the -Keep switch or use the Remove-Job CmdLet as shown below.</p>
<p />
<pre>
<strong>
PS > Remove-Job $Job1.ID
</strong>
</pre>
<p />
So how to solve this without PowerShell V2 installed ? well, we could always use Wscript.Shell. Here's an example on running backgroundjobs with wscript.shell.</p>
<p />
<pre>
<strong>
PS > $Wscript = New-Object -Com Wscript.Shell
PS > $Command = "powershell.exe &#038; 'C:\temp\Example Scripts\script2.ps1' -Argument1 'Hello' -Argument2 'World'"
PS > $Wscript.Run($command,0,$False)
0
</strong>
</pre>
<p />
So how do we varify that the script actually runs ? Well, we can solve this with a simple pipeline.</p>
<p />
<pre>
<strong>
PS > $Wscript = New-Object -Com Wscript.Shell
PS > $OutFile = "C:\temp\output.txt"
PS > $Command = "powershell.exe &#038; 'C:\temp\Example Scripts\script2.ps1' -Argument1 'Hello' -Argument2 'World' | Out-File $OutFile"
PS > $Wscript.Run($command,0,$False)
</strong>
0
<strong>
PS > Get-Content $OutFile
</strong>
Argument1 is: Hello
Argument2 is: World
</pre>
<p />
Hope you find this guide useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2009/12/16/running-scripts-with-arguments-in-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>#SEF09</title>
		<link>http://www.powershell.nu/2009/11/19/sef09/</link>
		<comments>http://www.powershell.nu/2009/11/19/sef09/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 14:02:53 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=917</guid>
		<description><![CDATA[First of all I would like o thank all the great people that attended the SharePoint and Exchange Forum 2009 here in Stockholm, Sweden. Special Thanks to Göran Husman, Everyone at Humandata and all sponsors. Great work! The international Speakers included Joel Oleson, Eric Shupps, Todd Klindt, Steve Smith and Penny Coventry. On the Swedish [...]]]></description>
			<content:encoded><![CDATA[<p>First of all I would like o thank all the great people that attended the SharePoint and Exchange Forum 2009 here in Stockholm, Sweden.<br />
Special Thanks to <a href="http://itbloggen.se/cs/blogs/ghusman/default.aspx">Göran Husman</a>, Everyone at <a href="http://www.humandata.se">Humandata</a> and all sponsors. Great work!</p>
<p />
The international Speakers included <a href="http://www.sharepointjoel.com/">Joel Oleson</a>, <a href="http://www.sharepointcowboy.com/">Eric Shupps</a>, <a href="http://www.toddklindt.com/">Todd Klindt</a>, <a href="http://suguk.org/blogs/combined_knowledge/default.aspx">Steve Smith</a> and <a href="http://sharepoint.mindsharpblogs.com/Penny/default.aspx">Penny Coventry</a>.<br />
On the Swedish team we got some great sessions from <a href="http://www.wictorwilen.se/">Wictor Wilén</a>, <a href="http://www.zimmergren.net">Tobias Zimmergren</a> and, of course, <a href="http://itbloggen.se/cs/blogs/ghusman/default.aspx">Göran Husman.</a></p>
<p />
My session on SharePoint &#038; PowerShell went well.. almost. The night before my presentation I decided to run through all my code examples one last time, which resultet in a USB-Disc crash. Unlucky for me was that my VMWare was stored on the USB-Disc.<br />
So after half an hour of panic, 3 hours of installation and 1 hour of testing i finally got everything in place, just in time to get my morning coffee and head off to SEF. Anyway, you can <a href="http://www.powershell.nu/wp-content/uploads/2009/11/SEF.zip">download my presentation here</a> or on <a href="http://www.seforum.se">www.seforum.se</a></p>
<p />
Hope to see all y&#8217;all next year!</p>
<p />
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2009/11/19/sef09/feed/</wfw:commentRss>
		<slash:comments>0</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>Scripting PDF Documents through PowerShell</title>
		<link>http://www.powershell.nu/2009/09/08/scripting-pdf-documents-through-powershell/</link>
		<comments>http://www.powershell.nu/2009/09/08/scripting-pdf-documents-through-powershell/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 11:06:00 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[PDF]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=801</guid>
		<description><![CDATA[Microsoft Office Supports Scripting possibilities through Com Objects. But what about PDF Documents ? Luckily there is a DLL available for download that let&#8217;s us Create PDF documents through .NET First you have to Download the ITextSHarp.dll Next, Time for some PowerShell Magic. Step One: Load the DLL. PS > [System.Reflection.Assembly]::LoadFrom("C:\itextsharp\itextsharp.dll") Step Two: Create a [...]]]></description>
			<content:encoded><![CDATA[<p>Microsoft Office Supports Scripting possibilities through Com Objects. But what about PDF Documents ? Luckily there is a DLL available for download that let&#8217;s us Create PDF documents through .NET</p>
<p />
First you have to <a href="http://sourceforge.net/projects/itextsharp/">Download the ITextSHarp.dll</a></p>
<p />
Next, Time for some PowerShell Magic.</p>
<p />
<strong>Step One:</strong> Load the DLL.</p>
<p />
<pre>
<strong>
PS > [System.Reflection.Assembly]::LoadFrom("C:\itextsharp\itextsharp.dll")
</strong>
</pre>
<p><strong>Step Two:</strong> Create a Variable holding the iTextSharp.text.Document Object</p>
<p />
<pre>
<strong>
PS > $Doc = New-Object iTextSharp.text.Document
</strong>
</pre>
<p />
<strong>Step Three:</strong> Create a PDF Document with a connection to the $Doc variable</p>
<p />
<pre>
<strong>
PS > [void][iTextSharp.text.pdf.PdfWriter]::GetInstance($Doc, [System.IO.File]::Create("C:\PDF\Goude.pdf") )
</strong>
</pre>
<p />
<strong>Step Four:</strong> Open The Document ( In order to add information to the PDF File )</p>
<p />
<pre>
<strong>
PS > $Doc.Open()
</strong>
</pre>
<p />
<strong>Step Five:</strong> Create a Text Chunk and append Text to Display in Pdf Document</p>
<p />
<pre>
<strong>
PS > $Chunk = New-Object iTextSharp.text.Chunk
PS > [void]$Chunk.Append(“Demo From PowerShell.nu”)
</strong>
</pre>
<p />
<strong>Step Six:</strong> Add the Chunk of Text, Set an Author with the AddAuthor() method and finally Close it with the Close() method</p>
<p />
<pre>
<strong>
PS > $Doc.Add($Chunk)
PS > $Doc.AddAuthor("Niklas Goude")
PS > $Doc.Close()
</strong>
</pre>
<p />
Voila, you now have a PowerShell made PDF File. You can, of course, create far more advanced PDF files containing tons of information. I&#8217;ll get back to this in a later Post.</p>
<p />
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2009/09/08/scripting-pdf-documents-through-powershell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Scripting Mp3 Tags through PowerShell</title>
		<link>http://www.powershell.nu/2009/09/04/scripting-mp3-metadata-through-powershell/</link>
		<comments>http://www.powershell.nu/2009/09/04/scripting-mp3-metadata-through-powershell/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 20:24:56 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[Media]]></category>
		<category><![CDATA[Media-Player]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=787</guid>
		<description><![CDATA[Structuring up you Music Library can be a rather time consuming task. You can however script this rather easily through PowerShell using the taglib-sharp library. Let&#8217;s start off by downloading the Tag-Lib Library Next, We have to Load the Assembly from PowerShell in order to access the Classes. PS > $TagLib = "C:\taglib\Libraries\taglib-sharp.dll" PS > [...]]]></description>
			<content:encoded><![CDATA[<p>Structuring up you Music Library can be a rather time consuming task. You can however script this rather easily through PowerShell using the <a href="http://developer.novell.com/wiki/index.php/TagLib_Sharp">taglib-sharp</a> library.</p>
<p />
Let&#8217;s start off by downloading the <a href="http://developer.novell.com/wiki/index.php/TagLib_Sharp">Tag-Lib Library</a><br />
Next, We have to Load the Assembly from PowerShell in order to access the Classes.</p>
<p />
<pre>
<strong>
PS > $TagLib = "C:\taglib\Libraries\taglib-sharp.dll"

PS > [System.Reflection.Assembly]::LoadFile($TagLib)
</strong>

GAC    Version        Location
---    -------        --------
False  v2.0.50727     C:\taglib\Libraries\taglib-sharp.dll
</pre>
<p />
Now that we&#8217;ve loaded the dll, we need a music file that we want to set properties on, in this example I&#8217;m going to use a mp3 file. If we check out the properties on the mp3 file, we can see that nothing is set.</p>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2009/09/taglib01.jpg"><img src="http://www.powershell.nu/wp-content/uploads/2009/09/taglib01.jpg" alt="taglib01" title="taglib01" width="377" height="515" class="alignnone size-full wp-image-788" /></a></p>
<p />
Let&#8217;s change this through PowerShell. We have to create a variable using the [Taglib.File] Class and use the filepath as an argument to the Create() method.</p>
<p />
<pre>
<strong>
PS > $Media  =  [TagLib.File]::Create("C:\Music\My Song.mp3")
</strong>
</pre>
<p />
The object contains a couple of Properties.</p>
<p />
<pre>
<strong>
PS > $Media
</strong>

Tag                    : TagLib.NonContainer.Tag
Properties             : TagLib.Properties
TagTypesOnDisk         : Id3v1, Id3v2
TagTypes               : Id3v1, Id3v2
Name                   : C:\temp\My Song.mp3
MimeType               : taglib/mp3
Tell                   : 0
Length                 : 0
InvariantStartPosition : 4608
InvariantEndPosition   : 7109078
Mode                   : Closed
</pre>
<p />
The one that We&#8217;re interested in is the Tag property, which contains additional underlaying properties and methods. Let&#8217;s check it out:</p>
<p />
<pre>
<strong>
PS > $Media.Tag
</strong>

StartTag             : TagLib.NonContainer.StartTag
EndTag               : TagLib.NonContainer.EndTag
TagTypes             : Id3v1, Id3v2
Tags                 : {Audiograbber 1.83.01, LAME d
                       v2.PrivateFrame TagLib.Id3v2.
Title                :
Performers           : {}
PerformersSort       : {}
AlbumArtistsSort     : {}
AlbumArtists         : {}
Composers            : {}
ComposersSort        : {}
TitleSort            :
AlbumSort            :
Album                :
Comment              :
Genres               : {}
Year                 : 0
Track                : 0
TrackCount           : 0
Disc                 : 0
DiscCount            : 0
Lyrics               :
Grouping             :
BeatsPerMinute       : 0
Conductor            :
Copyright            :
Pictures             : {}
IsEmpty              : True
Artists              : {}
FirstArtist          :
FirstAlbumArtist     :
FirstAlbumArtistSort :
FirstPerformer       :
FirstPerformerSort   :
FirstComposerSort    :
FirstComposer        :
FirstGenre           :
JoinedArtists        :
JoinedAlbumArtists   :
JoinedPerformers     :
JoinedPerformersSort :
JoinedComposers      :
JoinedGenres         :
</pre>
<p />
Let&#8217;s go ahead and set a couple of Values.</p>
<p />
<pre>
<strong>
PS > $Media.Tag.Performers = "Goude"
PS > $Media.Tag.AlbumArtists = "Goude"
PS > $Media.Tag.Artists = "Goude"
PS > $Media.Tag.Album = "My Album"
PS > $Media.Tag.Genres = "Rock"
PS > $Media.Tag.Track = "1"
PS > $Media.Tag.Title = "My Song"
PS > $Media.Tag.Year = "2009"
PS > $Media.Tag.Comment = "PowerShell Demo"
PS > $Media.Save()
</strong>
</pre>
<p />
If we check out the file properties through Explorer we&#8217;ll see that the properties are set on the file.</p>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2009/09/taglib02.jpg"><img src="http://www.powershell.nu/wp-content/uploads/2009/09/taglib02.jpg" alt="taglib02" title="taglib02" width="377" height="515" class="alignnone size-full wp-image-789" /></a></p>
<p />
So, editing one file is easy, but what if you want to edit a couple of thousand files..</p>
<p />
When I did this on my Media Files i used the Folder and File Names as reference. The folder and file structure was set up accordingly:</p>
<p />
<strong><br />
C:\Music\Rock\Artist1 &#8211; Album\01 &#8211; First Song.mp3<br />
C:\Music\Rock\Artist1 &#8211; Album\02 &#8211; Second Song.mp3<br />
C:\Music\Rock\Artist2 &#8211; Album\01 &#8211; First Song.mp3<br />
</strong></p>
<p />
So with this information i could make a script that Used this information in order to set the Tags. The script uses the &#8220;Rock&#8221; folder name as Genre, Then it Splits the &#8220;Artist &#8211; Album&#8221; folder and sets Artist = Artist and Album = Album, finally it splits the file name &#8220;01 &#8211; First Song.mp3&#8243; and sets Track = 01 and Title = First Song. I&#8217;ve also error handling in the script so that You can follow up on files that didn&#8217;t pass through the script.</p>
<p />
<a href = "http://www.powershell.nu/wp-content/uploads/2009/09/set-media.ps1">Click Here to download the Script</a></p>
<p />
Examples on Running the script:</p>
<p />
<pre>
<strong>
PS > Set-Media.ps1 -Folder C:\MyMusic\Rock -LogFile C:\Log\SetMediaLog.txt
</strong>
</pre>
<p />
Note! You can always modify the script to fit your own environment and folder structure.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2009/09/04/scripting-mp3-metadata-through-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Managing Local Groups through PowerShell</title>
		<link>http://www.powershell.nu/2009/07/06/managing-local-groups-through-powershell/</link>
		<comments>http://www.powershell.nu/2009/07/06/managing-local-groups-through-powershell/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 14:46:26 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[Client Management]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=781</guid>
		<description><![CDATA[When managing Local Groups through PowerShell, we can use the [ADSI] type adapter. Starting off, We have to connect to the Local Group that we want to modify. PS > $ComputerName = $env:COMPUTERNAME PS > $Group = "Administrators" PS > $LocalGroup = [adsi]"WinNT://$computerName/$Group,group" PS > $LocalGroup distinguishedName : Path : WinNT://Computer01/Administrators,group Now that we&#8217;re connected [...]]]></description>
			<content:encoded><![CDATA[<p>When managing Local Groups through PowerShell, we can use the [ADSI] type adapter.<br />
Starting off, We have to connect to the Local Group that we want to modify.</p>
<p />
<pre>
<strong>
PS > $ComputerName = $env:COMPUTERNAME
PS > $Group = "Administrators"
PS > $LocalGroup = [adsi]"WinNT://$computerName/$Group,group"
PS > $LocalGroup
</strong>

distinguishedName :
Path              : WinNT://Computer01/Administrators,group
</pre>
<p />
Now that we&#8217;re connected to the Local Group, we can start of by adding a user. First let&#8217;s add a Local User.</p>
<p />
<pre>
<strong>
PS > $Domain = "powershell"
PS > $UserName = "nigo"
PS > $LocalGroup.Add("WinNT://$Domain/$userName")
</strong>
</pre>
<p />
This adds the Domain user powershell\nigo to the local Administrators Group. If we instead want to add a Local User, we just replace the Domain Name with the Local COmputer Name.</p>
<p />
<pre>
<strong>
PS > $ComputerName = $env:COMPUTERNAME
PS > $LocalGroup.Add("WinNT://$ComputerName/$userName")
</strong>
</pre>
<p />
And if we want to remove a User from a local Group, we use the Remove() method.</p>
<p />
<pre>
<strong>
PS > $Domain = "powershell"
PS > $UserName = "nigo"
PS > $LocalGroup.Remove("WinNT://$Domain/$userName")
</strong>
</pre>
<p />
Here&#8217;s a script that automates these tasks.</p>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2009/07/set-localgroup.ps1">Click here to download the script.</a></p>
<p />
Here are some examples on running the script.</p>
<p />
<pre>
<strong>
PS > Set-LocalGroup.ps1 -UserName nigo -Add

PS > Set-LocalGroup.ps1 -UserName nigo -Remove

PS > Set-LocalGroup.ps1 -UserName nigo -Group "Guests" -Domain powershell -Add

PS > Set-LocalGroup.ps1 -help
</strong>
</pre>
<p />
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2009/07/06/managing-local-groups-through-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
