我无法使用此脚本在IIS服务器中添加网站

时间:2019-10-31 12:49:20

标签: powershell

运行代码时,出现此错误:

  

New-Item:找不到与参数名称“ Bindings”匹配的参数。   在C:\ Users \ INTERN05 \ Desktop \ laborious.ps1:67 char:40   + $ newweb =新项目$ iiswebsite -Bindings $ Bindings -PhysicalP ...   + ~~~~~~~~~~       + CategoryInfo:InvalidArgument:(:) [New-Item],ParameterBindingException       + FullyQualifiedErrorId:NamedParameterNotFound,Microsoft.PowerShell.Commands.NewItemCommand

有人可以帮助我吗?

这是我的代码:

function GenerateForm {

    [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
    [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null

    $form1 = New-Object System.Windows.Forms.Form
    $label5 = New-Object System.Windows.Forms.Label
    $button2 = New-Object System.Windows.Forms.Button
    $button1 = New-Object System.Windows.Forms.Button
    $label3 = New-Object System.Windows.Forms.Label
    $label2 = New-Object System.Windows.Forms.Label
    $textBox3 = New-Object System.Windows.Forms.TextBox
    $textBox2 = New-Object System.Windows.Forms.TextBox
    $label1 = New-Object System.Windows.Forms.Label
    $textBox1 = New-Object System.Windows.Forms.TextBox
    $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState

    $button1_OnClick=
    {
    $textBox2.Text = "C:\Users\INTERN05\Documents\Sample_Site\"
    $textBox1.Text = ""
    $textBox3.Text = ""
    $richTextBox1.Text = ""

    }

    $handler_label3_Click=
    {

    }

    $handler_label5_Click=
    {
    #TODO: Place custom script here

    }


    $handler_textBox2_TextChanged=
    {
    #TODO: Place custom script here

    }

    $button2_OnClick=
     {



        param(
            [Parameter(Mandatory = $true)][string]$iiswebsite = $textBox1,
            [Parameter(Mandatory = $true)][string]$path = $textBox2,
            [Parameter(Mandatory = $true)][string]$apppoolName = $textbox3.Text
        )
        Import-Module Webadministration
        cd IIS:\AppPools\
        if (-Not(Test-Path $apppoolName -PathType Any)) {
            $app = New-Item $apppoolName
            $app | Set-ItemProperty -Name "managedRuntimeVersion" -Value "No Managed Code"
        }
        cd IIS:\Sites\
        $Bindings = @{
            protocol           = "http" ;
            bindingInformation = ":99:";
            serverHostName     = "localhost" + $iiswebsite
        }
        $newweb = New-Item $iiswebsite -Bindings $Bindings -PhysicalPath $textBox2.Text  | Set-ItemProperty -Name "applicationPool" -Value $apppoolName
    }



    $handler_label2_Click=
    {
    #TODO: Place custom script here

    }

    $handler_label1_Click=
    {
    #TODO: Place custom script here

    }

    $OnLoadForm_StateCorrection=
    {#Correct the initial state of the form to prevent the .Net maximized form issue
        $form1.WindowState = $InitialFormWindowState
    }

    #----------------------------------------------
    #region Generated Form Code
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 489
    $System_Drawing_Size.Width = 672
    $form1.ClientSize = $System_Drawing_Size
    $form1.DataBindings.DefaultDataSourceUpdateMode = 0
    $form1.Name = "form1"
    $form1.Text = "u/410th"

    $label5.DataBindings.DefaultDataSourceUpdateMode = 0
    $label5.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",12,0,3,0)

    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 222
    $System_Drawing_Point.Y = 9
    $label5.Location = $System_Drawing_Point
    $label5.Name = "label5"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 28
    $System_Drawing_Size.Width = 120
    $label5.Size = $System_Drawing_Size
    $label5.Text = "IIS Site Wizard"
    $label5.add_Click($handler_label5_Click)

    $form1.Controls.Add($label5)


    $button2.DataBindings.DefaultDataSourceUpdateMode = 0

    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 384
    $System_Drawing_Point.Y = 300
    $button2.Location = $System_Drawing_Point
    $button2.Name = "button2"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 23
    $System_Drawing_Size.Width = 75
    $button2.TabIndex = 5
    $button2.Size = $System_Drawing_Size
    $button2.Text = "Create Site"
    $button2.UseVisualStyleBackColor = $True
    $button2.add_Click($button2_OnClick)

    $form1.Controls.Add($button2)


    $button1.DataBindings.DefaultDataSourceUpdateMode = 0

    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 127
    $System_Drawing_Point.Y = 300
    $button1.Location = $System_Drawing_Point
    $button1.Name = "button1"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 23
    $System_Drawing_Size.Width = 75
    $button1.Size = $System_Drawing_Size
    $button1.TabIndex = 4
    $button1.Text = "Reset"
    $button1.UseVisualStyleBackColor = $True
    $button1.add_Click($button1_OnClick)

    $form1.Controls.Add($button1)


    $label3.DataBindings.DefaultDataSourceUpdateMode = 0

    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 49
    $System_Drawing_Point.Y = 249
    $label3.Location = $System_Drawing_Point
    $label3.Name = "label3"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 20
    $System_Drawing_Size.Width = 51
    $label3.Size = $System_Drawing_Size
    $label3.Text = "App Pool"
    $label3.add_Click($handler_label3_Click)

    $form1.Controls.Add($label3)

    $label2.DataBindings.DefaultDataSourceUpdateMode = 0

    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 49
    $System_Drawing_Point.Y = 145
    $label2.Location = $System_Drawing_Point
    $label2.Name = "label2"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 24
    $System_Drawing_Size.Width = 51
    $label2.Size = $System_Drawing_Size
    $label2.Text = "Path"
    $label2.add_Click($handler_label2_Click)

    $form1.Controls.Add($label2)

    $textBox3.DataBindings.DefaultDataSourceUpdateMode = 0
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 106
    $System_Drawing_Point.Y = 249
    $textBox3.Location = $System_Drawing_Point
    $textBox3.Name = "textBox3"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 20
    $System_Drawing_Size.Width = 396
    $textBox3.Size = $System_Drawing_Size
    $textBox3.TabIndex = 2

    $form1.Controls.Add($textBox3)

    $textBox2.DataBindings.DefaultDataSourceUpdateMode = 0
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 106
    $System_Drawing_Point.Y = 145
    $textBox2.Location = $System_Drawing_Point
    $textBox2.Name = "textBox2"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 20
    $System_Drawing_Size.Width = 396
    $textBox2.Size = $System_Drawing_Size
    $textBox2.TabIndex = 1
    $textBox2.Text = "C:\Users\INTERN05\Documents\Sample_Site\"
    $textBox2.add_TextChanged($handler_textBox2_TextChanged)

    $form1.Controls.Add($textBox2)

    $label1.DataBindings.DefaultDataSourceUpdateMode = 0

    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 49
    $System_Drawing_Point.Y = 60
    $label1.Location = $System_Drawing_Point
    $label1.Name = "label1"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 17
    $System_Drawing_Size.Width = 51
    $label1.Size = $System_Drawing_Size
    $label1.Text = "Name"
    $label1.add_Click($handler_label1_Click)

    $form1.Controls.Add($label1)

    $textBox1.DataBindings.DefaultDataSourceUpdateMode = 0
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 106
    $System_Drawing_Point.Y = 60
    $textBox1.Location = $System_Drawing_Point
    $textBox1.Name = "textBox1"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 20
    $System_Drawing_Size.Width = 396
    $textBox1.Size = $System_Drawing_Size
    $textBox1.TabIndex = 0

    $form1.Controls.Add($textBox1)


    $InitialFormWindowState = $form1.WindowState
    #Init the OnLoad event to correct the initial state of the form
    $form1.add_Load($OnLoadForm_StateCorrection)
    #Show the Form
    $form1.ShowDialog()| Out-Null

    } 
    GenerateForm

1 个答案:

答案 0 :(得分:0)

由于错误状态,cmdlet New-Item不包含参数-Bindings

尝试使用New-IISSite