I am executing one powershell script file (.ps1) from my webpage using System.Management.Automation dll. My ps1 file have following script in it:
param
(
[String]$WebDomain = ""
)
Import-Module WebAdministration
$WebsiteDirectory = "C:\websiteroot"
#Create new application pool in IIS
New-WebAppPool -Name $WebDomain
$AppPoolVersion = "IIS:\AppPools\" + $WebDomain
#Create new website in IIS
New-Website -Name $WebDomain -Port 80 -IPAddress "*" -HostHeader $WebDomain -PhysicalPath $WebsiteDirectory -ApplicationPool $WebDomain
It's getting executed successfully. No errors returned (I checked HadErrors property of PowerShell object). In IIS Application Pool and Website is getting created. Only thing is that website's physical path is not getting set as mentioned.
I have already changed the identity of application pool to custom account and added admin account details. So that is not an issue.
Any idea why it's not working and is there any workaround?
Thanks in advance.