I am trying to add a IIS website via command-lets. What I currently have:
' User input
Dim domainname As String = "niels_test"
' System vars
Dim basePath As String = "C:\Projecten\Websites\"
Dim finalDirname As String = basePath & domainname
Dim shell As PowerShell = PowerShell.Create
'shell.Commands.AddScript("mkdir """ & finalDirname & """")
shell.Commands.AddScript("New-Website -name """ & domainname & """ -PhysicalPath '" & finalDirname & "' -port 80")
Dim results = shell.Invoke()
If results.Count > 0 Then
Dim b As New StringBuilder
For Each PSObject In results
b.AppendLine(PSObject.BaseObject.ToString)
Next
Else
Throw New Exception("NORESULT")
End If
If I comment out hte line for mkdir
it works. But I cannot create a new website in IIS this way. If I execute that command via the powershell on the server itself. It does work.
This code is inside a .aspx.vb
file.
Any idea on how to get this working?