?
Solved

Add-WebConfigurationProperty and -name parameter

Posted on 2016-10-13
6
Medium Priority
?
96 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 13

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 13

Expert Comment

by:Dustin Saunders
ID: 41841996
Does it give you a specific error?  Can you paste the red text?
0
Industry Leaders: 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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

719 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