Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 views
in Technique[技术] by (71.8m points)

powershell - Using IIS command 'New-Website' in C# not working

I am using Powershell SDK in C sharp and and trying to add new website in IIS. But it is not working.

String query = "Import-Module WebAdministration ; New-Website -Name 'testwebsite' -Port 8011  -PhysicalPath '##APPLICATIONFOLDER'  -force";


using (PowerShell PowerShellInst = PowerShell.Create())
            {
              
                PowerShellInst.AddScript("Set-ExecutionPolicy Bypass -Scope Process; "+  query);
                Collection<PSObject> PSOutput = PowerShellInst.Invoke();
                PowerShellInst.Commands.Clear();

             }

I am getting following error

C:WINDOWSsystem32WindowsPowerShellv1.0ModulesWebAdministrationWebAdministration.psd1' does not support current PowerShell edition 'Core'. Its supported editions are 'Desktop'. Use 'Import-Module -SkipEditionCheck' to ignore the compatibility of this module.


The term 'New-Website' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

When I run new website on actual powershell it works fine.

enter image description here

How I can create new website using c sharp?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...