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