Skip to content

mvpskill.com | Change the World by Contributions.

IT Professionals Knowledge Base

  • Home
  • Latest
  • MS Azure
  • MS 365
  • MS Copilot
  • MS PowerPlatform
  • ServiceNow
  • Events
  • Live
  • About Us

ตัวอย่างการใช้งาน PowerShell กับ user, OU, Groups, Computer Account

ก่อนนำไปประยุกต์ใช้ให้เข้าใจตรงกันก่อนนะครับ

Domain = demo.local

คำสั่ง PowerShell เพื่อเปลี่ยน List User Account

Get-Help Get-ADUser -Parameter Properties(พิมพ์คำสั่งนี้เพื่อดูตัวอย่างการใช้งานคำสั่ง –Parameter ของ Get-ADUser)

 

Get-ADUser -Filter ‘office –eq ”BKK”‘ –Properties Office,StreetAddress,City,State,Country,PostalCode | Format-Table SamAccountName,Office,StreetAddress,City,State,Country,PostalCode (พิมพ์คำสั่งนี้เพื่อให้ PowerShell ทำการ List รายชื่อของพนักงานที่อยู่ Office BKK โดยเรียงข้อมูลที่ต้องการ)

ตัวอย่างการใช้งาน PowerShell กับ user, OU, Groups, Computer Account

1. คำสั่งเกี่ยวกับ Groups

Get-Help Get-ADGroup –Full (พิมพ์คำสั่งนี้เพื่อดูตัวอย่างการใช้งานคำสั่ง)

Get-ADGroup -Filter *

Get-ADGroup -Identity Sales (พิมพ์คำสั่งนี้เพื่อดู Group G-Finance)

ตัวอย่างการใช้งาน PowerShell กับ user, OU, Groups, Computer Account

Get-Help Get-ADGroupMember –Full(พิมพ์คำสั่งนี้เพื่อดูตัวอย่างการใช้งานคำสั่ง)

Get-Help Disable-ADAccount –Full(พิมพ์คำสั่งนี้เพื่อดูตัวอย่างการใช้งานคำสั่ง)

Get-ADGroup -Identity G-Finance | Get-ADGroupMember | Disable-ADAccount –WhatIf

ตัวอย่างการใช้งาน PowerShell กับ user, OU, Groups, Computer Account

การ Disable User ใน Group / Enable User ใน Group ด้วย Powershell

Get-ADGroup -Identity G-Finance | Get-ADGroupMember | Disable-ADAccount

Get-ADGroup -Identity G-Finance | Get-ADGroupMember | Enable-ADAccount

ตัวอย่างการใช้งาน PowerShell กับ user, OU, Groups, Computer Account

ตัวอย่างการ Enable User ใน Group Finance

ตัวอย่างการใช้งาน PowerShell กับ user, OU, Groups, Computer Account

การใช้งาน Powershell กับ OU

Get-Help Get-ADOrganizationalUnit –Full (พิมพ์คำสั่งนี้เพื่อดูตัวอย่างการใช้งานคำสั่ง)

Get-ADOrganizationalUnit -Filter * -Properties ProtectedFromAccidentalDeletion (พิมพ์คำสั่งนี้เพื่อดูว่า OU ไหนยังไม่ได้มีการป้องกันการถูกลบโดยไม่ตั้งใจ)

ตัวอย่างการใช้งาน PowerShell กับ user, OU, Groups, Computer Account

ใช้ Powershell ค้นหาเครื่อง Computer ที่เป็น Windows2008R2

Get-ADComputer -Filter ‘OperatingSystem -like “Windows Server 2008 R2*”‘ –Properties OperatingSystem,OperatingSystemHotfix,OperatingSystemServicePack,OperatingSystemVersion

ตัวอย่างการใช้งาน PowerShell กับ user, OU, Groups, Computer Account

Get-Help ConvertTo-Html –Full(พิมพ์คำสั่งนี้เพื่อให้แปลงผลที่ได้เป็น html)

Get-Help Out-File –Full(พิมพ์คำสั่งนี้เพื่อดูตัวอย่างการใช้งานคำสั่ง)

คำสั่งด้านล่างนี้ใช้เพื่อสร้าง Report ออกมาเป็น .html ครับ

Get-ADComputer -Filter ‘OperatingSystem -like “Windows Server 2008 R2*”‘ –Properties OperatingSystem,OperatingSystemHotfix,OperatingSystemServicePack,OperatingSystemVersion | ConvertTo-Html -Property Name,SID,OperatingSystem* | Out-File C:\OSList.htm

ตัวอย่างการใช้งาน PowerShell กับ user, OU, Groups, Computer Account

ใช้คำสั่ง PowerShell สร้าง OU

ใช้คำสั่งด้านล่างนี้ครับ (ในรูปตัวอย่างผมใช้งานจาก PowerShell ISE ทำการ RUN นะครับเพราะสามารถใช้ TAB ได้)

new-adorganizationalunit PowerShell

ตัวอย่างการใช้งาน PowerShell กับ user, OU, Groups, Computer Account

ใช้คำสั่ง PowerShell สร้าง User

New-ADUser -SamAccountName test02 -Name “test02” -UserPrincipalName [email protected] -AccountPassword (ConvertTo-SecureString -AsPlainText “password@1” -Force) -Enabled $true -PasswordNeverExpires $true -Path “OU=Engineer,DC=demo,DC=local”

ตัวอย่างการใช้งาน PowerShell กับ user, OU, Groups, Computer Account

ผลลัพธ์ที่ได้จากการ RUN PowerShell เพื่อสร้าง User = Test02 อยู่ใน OU = Engineer ครับ ตามรูปด้านล่าง

ตัวอย่างการใช้งาน PowerShell กับ user, OU, Groups, Computer Account

Share this:

  • Tweet

Like this:

Like Loading...

Related

This entry was posted in Active Directory & Group Policy, PowerShell and tagged Computer Account, Groups, OU, ตัวอย่างการใช้งาน PowerShell กับ user on October 18, 2012 by Suttipan Passorn.

About Suttipan Passorn

สุทธิพันธ์ ภัสสร | Suttipan Passorn | รางวัล Most Valuable Professional สาขา Management Infrastructure 2009 - ปัจจุบัน | ความรู้.....จะมีประโยชน์ก็ต่อเมื่อถูกนำมาจดบันทึกและแบ่งปัน | ผมใช้เวลาว่างเขียน Blog KB และ E-Book Free Download ขอให้มีความสุขกับการเข้ามาเยี่ยมชม Blog นี้ครับ ;)

View all posts by Suttipan Passorn →

Post navigation

← วิธีติดตั้ง Active Directory บน Server Core Note บทความที่กำลัง Share ผ่าน support.microsoft.com →

ค้นหาในเวป mvpskill

Monthly Archives

Reference

  • 5 นาทีกับ MVP 365
  • Active Directory & Group Policy
  • Azure
  • Certification & Exam
  • Download E-Book
  • Exchange&Outlook
  • Featured Posts
  • Free Training
  • Microsoft 365
  • Microsoft 365 Admin
  • Microsoft 365 Compliance
  • Microsoft 365 Copilot
  • Microsoft 365 Copilot Admin
  • Microsoft 365 Life
  • Microsoft 365 Security
  • Microsoft Office
  • Microsoft Teams
  • MVP Life
  • MVPSkill Events
  • Power Apps
  • Power Automate
  • Power BI
  • Power Platform
  • Power Virtual Agent
  • PowerShell
  • Product Update
  • SharePoint & OneDrive
  • Skype for Business
  • System Center
  • Tips & Technics
  • Tools
  • VDO Learning
  • Windows Client
  • Windows Security
  • Windows Server
  • Windows Server 2012
  • Yammer
  • นอกเรื่อง IT Pro
  • Share on Facebook (Opens in new window)Facebook
      Proudly powered by WordPress
      %d