Link to home
Start Free TrialLog in
Avatar of davesnb
davesnbFlag for Canada

asked on

Add-WebConfigurationProperty and -name parameter

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

Avatar of Dustin Saunders
Dustin Saunders
Flag of United States of America image

Can you give an example of a value you tried to use as a string and the resulting error message?
Avatar of davesnb

ASKER

it will not accept ip addresses example "192.168.1.1" as the  '-name' or a string value , example "fusion"
Does it give you a specific error?  Can you paste the red text?
Avatar of davesnb

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of davesnb

ASKER

You da man Subsun , you da man!