Get the App
SLTechnology News&Howtos  ›  Servers  › 

Powshell looks up the computer name and account in the domain

Shulou Source: shulou.com Published: 2022-06-03 04:53:38 11月03日 Update

One of the requirements we get today is to find the statistics of computer accounts in the specified OU. It turns out that I often use Get-Aduser to find the domain account, and one of the commands I can think of is Get-Adcomputer.

Then can not help but open the www.bing.com to find, generally I am still used to using this search engine. There are not many people playing powershell in China.

Https://docs.microsoft.com/en-us/powershell/module/activedirectory/get-adcomputer?view=winserver2012-ps

These are some examples given by Microsoft officials.

My approach is to first use the following command to see all the properties of a computer account

Get-Adcomputer-Identity computer name-Properties *

It turned out to be a lot, and then I flipped through it and thought that Name and LastLogonDate should be useful. In fact, there are some methods on the Internet, but I just don't bother to use them. Then I generated the following command, which is also very practical.

Get-ADComputer-Filter-SearchBase "ou,dc=, dc=, dc="-Properties that ou= is looking for | Select-Object Name,LastLogonDate | out-file c:\ computername.txt

There are two points to note:

First, you need to use administrator privileges to open powershell, otherwise you cannot write to the local file.

Second, remove the out-file first, look at the results and then generate the file.

Searchbase this parameter does not understand, you can search more, in fact, it is very simple.

Tags: That is computers accounts commands files results search generation utility involuntary two examples practices parameters piles official attributes engines search engines methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn OPPO Reno MySQL Redmi macOS