SharePoint site test Data Automation Series-Creating SharePoint List Items from PowerShell

Source: Internet
Author: User

The code is as follows (save to a local PS1 file, right-click Run with PowerShell):

add-PSSnapin microsoft.sharepoint.powershellfunction Createsplistitems () {$sites= get-SPSiteif($sites. Count-eq0) {Write-warning"There is no site available."Createsplistitems}Else{Write-host"Choose the site:"-Foregroundcolor Yellow for($i =0; $i-lt $sites. Count; $i + +) {$tip="["+ $i +"]."+$sites [$i].url Write-Host $tip} $choice= Read-host"Enter the number before"$tip="You chose"+ $choice +". "+"The site you chose is '"+ $sites [[int] $choice].url+"'"Write-host $tip-Foregroundcolor Green Write-host"Choose the Web:"-Foregroundcolor Yellow $webs= $sites [[int] $choice]. Allwebs for($i =0; $i-lt $webs. Count; $i + +) {$tip="["+ $i +"]."+$webs [$i].url Write-Host $tip} $choice= Read-host"Enter the number before"$tip="You chose"+ $choice +". "+"The web chose is '"+ $webs [[int] $choice].url+"'"Write-host $tip-Foregroundcolor Green $lists= $webs [[int] $choice].listsif($lists. Count-eq0) {Write-warning"There is no list available."Createsplistitems}Else{Write-host"Choose the list:"-Foregroundcolor Yellow for($i =0; $i-lt $lists. Count; $i + +) {$tip="["+ $i +"]."+$lists [$i].title Write-Host $tip} $choice= Read-host"Enter the number before"$tip="You chose"+ $choice +". "+"The web chose is '"+ $webs [[int] $choice].url+"'"$list= $lists [[int] $choice] $tip="The list chose is '"+ $list. Title +"'"Write-host $tip-Foregroundcolor Green $amount= Read-host"How many items does want to create"$titleEp= Read-host"Give An example of the item title, such as ' Tylan '"             for($i =1; $i-le $amount; $i + +) {$random= Get-random10000$sign= $date. month+ $date. day+ $date. hour+ $date. minute+ $date. second+$random $newItem=$List. Items.Add () $newItem ["Title"] = $sign. ToString () + $titleEp +"TestData"$newItem. Update ()} $tip="Items have been created successfully under the list '"+ $list. title+"'."Write-host $tip-Foregroundcolor Green $choice= Read-host"Press ' C ' to continue"            if($choice-eq'C') {Createsplistitems}}}}createsplistitems

Operating interface:

SharePoint site test Data Automation Series-Creating SharePoint List Items from PowerShell

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.