简体   繁体   中英

Getting virtual directories from IIS with powershell in an MVC application

I have created my own custom IIS directory browser in MVC3 (C#) and have hit a rough spot.

Currently I am using the Microsoft.Web.Administration namespace to get virtual directories out which is working fine, however I thought I'd try with PowerShell as the Site class needs permission to a folder in the windows directory.

Currently my code is as follows:

        PowerShell ps = PowerShell.Create();
        ps.AddCommand("import-module");
        ps.AddArgument("webadministration");
        ps.AddCommand("get-webvirtualdirectory");
        ps.AddParameter("Name", "Default");
        IEnumerable<PSObject> results = ps.Invoke();

Now default does in have fact two virtual directories, however when I run this peice of code no errors occur, all seems to work as expected however, the collection returned in "results" comes out empty..

Even more of a conundrum, when I call import-module webadministration then get-webvirtualdirectory -name Default directly into powershell it works as expected returning the list of two.

确保IIS连接池进程正在以管理员权限运行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM