IP Address and Domain Restriction by Powershell

Er Bo Guan 81 Reputation points
2022-05-17T20:10:54.577+00:00

I try to automatic a manual process in IIS. For one hour, we want to restrict all use to access one application. I search and test for today and cannot find a solution. Please help me out. All I need are at attached file. I just wonder if I can do it by Power Shells and schedule it instead of manually do it. Thank you.

202847-powershellhelp.pdf

Windows for business | Windows Server | User experience | PowerShell
{count} votes

Accepted answer
  1. MotoX80 36,291 Reputation points
    2022-05-18T20:35:02.017+00:00

    Verify that you have the scripts and tools installed.

    203279-capture.png

    Add a deny entry.

    203309-capture1.png

    Open Configuration editor and navigate to system.webServer/security/ipSecurity. You should have count=1.Click on Edit Items.

    203295-capture2.png

    Make a trivial change to the ip address. Then close the popup.

    203269-capture3.png

    Then click on Generate Script. Copy the appcmd or Powershell statements from the Script Dialog popup.

    203128-capture4.png

    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2022-05-17T21:12:12.76+00:00

    Without knowing what you've already tried and failed at it's hard to know if anything anyone will recommend will be met with "already tried that!".

    So, how about this: edit-an-existing-iis-ip-restriction-with-powershell

    0 comments No comments

  2. Er Bo Guan 81 Reputation points
    2022-05-17T21:27:15.33+00:00

    Thanks for your quick response. I had tried that before and it seems not work for me?

    What I need are:
    (1) Go go IIS (local host) / the web application.
    (2) "IP Address and Domain Restriction"
    (3) Add "Deny Entry"
    (4) "Specific IP Address"
    (5) Enter "0.0.0.0"
    (6) "OK"
    (7) Remove the entry one hour later.

    All these steps are manually do them now. I just wonder if I can use Powershell and schedule to do them?


  3. Er Bo Guan 81 Reputation points
    2022-05-18T19:07:04.33+00:00

    I play around IIS configuration editor. But I cannot "Add Deny Entry" and enter "Specific IP Address"? (Please see the attachment). When I do it manually, I normally "Add Deny Entry" in an application and enter 0.0.0.0 as "specific ip address". But I cannot see they are available?
    203278-powershellhelp2.pdf


  4. Er Bo Guan 81 Reputation points
    2022-05-18T19:28:08.63+00:00

    We just do it for one application/site, not for whole IIS (all sites). I am looking for web configure file now.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.