PowerShell Workbench GUI


#Author:KIVIN LIU
#Usage:
#1.Create folder C:\POWERSHELL\LOG and C:\POWERSHELL\WORKBENCH
#2.Run PowerShell ISE as Administrator, execute the commond Set-ExecutionPolicy UnRestricted
#3.Open the workbench file in the ISE and press F5 to run the command

CLS
if(Test-Path C:\POWERSHELL\WORKBENCH) #Create WORKBENCH DIRECOTRY
{}
else
{
mkdir -Path C:\POWERSHELL\WORKBENCH
}

if(Test-Path C:\POWERSHELL\LOG) #CREATE LOG FOLDER
{}
else
{
mkdir -Path C:\POWERSHELL\LOG
}
“”|out-file C:\POWERSHELL\LOG\Workbench.log #Initialize the Workbench selection

$WorkDirectory = ‘C:\POWERSHELL\WORKBENCH’ #Change the work directory to WORKBENCH
CD $WorkDirectory

Import-Module ActiveDirectory
$index = 1 #For Property search global variable /reset the index number
################################################WorkBench Form BEGIN########################################
[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)|out-null
[System.Reflection.Assembly]::LoadWithPartialName(“System.Drawing”)|out-null
$Workbench = New-Object System.Windows.Forms.Form
$workbench.Text = “PowerShell Workbench v2.0 IT Analyst: $env:Username” #Get the run as user and show the user on the workbench form title
$Workbench.Size = New-Object System.Drawing.Size(1000,600)
$Workbench.StartPosition = “CenterScreen”
$Workbench.KeyPreview = $True
$Workbench.MaximizeBox = $false

$mEmployeeID_Binding_Resources = New-Object System.Windows.Forms.Button
$mEmployeeID_Binding_Resources.Text=”EmployeeID Binding Resources”
$mEmployeeID_Binding_Resources.Location = New-Object System.Drawing.Size(40,40)
$mEmployeeID_Binding_Resources.Size = New-Object System.Drawing.Size(200,80)
$Workbench.Controls.Add($mEmployeeID_Binding_Resources)
$mEmployeeID_Binding_Resources.Add_Click(

{
$Workbench.Close()
1 |out-file C:\POWERSHELL\LOG\Workbench.log #Set the identity as 1 when select EmployeeID Binding Resources
}
)

$mUnlock_Reset_Pwd = New-Object System.Windows.Forms.Button
$mUnlock_Reset_Pwd.Text=”Unlock/Reset Password”
$mUnlock_Reset_Pwd.Location = New-Object System.Drawing.Size(40,250)
$mUnlock_Reset_Pwd.Size = New-Object System.Drawing.Size(200,80)
$Workbench.Controls.Add($mUnlock_Reset_Pwd)
$mUnlock_Reset_Pwd.Add_Click(

{
$Workbench.Close()
2 |out-file C:\POWERSHELL\LOG\Workbench.log #Set the identity as 2 when select Unlock /Reset password
}
)

$mProperty_Search = New-Object System.Windows.Forms.Button
$mProperty_Search.Text=”Property Search”
$mProperty_Search.Location = New-Object System.Drawing.Size(40,450)
$mProperty_Search.Size = New-Object System.Drawing.Size(200,80)
$Workbench.Controls.Add($mProperty_Search)
$mProperty_Search.Add_Click(

{
$Workbench.Close()
3 |out-file C:\POWERSHELL\LOG\Workbench.log #Set identity as 3 when select Property Search button
}
)

$mEmployeeID_Update = New-Object System.Windows.Forms.Button
$mEmployeeID_Update.Text=”EmployeeID Update”
$mEmployeeID_Update.Location = New-Object System.Drawing.Size(340,40)
$mEmployeeID_Update.Size = New-Object System.Drawing.Size(200,80)
$Workbench.Controls.Add($mEmployeeID_Update)
$mEmployeeID_Update.Add_Click(

{
$Workbench.Close()
4 |out-file C:\POWERSHELL\LOG\Workbench.log #Set identity as 4 when select Update EmployeeID
}
)

$mDL_SecurityGroup_Search = New-Object System.Windows.Forms.Button
$mDL_SecurityGroup_Search.Text=”DL/Security Group Description Search”
$mDL_SecurityGroup_Search.Location = New-Object System.Drawing.Size(340,250)
$mDL_SecurityGroup_Search.Size = New-Object System.Drawing.Size(200,80)
$Workbench.Controls.Add($mDL_SecurityGroup_Search)
$mDL_SecurityGroup_Search.Add_Click(

{
$Workbench.Close()
5 |out-file C:\POWERSHELL\LOG\Workbench.log #Set identity as 5 when select DL /Security Gr0up Search
}
)

$mPMS = New-Object System.Windows.Forms.Button
$mPMS.Text=”PMS”
$mPMS.Location = New-Object System.Drawing.Size(340,450)
$mPMS.Size = New-Object System.Drawing.Size(200,80)
$Workbench.Controls.Add($mPMS)
$mPMS.Add_Click(

{
$Workbench.Close()
6 |out-file C:\POWERSHELL\LOG\Workbench.log #Set identity as 6 when select PMS button
}
)

$mBrightSig = New-Object System.Windows.Forms.Button
$mBrightSig.Text=”BrightSig”
$mBrightSig.Location = New-Object System.Drawing.Size(650,40)
$mBrightSig.Size = New-Object System.Drawing.Size(200,80)
$Workbench.Controls.Add($mBrightSig)
$mBrightSig.Add_Click(

{
$Workbench.Close()
7 |out-file C:\POWERSHELL\LOG\Workbench.log #Set idenetity as 7 when select BrightSig button
}
)

$mUserViewer = New-Object System.Windows.Forms.Button
$mUserViewer.Text=”User Viewer”
$mUserViewer.Location = New-Object System.Drawing.Size(650,250)
$mUserViewer.Size = New-Object System.Drawing.Size(200,80)
$Workbench.Controls.Add($mUserViewer)
$mUserViewer.Add_Click(

{
$Workbench.Close()
8 |out-file C:\POWERSHELL\LOG\Workbench.log #Set identity as 8 when select UserViewer button
}
)

$mOther = New-Object System.Windows.Forms.Button
$mOther.Text=”Other”
$mOther.Location = New-Object System.Drawing.Size(650,450)
$mOther.Size = New-Object System.Drawing.Size(200,80)
$Workbench.Controls.Add($mOther)

$mOther.Add_Click(

{
$Workbench.Close()
9 |out-file C:\POWERSHELL\LOG\Workbench.log #Set identity as 9 when select other button
}
)

$Workbench.Add_KeyDown({if ($_.KeyCode -eq “Escape”)
{

$Workbench.Close()
Write-Host “Cancel!!!Exit!!!” -ForegroundColor Red

}})

$Workbench.ShowDialog()
$Workbench.Topmost = $False
$Workbench.Add_Shown($Workbench.Activate())

################################################WorkBench From END########################################

$WorkBenchSelection = Get-Content C:\POWERSHELL\LOG\Workbench.log #Get the identity from the log file
switch($WorkBenchSelection) #Different identity call different PowerShell Script file
{

1
{
.\Binding-VV-CSV-COM-AD-Random-EmployeeID-Reserve-DL-HotFix5-SAP.ps1
}
2
{
.\PS-Account-Locked-Out-Toolkit-Universal-U2.ps1
}
3
{
.\PS-ActiveDirectory-Searcher-U2.ps1
}
4
{}
5
{}
6
{}
7
{}
8
{}
9
{}
default
{
Write-Host “Wrong selection!!!Exit!!!” -ForegroundColor Red #For the default action on the identity
}
}

本文链接: http://www.pstips.net/powershell-workbench-gui.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

发表评论

电子邮件地址不会被公开。 必填项已用*标注