functions/Draw-Month.ps1

function Draw-Month {
    [CmdletBinding()]
    param 
    (
        # Parameter help description
        [ValidateNotNullOrEmpty()]
        [ValidateSet("Month","MonthAndYear")]
        [string]
        $Title="Month",
        
        [parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string]
        $Year,

        [parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string]
        $Month,

        [parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [ValidateRange(0,6)]
        [int]
        $FirstDayOfMonth,

        [parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [ValidateSet(29,30,31)]
        [int]
        $DaysInMonth,

        [parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [ValidateRange(1,31)]
        [int]
        $today,

        [parameter(Mandatory=$false)]
        [allownull()]
        [int[]]
        $holidays,

        [parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [System.Management.Automation.Host.Coordinates]
        $cursorPos

    )
    
    if (-not $cursorPos)
    {
        $cursorPos = $Host.UI.RawUI.CursorPosition
    }
    [int]$cursorInitX = $cursorPos.X
    if ($Title -eq "MonthAndYear")
    {
        $strTitle = $Month + " " + [string]$Year  
    }
    else 
    {
        $strTitle = $Month
    }

    if ($FirstDayOfMonth -eq 6)
    {
        $FirstDayOfMonth = 0
    } 
    else
    {
        $FirstDayOfMonth += 1
    }

    [int]$titleStartPos = (20 - $strTitle.Length) / 2
    $cursorPos.X = ($cursorPos.X + $titleStartPos)
    $Host.UI.RawUI.CursorPosition = $cursorPos
    Write-Host $strTitle
    $cursorPos.X = ($cursorPos.X - $titleStartPos)
    $cursorPos.Y++
    $Host.UI.RawUI.CursorPosition = $cursorPos
    Write-Host "Sa Su Mo Tu We Th Fr"
    $cursorPos.Y++

    $firstDayPosArr = @(0,3,6,9,12,15,18) 
    $cursorPos.X += ($firstDayPosArr[$FirstDayOfMonth] +  1)
    $Host.UI.RawUI.CursorPosition = $cursorPos
    [int]$weekDayIndex = $FirstDayOfMonth
    $d = 1
    while ($d -le $DaysInMonth) 
    {
        for ($i = 0; $i -le 6; $i ++)
        {
            if (($i -eq $weekDayIndex) -and ($d -le $DaysInMonth))
            {
                if ($d -eq $today)
                {
                    Write-Host  $d -ForegroundColor Cyan
                }
                elseif ($holidays -contains $d)
                {
                    Write-Host  $d -ForegroundColor Magenta
                }
                elseif ($i -eq 6)
                {
                    Write-Host  $d -ForegroundColor Red
                }
                else 
                {
                    Write-Host $d -NoNewline
                }
                
                $cursorPos.X += 3
                if (($d + 1) -eq 10){$cursorPos.X -= 1}
                $Host.UI.RawUI.CursorPosition =$cursorPos
                $weekDayIndex++
                $d++
            }
        }
       $weekDayIndex = 0
       $cursorPos.y++
       $cursorPos.X = $cursorInitX
       if ($d -lt 10 ){$cursorPos.X += 1}
       $Host.UI.RawUI.CursorPosition = $cursorPos
    }
}