About Me

Calgary, Alberta, Canada
Some know me as Phani, many know me as 'PK'… Mr.Perfect

Thursday, November 11, 2010

Lab 1 - Working with PowerShell scripts



Setup - Development environment


Please follow this link to set up the development environment.


Exercise 1: Open PowerShell Console
1.       1. Create a folder for all the Labs. (In my RIG it is “D:\PK Blog\Labs\Lab 1 – Powershell” )
2.       2. Launch the PowerShell console from Windows Start menu.  
                You’ll find the PowerShell Shortcut at Start >> All Programs >> Accessories >> Windows              
                 PowerShell >> Windows Powershell.
3.       3. Once you have a command prompt in the windows PowerShell console window, type the following
                command using the Set-Location cmdlet
                 Set-Location "D:\PK Blog\Labs\Lab 1 - Powershell"
4.       4. The current folder of the Windows PowerShell console should now be located to the folder created in  
                 step 1.
5.       5. To see a listing of all ps1 files, type the below command. 
                Get-ChildItem
Exercise 2: Hello World Example
1.       1. Type Notepad HelloWorld.ps1 and press enter.
2.       2. Console prompts to create a new file or not.
6.       3. Copy and paste the below code in the .
$HelloWorld = "Hello World - PowerShell Scripting"
write-host "--------------------------"
write-host $HelloWorld
write-host "--------------------------"
7.        4. Run Hello.ps1

 Exercise 3: Load Snapin script
1.       1. Type Notepad LoadSharePointSnapIn.ps1 and press enter.
2.       2. Console prompts to create a new file or not.
3.       3. Copy and paste the below code in the notepad.
write-host "--------------------------"
write-host "Loading SharePoint Snapin"
Add-PSSnapin Microsoft.SharePoint.PowerShell
write-host "SharePoint Snapin Loaded"
write-host "--------------------------"
4.       4. Save the file
5.       5.  Run LoadSharePointSnapIn.Ps1. Type “LoadSharePointSnapIn.Ps1” and Press enter.
  
Now you will be able to use all the SharePoint 2010 cmdlets.


Exercise 4: cmdlets included in Microsoft.sharepoint.PowerShell
1.       Run the below command to list all the cmdlets included in Microsoft.SharePoint.PowerShell
Get-Command -PSSnapin Microsoft.SharePoint.PowerShell

2.       Try running again the below command to list all the cmdlets based on the verb of Get

            Get-Command -PSSnapin Microsoft.SharePoint.PowerShell –verb Get

3.       Try running the below command with verb parameter and pipe the output to a text file.

            Get-Command -PSSnapin Microsoft.SharePoint.PowerShell –verb Get | out-file –filepath “

Exercise 5: SharePoint Site Collection Creation using New-SPSite
Before starting this exercise, let us run the following command to get help information on the New-SPSite cmdlet which will show you a list of parameters and indicate which ones are mandatory and which ones are optional.

Note: The optional parameters are enclosed in square brackets

Get-Help New-SPSite


1.       1. Type Notepad SiteProvision.ps1 and press enter.
2.       2. Console confirms to create a new file or notepad.
3.       3. Copy and paste the below code in the notepad.
write-host "--------------------------"
write-host "Site Provisioning started"
New-SPSite http://kshaunish/sites/Lab1 -OwnerAlias "ADDALA\Administrator" -Language 1033 -Template STS#1 -Name Lab1
write-host "Site has been provisioned"
write-host "--------------------------"

4.       4. Save the file
5.       5.  Run SiteProvision.Ps1. Type “SiteProvision.Ps1” and Press enter

Lab 1 site has been provisioned by the above script.

If you complete these exercises you will get some hands-on experience in working with some of the SP2010 Windows PowerShell cmdlets.


1 comment:

  1. Hi Phani,
    This is RaviPola, As per your instructions I am bale to create .PS1, but unable to run the same.
    Is any pre-requisites (Framework) are needed on my machine? as I am using Windows 7, Framework 2.0 and Visual Studio 2005 (Ajax 1.0).
    Please guide me on the same.

    Thank you,
    RaviPola.

    ReplyDelete