.NET Logo
Welcome Guest Search | Active Topics | Members | Log In | Register

powershell คร้ังที่ 10 Options · View
paedotnet
Posted: Sunday, December 23, 2007 10:30:02 PM

Rank: มือเทพ
Groups: Member

Joined: 12/6/2007
Posts: 345
Location: bkk

การจัดการกับ 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]
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.


Sponsored by