Powershell command works in Powershell but not inside of a script, why?
Add this line at the top of your script, it will import the necessary IIS module:
Import-Module WebAdministration;
EDIT, thanks to @KyleMit: if you don't have WebAdministration installed, you may need to first run (with elevated privilege)
Import-Module ServerManager; Add-WindowsFeature Web-Scripting-Tools