Solved

Add-WebConfigurationProperty and -name parameter

Posted on 2016-10-13
6
76 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

627 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