PowerShell Tip Remote Management using Windows PowerShell

0
993

PowerShell สามารถเปิดช่องทางการ Execute Command ผ่านทาง remote console ได้ด้วย ซึ่งประหยัด Bandwidth ในการ Remote ไปยัง Server และเพิ่มความสะดวกในการ Execute คำสั่งบางอย่างที่ Administrator ต้องใช้งานเป็นประจำให้รวดเร็วขึ้น

ตัวอย่างการใช้งาน

เครื่อง Client Windows 8 ของ Administrator ใช้ Remote PowerShell ไปยังเครื่อง Windows Server 2012R2

PowerShell Tip Remote Management using Windows PowerShell

การตั้งค่าที่ฝั่งเครื่อง Windows Server2012R2

enable-psremoting

PowerShell Tip Remote Management using Windows PowerShell

กด Y เพื่อให้ Server ช่วยเปิด Port Firewall ให้หมด หากมี Firewall อื่น ๆ กั้นอยู่ให้

เช็คที่ Firewall แล้วตรวจสอบ remote ต่าง ๆ ว่าได้ Allow ไว้หรือยัง โดย Port ที่ต้องใช้คือ

TCP/5985

TCP/5986

PowerShell Tip Remote Management using Windows PowerShell

หากมี Server หลายเครื่องและ Join Domain อยู่แล้ว สามารถสั่งโดยใช้ GPO อันนี้ได้เลยครับ

การเพิ่ม Enable WMI Remote Management

Computer Configuration > Policies > Windows Settings > Security Settings > Windows Firewall with Advanced Security > Global Settings

 

PowerShell Tip Remote Management using Windows PowerShell

PowerShell Tip Remote Management using Windows PowerShell

การตั้งค่าที่เครื่อง Client Windows8

ตั้งค่า TrustedHosts เพื่อให้ remote command ได้

Get-Item WSMan:\localhost\Client\TrustedHosts

PowerShell Tip Remote Management using Windows PowerShell

set-item wsman:\localhost\Client\TrustedHosts -value *

PowerShell Tip Remote Management using Windows PowerShell

วิธีใช้งาน Remote PowerShell วิธีที่ 1 (ใช้จาก Console PowerShell.exe)

ทดสอบ Ping ดูก่อนครับ ถ้า Client เชื่อมต่อกับ Server ได้แล้วก็ใช้คำสั่งนี้เลย

Enter-PSSession –computername 10.28.106.121 –credential $cred

จากนั้นระบบจะถาม User / Password ที่มีสิทธิ์เข้าไปจัดการ Server ก็ใส่ตามสบายครับ

PowerShell Tip Remote Management using Windows PowerShell

ใส่แล้วก็จะได้ Session เหมือนทำงานอยู่บน Windows Server 2012R2 ตามนี้เลยครับ

PowerShell Tip Remote Management using Windows PowerShell

วิธีใช้งาน Remote PowerShell วิธีที่ 2 (ใช้จาก Console PowerShell ISE)

ใน Windows 8 มี PowerShell ISE ติดตั้งมาโดย Default แล้วครับเปิดขึ้นมาใช้แล้วเลือก File > New Remote PowerShell Tab

PowerShell Tip Remote Management using Windows PowerShell

จะมีหน้าจอมาถาม User / Password ด้วยครับ

PowerShell Tip Remote Management using Windows PowerShell

จากนั้นก็ตามสบายเช่นเคย Remote ได้แล้วครับ เยห์

PowerShell Tip Remote Management using Windows PowerShell

เพิมเติม คู่มือการติดตั้ง Windows PowerShell Web Access บน Windows Server 2012 อ่านได้จาก link ด้านล่างนี้ครับ

http://wp.me/p2KHv9-14D