hi there
in my script the variable wont work some one can help ??
variable in probleme are $Textbox 1, 2, 3, 4
When i click create the variable not working
CODE START
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
Function AddEm
{
$TextBox4.Text = $TextBox1.Text + " " + $TextBox2.Text
$Textbox3.Visible = $true
$Textbox3.Text = $Textbox1.Text[0] + “” + $Textbox2.Text + “@email.com”
$Textbox3.Visible = $true
}
Function MakeForm
{
$script:Form1 = New-Object system.Windows.Forms.Form
$Form1.Text = “Add Mail box”
$Font = New-Object System.Drawing.Font(“Times New Roman”, 12, [System.Drawing.FontStyle]::Bold)
$Form1.Font = $Font
$label = New-Object Windows.Forms.Label
$label.Location = New-Object Drawing.Point 150, 80
$label.Size = New-Object Drawing.Point 200, 25
$label.text = “First Name”
$Form1.Controls.Add($label)
$script:TextBox1 = New-Object System.Windows.Forms.Textbox
$TextBox1.Location = New-Object System.Drawing.Size(5, 80)
$TextBox1.Size = New-Object System.Drawing.Size(100, 40)
$label = New-Object Windows.Forms.Label
$label.Location = New-Object Drawing.Point 150, 113
$label.Size = New-Object Drawing.Point 200, 25
$label.text = “Name”
$Form1.Controls.Add($label)
$script:TextBox2 = New-Object System.Windows.Forms.Textbox
$TextBox2.Location = New-Object System.Drawing.Size(5, 110)
$TextBox2.Size = New-Object System.Drawing.Size(100, 40)
$label = New-Object Windows.Forms.Label
$label.Location = New-Object Drawing.Point 150, 143
$label.Size = New-Object Drawing.Point 200, 25
$label.text = “Full Name”
$Form1.Controls.Add($label)
$script:TextBox4 = New-Object System.Windows.Forms.Textbox
$TextBox4.Location = New-Object System.Drawing.Size(5, 140)
$TextBox4.Size = New-Object System.Drawing.Size(120, 40)
$script:TextBox3 = New-Object System.Windows.Forms.Textbox
$TextBox3.Location = New-Object System.Drawing.Size(5, 210)
$TextBox3.Size = New-Object System.Drawing.Size(200, 40)
$TextBox3.Visible = $false
$Button1 = New-Object System.Windows.Forms.Button
$Button1.Location = New-Object System.Drawing.Size(95, 20)
$Button1.Size = New-Object System.Drawing.Size(80, 50)
$Button1.Text = “Create”
$Button1.Add_Click({
Set-ExecutionPolicy Unrestricted -Scope Process -Force
$Username = “admin@.onmicrosoft.com”
$Password = ConvertTo-SecureString ‘Password’ -AsPlainText -Force
$LiveCred = New-Object System.Management.Automation.PSCredential $Username, $Password
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $LiveCred -Authentication Basic -AllowRedirection
Import-PSSession $Session
Connect-MsolService -Credential $LiveCred
Import-Module MSOnline
Get-MsolUser
New-MsolUser -UserPrincipalName “$Textbox3” -FirstName “$textbox1” -LastName “$textbox2” -DisplayName “$textbox4” -UsageLocation CA
Set-MsolUserPassword -UserPrincipalname “$Textbox3” -NewPassword “$password1”
$forcechange = Read-Host “force a changer Y/N”
if ($forcechange -eq “n”)
{
Set-MsolUserPassword -UserPrincipalName “$Textbox3” -NewPassWord “$nouveaupass” -ForceChangePassword $false
}
else
{
Set-MsolUserPassword -UserPrincipalName “$Textbox3” -NewPassWord “$nouveaupass” -ForceChangePassword $true
}
Get-MsolAccountSku
$LicenseSKU = Get-MsolAccountSku | Out-GridView -Title ‘Select a license plan to assign to users’ -OutputMode Single | Select-Object -ExpandProperty AccountSkuId
$x = Get-MsolUser -All -UnlicensedUsersOnly | Out-GridView -Title ‘Select users to assign license plan to’ -OutputMode Multiple
$x | Set-MsolUser -UsageLocation CA
$x | Set-MsolUserLicense -AddLicenses $LicenseSKU
})
$Button2 = New-Object System.Windows.Forms.Button
$Button2.Location = New-Object System.Drawing.Size(5, 20)
$Button2.Size = New-Object System.Drawing.Size(80, 50)
$Button2.Text = “Creation email”
$Button2.Add_Click({ AddEm })
$Button3 = New-Object System.Windows.Forms.Button
$Button3.Location = New-Object System.Drawing.Size(185, 20)
$Button3.Size = New-Object System.Drawing.Size(80, 50)
$Button3.Text = “Exit”
$Button3.Add_Click({ $Form1.Close() })
$Form1.Controls.Add($Button1)
$Form1.Controls.Add($Button2)
$Form1.Controls.Add($Button3)
$Form1.Controls.Add($TextBox1)
$Form1.Controls.Add($TextBox2)
$Form1.Controls.Add($TextBox3)
$Form1.Controls.Add($TextBox4)
$Form1.ShowDialog()
}
$Button6 = New-Object System.Windows.Forms.Button
$Button6.Location = New-Object System.Drawing.Size(25, 15)
$Button6.Size = New-Object System.Drawing.Size(110, 23)
$Button6.Text = “Créé Usager”
$Button6.Add_Click({ MakeForm -form1 })
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Build Form
$Form = New-Object System.Windows.Forms.Form
$Form.Text = “O365 Manager”
$Form.Size = New-Object System.Drawing.Size(800, 800)
$Form.StartPosition = “CenterScreen”
$Form.Topmost = $false
$form.Controls.Add($Button6)
$form.Controls.Add($Button7)
#Add Button event
$Button6.Add_Click($Button6)
$Button7.Add_Click($Button7)
$form.ShowDialog()