davesnb
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-WebConfigurationProper ty and Remove-WebConfigurationPro perty . 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 ?
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-WebConfigurationProper
# 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
}
Can you give an example of a value you tried to use as a string and the resulting error message?
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?
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You da man Subsun , you da man!