ติดตั้งและจัดการ Windows Server 2022 ผ่าน PowerShell แบบมืออาชีพ

 PowerShell คือเครื่องมือที่ผู้ดูแลระบบ Windows Server ระดับมืออาชีพใช้งานทุกวัน เพราะช่วยให้สามารถบริหารจัดการ Server ได้รวดเร็วกว่า GUI หลายเท่า โดยเฉพาะในองค์กรที่มี Server จำนวนมาก

ปัจจุบัน Data Center และองค์กรขนาดใหญ่จำนวนมากใช้ PowerShell เป็นมาตรฐานในการติดตั้งและบริหาร Windows Server 2022

บทความนี้จะรวบรวมคำสั่ง PowerShell สำคัญที่ควรรู้สำหรับการติดตั้งและดูแล Windows Server

① PowerShell คืออะไร

PowerShell คือ Command-Line และ Scripting Platform ของ Microsoft

ใช้สำหรับ

  • บริหาร Server

  • ติดตั้ง Role

  • จัดการ Network

  • จัดการ User

  • Automation

ได้จากคำสั่งเพียงไม่กี่บรรทัด

② ทำไมต้องใช้ PowerShell

ข้อดี

  • เร็วกว่า GUI

  • ทำงานซ้ำอัตโนมัติได้

  • จัดการหลายเครื่องพร้อมกันได้

  • เหมาะกับ Server Core

จึงกลายเป็นมาตรฐานในองค์กรขนาดใหญ่

③ เปิด PowerShell แบบ Administrator

ค้นหา

PowerShell

จากนั้น

Run as Administrator

เพื่อให้มีสิทธิ์เต็มในการบริหารระบบ

④ ดูข้อมูลเครื่อง Server

Get-ComputerInfo

แสดง

  • OS Version

  • RAM

  • CPU

  • Hostname

  • Domain

ทั้งหมด

⑤ ดูชื่อเครื่อง

hostname

หรือ

$env:COMPUTERNAME

⑥ ดู IP Address

Get-NetIPAddress

แสดง IPv4 และ IPv6 ทั้งหมด

⑦ ดู Network Adapter

Get-NetAdapter

ตรวจสอบ

  • ความเร็ว

  • สถานะ

  • ชื่อ Interface

⑧ ดู Service ทั้งหมด

Get-Service

ใช้ตรวจสอบบริการที่กำลังทำงาน

⑨ รีสตาร์ต Service

ตัวอย่าง

Restart-Service WinRM

⑩ ดู Process ที่ทำงานอยู่

Get-Process

เหมาะสำหรับวิเคราะห์ปัญหา Performance

⑪ ดู Event Log

Get-EventLog -LogName System -Newest 20

ใช้ตรวจสอบ Error ล่าสุด

⑫ ดู Role และ Feature

Get-WindowsFeature

แสดงรายการทั้งหมดในระบบ

⑬ ติดตั้ง DNS Server

Install-WindowsFeature DNS -IncludeManagementTools

⑭ ติดตั้ง DHCP Server

Install-WindowsFeature DHCP -IncludeManagementTools

⑮ ติดตั้ง IIS

Install-WindowsFeature Web-Server -IncludeManagementTools

⑯ ติดตั้ง Hyper-V

Install-WindowsFeature Hyper-V -IncludeManagementTools -Restart

ระบบจะรีสตาร์ตอัตโนมัติ

⑰ เปลี่ยนชื่อเครื่อง

Rename-Computer -NewName "SRV01"

จากนั้น

Restart-Computer

⑱ ตั้งค่า Static IP

New-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress 192.168.1.10 -PrefixLength 24 -DefaultGateway 192.168.1.1

⑲ ตั้งค่า DNS

Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses 192.168.1.10

⑳ Join Domain ผ่าน PowerShell

Add-Computer -DomainName company.local

จากนั้น

Restart-Computer

㉑ เปิด Remote Desktop

Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections" -Value 0

㉒ เปิด Firewall สำหรับ RDP

Enable-NetFirewallRule -DisplayGroup "Remote Desktop"

㉓ รีสตาร์ต Server

Restart-Computer

㉔ ปิด Server

Stop-Computer

㉕ ดู Uptime ของเครื่อง

(Get-Date) - (gcim Win32_OperatingSystem).LastBootUpTime

ช่วยตรวจสอบว่าเครื่องเปิดมานานเท่าไร

㉖ ตรวจสอบพื้นที่ Disk

Get-Volume

㉗ ตรวจสอบ RAM

Get-CimInstance Win32_OperatingSystem | Select TotalVisibleMemorySize,FreePhysicalMemory

㉘ ใช้งานกับ Server Core

PowerShell คือเครื่องมือหลักของ

Server Core

เพราะไม่มี Desktop GUI

ผู้ดูแลระบบจึงต้องใช้ PowerShell เป็นประจำ

㉙ แนวทางสำหรับองค์กร

ควรฝึกใช้ PowerShell ตั้งแต่เริ่มต้น

โดยเฉพาะงาน

  • Network

  • User

  • Active Directory

  • Hyper-V

  • Automation

จะช่วยลดเวลาทำงานได้อย่างมาก

㉚ สรุป

PowerShell เป็นเครื่องมือสำคัญที่สุดตัวหนึ่งของ Windows Server 2022 และเป็นทักษะที่ผู้ดูแลระบบยุคใหม่ควรมี

คำสั่งพื้นฐานที่ควรจำ

  • Get-ComputerInfo

  • Get-Service

  • Get-WindowsFeature

  • Install-WindowsFeature

  • Restart-Computer

  • Get-NetIPAddress

comsiam แนะนำว่า หากต้องการก้าวสู่การเป็น System Administrator ระดับมืออาชีพ ควรเริ่มเรียนรู้ PowerShell ตั้งแต่วันแรก เพราะสามารถลดเวลาการบริหาร Server ได้หลายเท่า และเป็นมาตรฐานที่องค์กรทั่วโลกใช้งานจริง

Popular posts from this blog

Windows Server 2022 ยังน่าใช้ในปีนี้หรือไม่? คำตอบสำหรับคนกำลังวางระบบใหม่

สเปกเครื่องสำหรับติดตั้ง Windows Server 2022 เลือกอย่างไรให้คุ้มและใช้งานได้ยาว

Windows Server 2022 คืออะไร? คู่มือสำหรับมือใหม่