#Formulario
$Form = New-Object System.Windows.Forms.Form
$Form.Text="Formulario"
$Form.Size=New-Object System.Drawing.Size(500,500)
$Form.StartPosition="CenterScreen"
#Etiqueta
$Label=New-Object System.Windows.Forms.Label
$Label.Text="NOMBRE DE USUARIO"
$Label.AutoSize=$True
$Label.Location=New-Object System.Drawing.Size(150,70)
#Etiqueta2
$Label2=New-Object System.Windows.Forms.Label
$Label2.Text="NOMBRE DE OU"
$Label2.AutoSize=$True
$Label2.Location=New-Object System.Drawing.Size(170,140)
#Bot贸n
$Button=New-Object System.Windows.Forms.Button
$Button.Size=New-Object System.Drawing.Size(75,23)
$Button.Text="ENTER"
$Button.Location=New-Object System.Drawing.Size(150,210)
#Bot贸n2
$Button2=New-Object System.Windows.Forms.Button
$Button2.Size=New-Object System.Drawing.Size(75,23)
$Button2.Text="EXIT"
$Button2.Location=New-Object System.Drawing.Size(230,210)
#Caja de texto
$TextBox = New-Object System.Windows.Forms.TextBox
$TextBox.Location = New-Object System.Drawing.Size(100,100)
$TextBox.Size = New-Object System.Drawing.Size(260,20)
#Caja de texto 2
$TextBox2 = New-Object System.Windows.Forms.TextBox
$TextBox2.Location = New-Object System.Drawing.Size(100,170)
$TextBox2.Size = New-Object System.Drawing.Size(260,20)
#Funcionalidad para el formulario:
#Pulsar la tecla Enter almacena en una variable el contenido de la caja de texto y se muestra
#Pulsar la tecla Escape sale del formulario
$Form.KeyPreview = $True
$Form.Add_KeyDown({if ($_.KeyCode -eq "Enter"){$USUARIOCLASS = $TextBox.Text ; $OUCLASS = $TextBox2.Text; Write-Host $USUARIOCLASS ,$OUCLASS}})
$Form.Add_KeyDown({if ($_.KeyCode -eq "Escape"){$Form.Close()}})
#Funcionalidad para el bot贸n:
#Pulsar Enter almacena en una variable el contenido de la caja de texto y se muestra
#Pulsar Escape sale del formulario
$Button.Add_Click({$USUARIOCLASS = $TextBox.Text ; $OUCLASS = $TextBox2.Text; Write-Host $USUARIOCLASS,$OUCLASS})
$Button2.Add_Click({$Form.Close()})
#A帽adir etiqueta
$Form.Controls.Add($Label)
$Form.Controls.Add($Label2)
#A帽adir bot贸n
$Form.Controls.Add($Button)
$Form.Controls.Add($Button2)
#A帽adir caja de texto
$Form.Controls.Add($TextBox)
$Form.Controls.Add($TextBox2)
$Form.ShowDialog()
# Crear array de objetos Operacion
$arrayoperaciones = New-Object System.Collections.ArrayList
$arrayoperaciones.add([USUARIO]::new("1",$TextBox.text))
$arrayoperaciones.add([USUARIO]::new("2",$TextBox2.text))
$arrayoperaciones | ConvertTo-Json | Out-File D:\xampp\htdocs\operacion.json -Encoding default
##EN EL AD EJECUTAMOS EL SIGUIENTE SCRIPT (XAMP ACTIVO)
Invoke-RestMethod D:\xampp\htdocs\operacion.json
foreach($contenido in (Invoke-RestMethod "http://10.202.0.154/operacion.json"))
{
switch ($contenido.operacion)
{
"2"{New-ADOrganizationalUnit -Name $contenido.nombre -Path "dc=ad,dc=luis,dc=com,dc=ar" -ProtectedFromAccidentalDeletion:$false}
"1"{New-ADUser -Name $contenido.nombre -AccountPassword (ConvertTo-SecureString -string "P@ssw0rd" -AsPlainText -Force) -ChangePasswordAtLogon $false }
}
}