My first powershell script. The name says it all: it’s powerfull, you can do a lot with it. But what is Powershell:
Windows PowerShell is a new Windows command-line shell designed especially for system administrators. The Windows PowerShell includes an interactive prompt and a scripting environment that can be used independently or in combination.Unlike most shells, which accept and return text, Windows PowerShell is built on top of the .NET Framework common language runtime (CLR) and the .NET Framework, and accepts and returns .NET Framework objects. This fundamental change in the environment brings entirely new tools and methods to the management and configuration of Windows.Windows PowerShell introduces the concept of a cmdlet (pronounced “command-let”), a simple, single-function command-line tool built into the shell. You can use each cmdlet separately, but their power is realized when you use these simple tools in combination to perform complex tasks. Windows PowerShell includes more than one hundred basic core cmdlets, and you can write your own cmdlets and share them with other users.Like many shells, Windows PowerShell gives you access to the file system on the computer. In addition, Windows PowerShell providers enable you to access other data stores, such as the registry and the digital signature certificate stores, as easily as you access the file system.
Working with Sharepoint, you can do most of the things STSADM does, and much more. A good starting point is the Powershell reference for Sharepoint by technet. Also a nice overview and collection of resources in this article by “sharepoint Joel”, from the very beginner to more advanced.
My first script simply installs all wsp file located in a dropfolder  (remove and uninstall first).

<code> $snapin = Get-PSSnapin | Where-Object {$_.Name -eq ‘Microsoft.SharePoint.Powershell’} if ($snapin -eq $null) { Write-Host “Loading SharePoint Powershell” Add-PSSnapin “Microsoft.SharePoint.Powershell” } $dir = "C:\solution\20101117.3" $WebAppUrl = "http://r95ffy1"; Write-Host “install all wsps in $dir” $list = Get-ChildItem $dir | where {$_.extension -eq ".wsp"} foreach($solutionFile in $list){ Write-Host "remove solution $solutionFile..." $targetSolution = Get-SPSolution | Where-Object {$_.Name -eq $solutionFile} if ($targetSolution.Deployed -eq “True”) { Write-Host “Uninstalling existing solution package: ” $targetSolution.Name if ($targetSolution.ContainsWebApplicationResource) { Uninstall-SPSolution -identity  $targetSolution.Name -allwebapplications -Confirm:$false } else { Uninstall-SPSolution -identity  $targetSolution.Name -Confirm:$false } while ($targetSolution.Deployed) { start-sleep -s 15 write-host "Waiting for Retraction to Complete" } start-sleep -s 15 write-host "Deleting Solution: " $targetSolution.Name Remove-SPSolution $targetSolution -Confirm:$false } start-sleep -s 15 Write-Host “Adding solution package $solutionFile ” Add-SPSolution $dir\$solutionFile $targetSolution = Get-SPSolution | Where-Object {$_.Name -eq $solutionFile} if ($targetSolution){ Write-Host “Installing solution $solutionFile” if ($targetSolution.ContainsWebApplicationResource) { Install-SPSolution -Identity $targetSolution.Name –WebApplication $WebAppUrl -GACDeployment -force } else { Install-SPSolution -Identity $targetSolution.Name -GACDeployment -force } } } Write-Host "Press any key to continue ..." $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") </code>