ĐÀO TẠO DOANH NGHIỆP : SỞ KHOA HỌC CÔNG NGHỆ TỈNH ĐỒNG NAI

ENTERPRISE TRAINING: DONG NAI DEPARTMENT OF SCIENCE AND TECHNOLOGY.

HÌNH ẢNH TẬP HUẤN LỚP SHAREPOINT WORKFLOW VÀ KIẾN TRÚC SHAREPOINT

PHOTOS OF SHAREPOINT WORKFLOW AND ARCHITECTURE CLASS.

HÌNH ẢNH TẬP HUẤN LỚP SHAREPOINT WORKFLOW VÀ KIẾN TRÚC SHAREPOINT

PHOTOS OF SHAREPOINT WORKFLOW AND ARCHITECTURE CLASS.

Tuesday, March 13, 2012

How to Create Sharepoint List And Add new – Edit – Delete Sharepoint Item list by Windows PowerShell ISE


Open Windows PowerShell ISE and paste this segment code to here then click Run Script
$web = get-spweb http://quochung-axioo:90
$web.Lists.Add(“PowerShellCustomList”,”Create SP List by Power Shell”,$web.ListTemplates["Custom List"])
$list = $web.Lists["PowerShellCustomList"]
$list.Fields.Add("LastName","Text","DO")
$list.Fields.Add("FirstName","Text","QuocHung")
$list.Fields.Add("Age","Number",25)
Run script succeeded
Open your sharepoint site and see your list was created
Edit view as follows:
Result as:
On ISE, new file .ps1 and paste this segment code to here then click run script
$spAssignment = Start-SPAssignment
$mylist = (Get-SPWeb -identity http://quochung-axioo:90 -AssignmentCollection $spAssignment).Lists["PowerShellCustomList"]
$newItem = $mylist.Items.Add()
$newItem["Title"] = “Added by Powershell”
$newItem["LastName"] = “QuocHung”
$newItem["FirstName"] = “Do”
$newItem["Age"] = 25
$newItem.Update()
Stop-SPAssignment $spAssignment
Go back your sharepoint list and see Item is added
Continue, New .PS1 and paste this segment code to here then click run script

$SPAssignment = Start-SPAssignment
$SPWeb = Get-SPWeb http://quochung-axioo:90 -AssignmentCollection $spAssignment
$SPList = $SPWeb.Lists["PowerShellCustomList"]
$SPItem = $SPList.GetItemById("1")
$SPItem["Title"] = "Edited by Powershell"
$SPItem.Update()
Stop-SPAssignment $SPAssignment
Go back your sharepoint list and see Item is Edited
Continue, New .PS1 and paste this segment code to here then click run script

$spList = Get-SPList -url "http://quochung-axioo:90/Lists/PowerShellCustomList"
$spListItem = $spList.GetItemById(1)
$spListItem.Delete()

Go back your sharepoint list and see Item is Deleted

How to run script sharepoint on powershell

Open Windows PowerShell ISE then paste segment code Get-SPSite to Command pane up  (View > Go to Command Pane)  as follows:
You see error because local user PowerShell ISE profile doesn’t create
Copy segment code and paste to Command pane up (View > Go to Command Pane) as follows:
# Creates a local user PowerShell ISE profile
if (!(test-path $profile ))
{new-item -type file -path $profile -force}
# opens it for edit
psEdit $profile
Completed
Save it (click to Icon Save)
Close and Open Again
Paste segment code “Get-SPSite” to Command pane up  (View > Go to Command Pane)  as follows:
Script run succeeded
You can copy “Get-SPSite” and paste to Script Pane (View -> Script Pane) then click “Run Script” Icon
Result as follows:
Save script
Exit ISE
Start ISE then open file .ps1
Choose your file
UI as follows
Result as follows:

How to install PowerShell Intergrated Scripting Environment (ISE)

Go to Start | Administrative Tools | Sever Manager | Right click to Feature | Add Features
Check to Windows PowerShell Intergrated Scripting Environment (ISE) then click Next
Click Install
Wait Installation Progress
Installation Succeeded
Click Start | Enter ISE to search Box
User interface (UI) as follows: