This article presents some useful Powershell commands for extracting data from the DBA. It is not exhaustive and will be completed over time. It is a collection of commands that can be found on different sites. This memo of Powershell commands avoids searching everywhere for commands that are often used but sometimes forgotten.
Counting the number of members of an AD group
(Get-ADGroup <group> -Properties *).Member.Count
Of course, you must replace with the name of the AD group. You can also specify the domain by adding “-Server” after the group name.
Finding disabled machines
Get-ADComputer -filter * -Server <server> -Properties OperatingSystem | Sort Name | Where-Object {$_.Enabled -like 'False'} | Format-Table Name,Enabled,OperatingSystem -AutoSize
This command allows you to highlight disabled machines in the AD. The “Operating System” column is used to filter machines.
Adding machines to an AD group
$ComputerList = "Computer1", "Computer2" $ADGROUP = "<ADGroup>" foreach ($Computer in $ComputerList) { Add-AdGroupmember -Identity $ADGROUP -Members $Computer echo $Computer }
This command allows you to add machines to an AD group in volume.