原本這篇文章應該是上午就寫完的,結果,不得不認可本身有點懶,對最近手頭上作的項目作了些總結,Powershell開發運維,也作了一段時間了,今天就來講說那些簡單的GUI的編程運維,首先從彈出窗口提及吧。shell
彈出窗口就本身在寫PS GUI代碼是常常用到的有3種方式,wscript方式,Forms方式,VB方式,先說說Wscript方式,這種方式最簡單,也最簡陋,只須要兩行代碼就能夠簡單作出彈出窗口。編程
Wscript方式:運維
function Read-MessageBoxDialogide
{spa
$PopUpWin = new-object -comobject wscript.shellorm
$PopUpWin.popup("Hello World")blog
}ip
Read-MessageBoxDialog開發
Forms方式,相對於Wscript方式來講,這種方式寫的代碼比較多可是呈現的樣式比較親切get
function Read-MessageBoxDialog
{
param ([string]$Message,
[string]$WindowTitle,
[System.Windows.Forms.MessageBoxButtons]$Buttons = [System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]$Icon = [System.Windows.Forms.MessageBoxIcon]::None)
Add-Type -AssemblyName System.Windows.Forms
return [System.Windows.Forms.MessageBox]::Show($Message, $WindowTitle, $Buttons, $Icon)
}
Read-MessageBoxDialog -Message "Hello World" -WindowTitle "CustomTitleHere" -Buttons OK -Icon Information
最後一種方式就是VB方式,這種方式是在PS中調用VB的方式來進行彈出窗口,樣式與Forms基本相似
function Read-MessageBoxDialog
{
param ([string]$Message,[string]$WindowTitle)
Add-Type -AssemblyName Microsoft.VisualBasic
return [Microsoft.VisualBasic.Interaction]::MsgBox($Message,'Information',$WindowTitle)
}
Read-MessageBoxDialog -Message "Hello World" -WindowTitle "CustomTitleHere"
最後能夠看出VB的樣式與Forms樣式同樣,可是代碼要比Forms的少不少,若是隻是提示窗口,建議用VB形式,若是想讓提示窗口顯示爲Information形式,而且OK與Cancel按鈕同時存在就將Forms方式中的Buttons屬性設置爲 OKCancel
function Read-MessageBoxDialog
{
param ([string]$Message,
[string]$WindowTitle,
[System.Windows.Forms.MessageBoxButtons]$Buttons = [System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]$Icon = [System.Windows.Forms.MessageBoxIcon]::None)
Add-Type -AssemblyName System.Windows.Forms
return [System.Windows.Forms.MessageBox]::Show($Message, $WindowTitle, $Buttons, $Icon)
}
Read-MessageBoxDialog -Message "Hello World" -WindowTitle "CustomTitleHere" -Buttons OKCancel -Icon Information