magritton
1/23/2018 - 8:16 PM

Random Date in SharePoint List Item

This places a random date into a SharePoint List item

$site = Get-SPweb "http://spsvde001/sites/RDR"

[DateTime]$theMin = "1/1/2008"
[DateTime]$theMax = [DateTime]::Now


$mList=$site.Lists["RDR"]
$i = 0

foreach($f in $mList.Items)
{
	$f["ID]
	$theRandomGen = new-object random
	$theRandomTicks = [Convert]::ToInt64( ($theMax.ticks * 1.0 - $theMin.Ticks * 1.0 ) * $theRandomGen.NextDouble() + $theMin.Ticks * 1.0 )
		
	$f["DeficiencyDate"] = new-object DateTime($theRandomTicks)
	$f.Update()

}