Can’t run the ‘dir’ or ‘Get-ChildItem” command from IIS:\ in powershell

Question:

I’m trying to automate some web application deployment tasks so I’m attempting to use powershell to accomplish this. I have a powershell script and a .bat file. The batch file is just there to execute the powershell script and contains this text. I’m on Windows 8 – 64bit.

I have some code in the powershell script that runs these commands:

When I get to the CD IIS:\AppPools\ command I get the following error:

From a separate powershell prompt, I can cd to IIS:\, but I can’t run the dir command and get a similar error. What am I missing?

Answer:

By specifying SysWOW64 you are forcing Powershell to run in a 32bit context. The WebAdministration module only supports a 64bit context.

Solution:

  1. If the batch file is running 32bit, use SysNative instead of SysWOW64
  2. If the batch file is 64bit, drop the SysWOW64 and use the standard path.

Source:

Can’t run the ‘dir’ or ‘Get-ChildItem” command from IIS:\ in powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply