A quick and easy post:

Import-Module ActiveDirectory

# Get the forest functional level
(Get-ADForest).ForestMode

# Get the domain functional level
(Get-ADDomain).DomainMode