0

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?

Niels
  • 48,601
  • 4
  • 62
  • 81

1 Answers1

0

Sounds like a permissions issue, the user under which you are running the website/appPool does not have the rights for "C:\Projecten\Websites\".
You can fix that by assigning a user with correct privileges to the Application Pool:

iis manager -> application pools -> yourPool -> advanced settings -> Process Model -> Identity

or give your app pool rights to the folder:

folder's security tab -> edit/add -> (in locations select your server) -> IIS AppPool\yourPool

Raf
  • 9,681
  • 1
  • 29
  • 41
  • But it's strange that I also can't do `get-website`. Which gives the same error, and I shouldn't need any permissions on directories for that. – Niels Jul 24 '14 at 14:56
  • A good way to verify whether it is permissions is assigning a user you know can execute `get-website` to the app pool(such us your own account). Don't forget to recycle the app pool afterwards. What is the error? – Raf Jul 24 '14 at 15:18