User interface Powershell是否将IIS中的IP列入白名单?

User interface Powershell是否将IIS中的IP列入白名单?,user-interface,powershell,iis,User Interface,Powershell,Iis,我正在尝试使用powershell将IP列入白名单。我的目标是通过GUI来实现这一点。我的IP白名单代码运行平稳,但在采用GUI方法时,它抛出以下错误: 我的代码是: import-module WebAdministration [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [System.Reflection.Assembly]::LoadWithPartialName("

我正在尝试使用powershell将IP列入白名单。我的目标是通过GUI来实现这一点。我的IP白名单代码运行平稳,但在采用GUI方法时,它抛出以下错误:

我的代码是:

import-module WebAdministration
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")  

$Form = New-Object System.Windows.Forms.Form    
$Form.Size = New-Object System.Drawing.Size(600,400)  
$type="Allow"

function SaveConfig 
{
Set-WebConfigurationProperty -Filter /system.webserver/security/ipsecurity -Name allowUnlisted -Value $False -Location "$url.text"
Add-WebConfiguration /system.webserver/security/ipsecurity -loaction "$url.text" -Value @{ipAddress="$ip.text";allowed="True"} -pspath IIS:\
$r1 = "The given range of ip addresses are added into whitelist"
$outputbox.text = $r1
}

$url_label = New-Object System.Windows.Forms.Label
$url_label.Location = New-Object System.Drawing.Size(40,20) 
$url_label.Size = New-Object System.Drawing.Size(280,20) 
$url_label.Text = "Please enter the URL"
$Form.Controls.Add($url_label) 

$url = New-Object System.Windows.Forms.TextBox 
$url.Location = New-Object System.Drawing.Size(40,50) 
$url.Size = New-Object System.Drawing.Size(260,60) 
$Form.Controls.Add($url)

$DropDownBox = New-Object System.Windows.Forms.ComboBox
$DropDownBox.Location = New-Object System.Drawing.Size(40,80) 
$DropDownBox.Size = New-Object System.Drawing.Size(180,20) 
$DropDownBox.DropDownHeight = 400 
$Form.Controls.Add($DropDownBox) 

$wksList=@("Allow","Deny")

foreach ($wks in $wksList)
 { 
 $DropDownBox.Items.Add($wks)
 } 

$ip_label = New-Object System.Windows.Forms.Label
$ip_label.Location = New-Object System.Drawing.Size(40,110) 
$ip_label.Size = New-Object System.Drawing.Size(280,20) 
$ip_label.Text = "Please enter the IP address"
$Form.Controls.Add($ip_label) 

$ip = New-Object System.Windows.Forms.TextBox 
$ip.Location = New-Object System.Drawing.Size(40,140) 
$ip.Size = New-Object System.Drawing.Size(260,60) 
$Form.Controls.Add($ip)


$mask_label = New-Object System.Windows.Forms.Label
$mask_label.Location = New-Object System.Drawing.Size(40,170) 
$mask_label.Size = New-Object System.Drawing.Size(280,20) 
$mask_label.Text = "Please enter the Subnet Mask"
$Form.Controls.Add($mask_label) 

$mask = New-Object System.Windows.Forms.TextBox 
$mask.Location = New-Object System.Drawing.Size(40,200) 
$mask.Size = New-Object System.Drawing.Size(260,60) 
$mask.Text="255.255.255.0"
$Form.Controls.Add($mask)


$Button = New-Object System.Windows.Forms.Button 
$Button.Location = New-Object System.Drawing.Size(40,230) 
$Button.Size = New-Object System.Drawing.Size(110,50) 
$Button.Text = "save" 
$Button.Add_Click({SaveConfig}) 
$Form.Controls.Add($Button) 

$outputBox = New-Object System.Windows.Forms.TextBox 
$outputBox.Location = New-Object System.Drawing.Size(350,50) 
$outputBox.Size = New-Object System.Drawing.Size(200,200) 
$outputBox.MultiLine = $True 
$outputBox.ReadOnly= $True
$Form.Controls.Add($outputBox)

$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()

添加WebConfiguration/system.webserver/security/ipsecurity-location“$url.text”-Value@{ipAddress=“$ip.text”;allowed=“True”}-pspath IIS:\


只需删除粗体代码中的倒逗号即可。:)

添加WebConfiguration/system.webserver/security/ipsecurity-location“$url.text”-Value@{ipAddress=“$ip.text”;allowed=“True”}-pspath IIS:\

只需删除粗体代码中的倒逗号即可。:)