1

I'd like to simply add some .Net Authorization rules in IIS (7.5 / win 2008 R2) using a powershell script with PS snap in. So far I was able to add some "allow" rules but not any deny ones.

Each time I try, it either does nothing or creates an "allow" rule, which seems odd, like if it was defaulting to allow all the time.

I tried with add-webconfigurationproperty and add-webconfiguration with no luck.

Maybe one of you has the correct command line to use?

For instance:

Add-WebConfiguration "/system.web/authorization" -value @{ElementTagName="Deny";users="*"} -PSPath "IIS:\Sites\Mysite"

Add-WebConfigurationProperty "/system.web/authorization" -Name "collection" -value @{ElementTagName='deny';users='test'} -PSPath "IIS:\Sites\Mysite"

will create 2 "allow" rules.

Same behavior if I remove ElementTagName='deny'. So weird. Like if the deny "mode" was to be accessed in some different way.

And for instance, if I go to IIS 8 and try to generate the script after adding a deny rule, the command line suggested is not working either.

How can I fix this?

hichris123
  • 10,145
  • 15
  • 56
  • 70
Cedricc
  • 96
  • 1
  • 5
  • Not exactly an answer to your question... but to achieve your goal, you can call `appcmd.exe` from powershell. See here an example to [add a deny rule](https://technet.microsoft.com/en-us/library/cc772441(v=ws.10).aspx)... – Peter Schneider May 09 '15 at 15:08
  • Thanks Peter, indeed I already found a way to add a deny rule with the appcmd.exe but I consider this as a workaround. I would be surprised that it's not possible with the regular PS snap in. – Cedricc May 11 '15 at 16:22

1 Answers1

1

The command you should use to add a deny rule in your example is:

Add-WebConfigurationProperty "/system.web/authorization" -PSPath "IIS:\Sites\Mysite" -Name "." -value @{users='test'} -Type "deny"

This bothered me too & I also had trouble getting appcmd to do the same thing. I did get it working in the end & found that the -Type parameter was the important one. This wasn't all that clear to me from the documentation which just says:

The type of property to add.

joelnb
  • 1,426
  • 11
  • 14