Public/TwoFactor.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function Get-Monocle2FACode
{
    # with thanks to @Fraham
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true)]
        [string]
        $Secret,

        [Parameter()]
        [DateTime]
        $DateTime
    )

    # set the date to now
    if ($null -eq $DateTime) {
        $DateTime = Get-Date
    }

    Write-MonocleHost -Message "Genetaring 2FA code for: $($DateTime.ToString('r'))"

    # get pin for the supplied date
    $interval = Get-Monocle2FAInterval -DateTime $DateTime

    # get pin for the time interval
    return (Get-Monocle2FAPin -Secret $Secret -Interval $interval)
}