Wednesday, December 8, 2010

PowerShell Script for SharePoint 2010

I have just started playing with PowerShell few days back....after initial issues like:

What should i use:

1. PowerShell Console



2. PowerShell ISE


3. PowerGUI AdminConsole


4. PowerGUI Script Editor


5. PowerWF


6. PowerShell Plus


So no worries guys....you can just start with PowerShell ISE....don't download any other tool....till you understand basics of PowerShell for SharePoint 2010.

Below is the script for begineers: Just copy and paste this in to ISE window, make sure you have executed

get-pssnapin :). If you see some red lines in display

So here we are all set:

$sitename = Read-Host "Please Enter Site Name"



Write-Host "Site Name Entered is" $sitename


if($sitename -eq "")


{"Please enter a value"}


else
{"You entered "+ $sitename}

Read-Host: Reads data from user, You can take as many as input parameters from users. Like backup farm or backup site collection or backup a single list.

Lets say: backup a single list, ask the sitename and show all the lists inside it. Tell him to put any name and you can do backup.

Write-Host - Write to window.

No comments: