Solved

Add-WebConfigurationProperty and -name parameter

Posted on 2016-10-13
6
57 Views
Last Modified: 2016-10-14
Hello EE,

I have a script that denys an ip between certain hour, it works great for one ip , however , I am uncertain how the -name parameter works for the Add-WebConfigurationProperty and Remove-WebConfigurationProperty . Currently, I could only use the "." for a name , it will not accept ip addresses as the  '-name' or a string value . The technet articles were of no help , does anyone have any experience using this ?

# Compose new entry    
$value1 = @{allowed="false";ipAddress="192.168.0.1"}


$Start = "04:00"
$End = "07:00"
$now = @(get-date)
If($now -gt $Start -and $now -lt $End){
# Add new entry to restrictions
Add-WebConfigurationProperty  -Filter 'system.webServer/security/ipSecurity' -pspath MACHINE/WEBROOT/APPHOST/webapi/v3/client1 -name "."  -Value $value1 -ErrorAction Stop
}
else{
# remove new entry to restrictions
Remove-WebConfigurationProperty  -Filter 'system.webServer/security/ipSecurity' -pspath MACHINE/WEBROOT/APPHOST/webapi/v3/client1  -name "."   -ErrorAction Stop
}

Open in new window

0
Comment
Question by:davesnb
  • 3
  • 2
6 Comments
 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41841973
Can you give an example of a value you tried to use as a string and the resulting error message?
0
 

Author Comment

by:davesnb
ID: 41841981
it will not accept ip addresses example "192.168.1.1" as the  '-name' or a string value , example "fusion"
0
 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41841996
Does it give you a specific error?  Can you paste the red text?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:davesnb
ID: 41842086
I think what it is based on request and error below is the name "." is a property , however that leads to how can I  remove ip addresses based on a "name" or ip address , do I need to use a where clause?



Add-WebConfigurationProperty  -Filter 'system.webServer/security/ipSecurity' -pspath MACHINE/WEBROOT/APPHOST/webapi/v3/client1 -name "fusion"  -Value $value1 -ErrorAction Stop

Open in new window




Add-WebConfigurationProperty : Property fusion is not found on  system.webServer/security/ipSecurity.
Parameter name: propName
At line:1 char:1
+ Add-WebConfigurationProperty  -Filter 'system.webServer/security/ipSecurity' -ps ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-WebConfigurationProperty], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.IIs.PowerShell.Provider.AddConfigurationPropertyCommand

Open in new window

0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 41842380
Try with -AtElement parameter to remove single entry from collection, example..
$value1 = @{allowed="false";ipAddress="192.168.0.1"}
Remove-WebConfigurationProperty  -Filter 'system.webServer/security/ipSecurity' -pspath MACHINE/WEBROOT/APPHOST/webapi/v3/client1  -AtElement $value1 -name "."   -ErrorAction Stop

Open in new window

PS : -Name Parameter accepts name of Web Configuration Property.
0
 

Author Comment

by:davesnb
ID: 41843550
You da man Subsun , you da man!
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question