Cmdlets not found in command line but available in ISE

Question:

I’m trying to create an IIS application and app pool using PowerShell on a Windows Server 2008 R2 VM. The powershell script is as follows:

If I run the script in the PowerShell ISE it works fine but if I run it from a command line (or a batch file using the command line) I get the error

The term New-WebAppPool is not recognized as the name of a cmdlet… etc.

Is there a way that the web administration cmdlets could be installed in the ISE but not the command line?

Answer:

Assuming that you’re using PowerShell v2 (the default version installed with Server 2008 R2) it’s as @jisaak suspected: you need to import the module WebAdministration explicitly in your code:

ISE seems to do that automatically.

Another option would be to upgrade to PowerShell v4, which also automatically imports modules when one of their exported cmdlets is used.

Source:

Cmdlets not found in command line but available in ISE by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply