PowerShell實戰 第四回 管理AD計算機對象

那麼今天來學習點什麼呢?就介紹幾條比較常用的計算機管理的powershell命令吧。

1. 獲取計算機對象

Get-ADComputer –Filter *"

如果想獲取某個OU的計算機對象,可以加searchBase的命令來限制OU,如下:

Get-ADComputer –Filter * -searchBae "OU=melody,DC=contoso,DC=com" | select Name

2. 查詢90天內有登陸域的計算機賬號

Search-ADaccount -AccountInactive -Timespan 90 –ComputersOnly | select Name,LastLogondate

還有一條命令也可以篩選出,但是不能顯示出LastLogondate

$lastLogon = (get-date).adddays(-90).ToFileTime() Get-ADComputer -filter {lastLogonTimestamp -gt $lastLogon}

再附上一條更復雜點的命令

Get-ADComputer -Filter * -Properties * | ?{((get-date) - $_.LastlogonDate).days -gt 365} | Move-ADObject -TargetPath "ou=離職人員計算機賬戶,dc=contoso,dc=com" –verbose

3. 查詢域內計算機系統信息

Get-ADComputer -Filter * -Property * | Select-Object Name,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion, LastLogonDate | Export-CSV AllWindows.csv -NoTypeInformation -Encoding UTF8

4. 查詢計算機的IP信息

Get-ADComputer -Filter {Name -Like "Computer-Name"} -Properties IPv4Address | Format-List Name,DnsHostName,IPv4Address

發佈了46 篇原創文章 · 獲贊 7 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章