IIS 7 and Above
PowerShell in VB.NET Webservices
Last post Sep 02, 2009 01:20 AM by sergeia
Mar 30, 2009 10:13 AM|MagnusVMI|LINK
I dont know if this is the right place for this question, but perhaps somebody can direct me right.
My plan is to write an solution for our administrative hosting system, to add (and remove) webbsites on a Windows 2008 Server.
I have decied to use PowerShell and are running this from a VB.NET Webservices.
The problem is when I run
Get-ChildItem IIS:\Sites|format-list name,id
I only see 2 of 6 webbsites (and that is the webservices itself and others in the same AppPool). I guess that I have to set som permissions so it could "see" from other AppPool, or are Im totally wrong here?
Please advise :)
Mar 30, 2009 12:29 PM|v-edsojo|LINK
Hi, did you try your code directly on Powershell console?
IIS Extension for powershell always list complete content based on your query.
Mar 30, 2009 03:57 PM|MagnusVMI|LINK
Yes. If I run the code directly on the console it works.
My Code: Get-ChildItem IIS:\Sites|format-list name,id
I have also tried with whoami to see that I execute as administrator, witch I am.
And my vb.net code to execute it:
results = pipeline.Invoke()
Mar 30, 2009 06:10 PM|MagnusVMI|LINK
I have also tried and make a windows application with the same code, and then it works great. It seams just not work when running as webbapplication.
Apr 05, 2009 05:17 AM|SuperTramp|LINK
I think you have encountered a bug in the IIS Powershell provider. This is just a hunch so someone from the team should respond.
When hosted in an IIS worker process (W3WP.EXE), any consumers of IIS configuration are redirected to an application-pool specific configuraiton file. This config file contains all the config pertinent to the given application pool. It is a security feature
(worker processes shouldn't be able to read each other's config). So if you are instantiating the powershell provider in-process, it is using this simpler config file.
This is a bug. The powershell provider should use a new instance of the configuration system and go directly against system32\inetsrv\applicationhost.config. Then it will work (though of course your app will have to run as a user who has access to applicationhost.config
-> namely an admin).
As a work around, you can have your application launch a process which has the powershell instance doing your work.
Hope that helps.
Sep 01, 2009 06:07 PM|meSync|LINK
Have you found any answer to this?
I am having the same problem. I have an script in and asp.net webservice that invokes powershell to run an exe (it converts files from docx to pdf). If I copy and paste the script into powershell it works perfect. If I run it from the web service it
doesn't seem to run.
I gave the web application Administrator rights (just for testing) and it still doesn't run the script. Any help would be greatly appreciated!
Sep 01, 2009 11:43 PM|SuperTramp|LINK
I think this is an issue for the IIS Powershell Snapin product team. They follow this forum and someone should respond.
Sep 02, 2009 01:20 AM|sergeia|LINK
I don't see these reported issues as a bug, snapin was designed this way and this is an expected behavior. The fact that you all are getting into that with PowerShell is just a specific case, you will see the same behavior with most of other APIs to configuration
system, when you run them from worker process. To fix this we either should redesign how snapin works, or you could host PowerShell and IIS snapin in other process, that doesn't have limitations of w3wp.exe and then communicate with this instance from worker
process. In my opinion, easiest way to do this is to use remoting feature of PowerShell v2.0. With this you will host PowerShell in the worker process only to create and open remote runspace to another instance of PowerShell that will be running under wsman
I will look for some workarounds.