Best Practice: You should use the #Requires statement in your scripts or modules (recommended at the top of the script).
The #Requires statement will run a script only if the prerequisites are met.
For example, if you created a script using classes (available in PowerShell 5), older PowerShell versions will not be able to run it.
PowerShell version : #Requires -Version 5.0
Module : #Requires -Modules activedirectory
RunAsAdministrator: #Requires -RunAsAdministrator
You can have several requirements in the same line: #Requires -Version 3.0 -Modules ActiveDirectory, DnsClient -RunAsAdministrator
or in several lines (I prefer having that in several lines, it is clearer to read).
#Requires -Version 3.0
#Requires -Modules ActiveDirectory, DnsClient
There is no specific order and you can put the #Requires statement where you want (here in line 2).
It is case insensitive (#REQUIRES #Requires or #requires, all work).
It is much better to use #Requires statement instead of writing additional code (to check specific version, module, etc.) or custom messages (moreover the error will be in the local language of the user).
#Requires -Version 5.0
# Not recommended
if ($PSVersionTable.PSVersion.Major -lt 5)
Write-Warning -Message "At least PowerShell 5 is required to run this script"