Get Random values from SharePoint list using PowerShell

Advertisements
In this article we are going to learn how to Get Random SharePoint items using PowerShell.
PowerShell is a Powerful scripting language, we can do our work/tasks easily, having so many built-in commands are available in PowerShell. In that we are using Get-Random command to get the random SharePoint list items.




add-pssnapin microsoft.sharepoint.powershell
$web = get-spweb -identity "http://dotnetsharepoint.com /sites/sharepoint/getrandom "
$Employeelist = $web.lists["Employee"];
$listitemsTotal = $Employeelist.Items.Count
$getvalues = $Employeelist.Items
if($listitemsTotal -gt 0)
{
$Random=Get-Random -Count $listitemsTotal -InputObject(1..$listitemsTotal)
}
for($j=0;$j -lt $listitemsTotal;$j++){
$RandomVal=$Random[$j]
$EmpNameName=$getvalues[$RandomVal]["EmployeeId"];
Write-host $RandomVal
write-host $EmpNameName

}
Advertisements
SHARE

lakshmitulasi Jasti

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment