Powershell
Windows Powershell ile GUI alan oluşturmak
Windows Powershell kodlama yapmak yerine bir GUI oluşturmak ve bu GUI üzerinden işlem yapmaya olana sağlayan bir stracture sahiptir. Bunu .Net class ve objelerine bağlanarak yapar. Aşağıda örnek bir Powershell GUI arayüz kodlaması paylaşıyorum.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
#Add-Type cmdlet'i, PowerShell oturumunuzda bir Microsoft .NET Core sınıfı tanımlamanıza olanak tanır. Ardından, New-Object cmdlet'ini kullanarak nesneleri somutlaştırabilir ve nesneleri herhangi bir .NET Core nesnesini kullandığınız gibi kullanabilirsiniz. Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing $AdmissionsAccount = New-Object System.Windows.Forms.Form $AdmissionsAccount.Text = "Create a New Account" $AdmissionsAccount.Size = New-Object System.Drawing.Size(300,300) $AdmissionsAccount.MaximizeBox = $false $AdmissionsAccount.MinimizeBox = $false $AdmissionsAccount.ControlBox = $true $TextBox_FName = New-Object System.Windows.Forms.TextBox $TextBox_FName.Location = New-Object System.Drawing.Size(25,40) $TextBox_FName.Size = New-Object System.Drawing.Size(250,20) $TextBox_FName.Text = "First Name" $AdmissionsAccount.Controls.Add($TextBox_FName) $TextBox_LName = New-Object System.Windows.Forms.TextBox $TextBox_LName.Location = New-Object System.Drawing.Size(25,70) $TextBox_LName.Size = New-Object System.Drawing.Size(250,20) $TextBox_LName.Text = "Last Name" $AdmissionsAccount.Controls.Add($TextBox_LName) $TextBox_UName = New-Object System.Windows.Forms.TextBox $TextBox_UName.Location = New-Object System.Drawing.Size(25,100) $TextBox_UName.Size = New-Object System.Drawing.Size(250,20) $TextBox_UName.Text = "User Name" $AdmissionsAccount.Controls.Add($TextBox_UName) $TextBox_Job = New-Object System.Windows.Forms.TextBox $TextBox_Job.Location = New-Object System.Drawing.Size(25,130) $TextBox_Job.Size = New-Object System.Drawing.Size(250,20) $TextBox_Job.Text = "Job Title" $AdmissionsAccount.Controls.Add($TextBox_Job) $TextBox_EmID = New-Object System.Windows.Forms.TextBox $TextBox_EmID.Location = New-Object System.Drawing.Size(25,160) $TextBox_EmID.Size = New-Object System.Drawing.Size(250,20) $TextBox_EmID.Text = "Employee ID" $AdmissionsAccount.Controls.Add($TextBox_EmID) $Button_Close = New-Object System.Windows.Forms.Button $Button_Close.Location = New-Object System.Drawing.Size(25,200) $Button_Close.Size = New-Object System.Drawing.Size(120,25) $Button_Close.TextAlign = "MiddleCenter" $Button_Close.Text = "Create User Account" $Button_Close.Add_Click({$AdmissionsAccount.Close()}) $AdmissionsAccount.Controls.Add($Button_Close) $AdmissionsAccount.Add_Shown({$AdmissionsAccount.Activate()}) [Void]$AdmissionsAccount.ShowDialog() $NewUser = [ordered]@{FirstName=($TextBox_FName).Text; LastName=($TextBox_LName).Text; Username=($TextBox_UName).Text; Title=($TextBox_Job).Text; Employee=($TextBox_EmID).Text} Return $NewUser |