0

I'm trying to set a user account as the Anonymous identity for a website authentication, and I've looked through every page on my Google searches but haven't found anything. There's a few things about setting it as the pool identity which is where I got the below line, but I'm not sure how that line is setting the pool identity, and I've tried to modify it to set the user account I want, but it's not working:

set-webconfigurationproperty /system.webServer/security/authentication/anonymousAuthentication -name UserName -value "domain\user" -Location "iis:\Sites\$NewApp"

I'm also trying to set a binding after I create a site, but the binding isn't being applied correctly, and I can't see why. I've looked at many examples online and tried to mimic what they have. I'm sure I just have a formatting error or something small like that. This is my binding line:

New-Item IIS:\Sites\$NewApp -bindings @{protocol="http";bindingInformation=$NewIP+":80"} -physicalPath "E:\Physicalpath"

I've spent 2 hours on this tonight, and it's driving me crazy. I just broke down and configured the servers manually for those couple items, but I really want to get this working so I can use it for other site creation scripts.

Thanks in advance for any assistance.

Squirreljester
  • 191
  • 1
  • 1
  • 7
  • Have you checked https://stackoverflow.com/questions/24535200/enable-authentication-for-iis-app-in-powershell – Ketanbhut Jun 15 '18 at 06:06
  • Yes, that doesn't show me how to add a user, just how to enable/disable it. – Squirreljester Jun 15 '18 at 22:15
  • That link was to tell you that you have to use -PSPath. Are you looking for an exact answer of your question? You have to get a part or hint of the solution of your query and build upon it as per your need. The answer to your question is provided below, in reality, multiple questions are answered here. – Ketanbhut Jun 16 '18 at 05:05

1 Answers1

0

I was able to set the user, needed to add -PSPath. You should be able to combine -PSPath and -Location as per the Link: Enable authentication for IIS app in Powershell

set-webconfigurationproperty /system.webServer/security/authentication/anonymousAuthentication -name userName -value "domain\user" -pspath iis:\ -Location "iis:\Sites\pwa"

Further, you second doubt is clarified here: Examples of IIS Powershell cmdlets

From the above link:

COMMAND Examples: When -Value parameter is used by IIS powershell cmdlet, it usually set with a single string value (NOTE: if the value contains space, it should be quoted with " or ')

The value can be hash table object if it is used to set a collection item

add-webconfiguration '/system.applicationHost/sites/site[@name="Default Web Site"]/bindings'-value @{protocol="http";bindingInformation="*:80:"} -pspath iis:\

You can use Add-WebConfiguration for setting bindings, like so:

Add-WebConfiguration '/system.applicationHost/sites/site[@name="pwa"]/bindings' -Value @{protocol="ftp";bindingInformation="10.0.0.100:21:pwa.fabrikam.local"} -PSPath iis:\

Or, you can use Set-WebConfiguration for modifying:

set-WebConfiguration '/system.applicationHost/sites/site[@name="pwa"]/bindings' -Value @{protocol="https";bindingInformation="*:443:pwa.fabrikam.local";sslFlags=0} -PSPath iis:\

Adding everything via variables. You can manage your variables it suites your needs, I've separated every components of bindings into various variables. Putting variables inside bracket helps evaluating expressions.

$siteName = "pwa"
$appFilter = "//system.applicationHost/sites/site[@name='$($sitename)']/bindings"
$newIP = "*"
$port = 80
$hostName = "pwa.fabrikam.local"
$bindings = @{
    protocol = "http"
    bindingInformation="$($newIP):$($port):$($hostName)"
}

set-WebConfiguration  -Filter $appFilter -Value $bindings -PSPath iis:\

If you now change only variables, the commands should continue to function. I tried changing IP and ports via variables $newIP and $port. Let us know how it goes.

Ketanbhut
  • 476
  • 2
  • 11
  • So, for the first item, I'll have to test that and see if it works, but it looks like the -pspath was what I was missing thanks. – Squirreljester Jun 15 '18 at 11:49
  • For the second item, I need to use a variable for the site name, so I can't use single quotes for the first part, can I use double quotes for that part or will that cause issues? Also, I need to use a variable for the IP address and when I replace the * with my variable $NewIP it turns the :80: red also, making it look like the whole thing will be the variable like $NewIP:80:. That's why I was trying to split it up, but it doesn't seem to add correctly when I split it up. – Squirreljester Jun 15 '18 at 11:56
  • @Squirreljester: Updated my answer to run command with variables. – Ketanbhut Jun 15 '18 at 14:02
  • That's kind of ugly and cumbersome to separate everything out like that. For the appfilter, are you sure it starts with double // because everywhere I've seen it it just starts with a single /. And why did you put dollar signs in front of each piece in the bindinginformation line? I'll try this and see if it works, but I'd like it to be at least 1 line for the binding. – Squirreljester Jun 15 '18 at 15:10
  • You don't have to use variables for everything, do use variables as you need. Test/modify the code as you find suitable for your own use. I just wanted to display how it works or it can work. – Ketanbhut Jun 15 '18 at 17:24
  • Check https://stackoverflow.com/questions/13615676/what-does-variablename-mean-in-expandable-strings-in-powershell to know more why you would choose to use "$($newIP):80" against "$newIP:80" – Ketanbhut Jun 15 '18 at 17:32