I was tasked to create a PS script that created a Windows Server Backup policy with a random start time

I came up with the following script for the random start time bits.

function Get-TimeSlot($startTime, $EndTime)
{ 
	$timeslots = @() 
	for ($i = $startTime; $i -ne $EndTime; $i++) { 
		if ($i -eq 24) { 
			$i = 0 
		} 
		$timeslots += $i 
	} 
	$timeslot = "$(Get-Random $timeslots):00" 
	return $timeslot 
} 
Get-TimeSlot -startTime 20 -EndTime 4

There might be a more Powershell’ish way of doing this, but it gets the job done.