Solved

Add-WebConfigurationProperty and -name parameter

Posted on 2016-10-13
6
22 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Set OWA language and time zone in Exchange for individuals, all users or per database.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now