การจัดการกับ COM
ถ้าเราต้องการสร้าง Window POPUP ใน powershell เราสามารถใช้ Window Script Host ดังนี้
$windows = New-Object -comObject wscript.shell
$windows.Popup("This is Test")
ผลลัพธ์จะมีหน้าต่าง window เกิดขึ้นมาโดย มีข้อความ This is Test
การเปิดใช้งาน Calculator
ก็พิมพ์คำสั่ง
cals
ผลลัพธ์จะมีเครื่องคิดเลขเกิดขึ้นมา
การเปิดใช้งาน Notepad
ก็พิมพ์
notepad
ผลลัพธ์จะมีโปรแกรม Nodepad เกิดขึ้นมา
การเปิด word
$openword = New-Object -comObject Word.Application
$openword.Visible = $true
ผลลัพธ์จะมีโปรแกรม word เกิดขึ้นมา
การเปิด Exel
$openexel = New-Object -comObject Word.Application
$openexel.Visible = $true
การจัดการทางด้าน network
$network = New-Object -comObject wscript.Network
$network
ผลลัพธ์แสดงดังรูป

การดู username,userdomain
$network.UserName
$network.UserDomain
การดูรายละเอียดเกี่ยวกับ network ของเครื่องใช้
ipconfig
การใช้ งาน Win32_NetworkAdapterConfiguration เพื่อดู Ip Address
$allip = Get-WmiObject -class Win32_NetworkAdapterConfiguration -computername . | Select-Object -Property IPAddress
$allip
หรือ
$allip = Get-WmiObject Win32_NetworkAdapterConfiguration | Format-Table *
$allip
เนื่องจากในตัวอย่างนี้ผลลัพธ์จะแสดงออกมาดังรูปที่ 2 ซึ่งรูปนี้ยังไม่ได้จัดรูป Format-table ตามสิ่งที่ต้องการดังนั้นตัวอย่างนี้เราจะจัดรูปก่อนดังนี้
$allip = Get-WmiObject Win32_NetworkAdapterConfiguration | Format-Table IpAddress,Description
$allip
การดุ MAC Address
$mac = Get-WmiObject Win32_NetworkAdapterConfiguration | Format-Table MacAddress
$mac
ผลลัพธ์จะแสดง mac address
การ ใช้ งาน Win32_PingStatus ในดูรายละเอีดยเกี่ยวกับ เครื่องที่ต้องการดู
Get-WmiObject -class Win32_PingStatus -filter "Address='ชื่อเครื่อง' "
ตรงชื่อเครื่องให้เราใส่ชื่อเครื่องลงไป
การใช้งาน Win32_OperatingSystem
Get-WmiObject Win32_OperatingSystem -property ServicePackMajorVersion -computer .
ตรง . หมายถึง เครื่องคอมพิวเตอร์ปัจจุบันที่ใช้งาน
[With great power comes great responsibility]