For Windows 7, the way to do it is different
Everything firewall-related in Server 2008/Vista / Server R2/ Windows 7, is managed through the HNetCfg.FwPolicy2 COM object
from here
If you want to use PowerShell but need to target both versions of the OS, I would say that writing 2 functions would be simplest since you already seem to know how to do it for Windows 8.