Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Creating a function call for scriptblock
function SecondsQuarter {
<#
.SYNOPSIS
returns the "quarter" based on the current time's seconds
.DESCRIPTION
Returns either "1st quarter", "2nd quarter", "3rd quarter", or "4th quarter" depending on the current time.
00-14: 1st quarter
15-29: 2nd quarter
30-44: 3rd quarter
45-59: 4th quarter
.EXAMPLE
PS C:\> SecondsQuarter
.INPUTS
None
.OUTPUTS
[System.String]
.NOTES
Can use this instead of a scriptblock
#>
if ((Get-Date).Second -lt 15) {
'1st Quarter'
}
elseif ((Get-Date).Second -lt 30) {
'2nd Quarter'
}
elseif ((Get-Date).Second -lt 45) {
'3rd Quarter'
}
else {
'4th Quarter'
}
}
for ($i = 0; $i -lt 10; $i++) {
[PSCustomObject]@{
Date = Get-Date
ScriptBlock = 'Actual Scriptblock'
DateDescription = SecondsQuarter
}
Start-Sleep -Seconds 6
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment