Powershell
PowerShell is a cross-platform task automation solution made up of a command-line shell, a scripting language, and a configuration management framework. PowerShell runs on Windows, Linux, and macOS.
As a scripting language, PowerShell is commonly used for automating the management of systems. It is also used to build, test, and deploy solutions, often in CI/CD environments. PowerShell is built on the .NET Common Language Runtime (CLR). All inputs and outputs are .NET objects.
Some of these script are custom written others were found while reasearching certain issues that I would run into over the years.
1. This script will get the last logon time of all users.
Get-ADuser -Filter * -Properties * | select-object CN,displayname,primarygroup,logoncount,modified,lastlogondate,created,whenchanged,Enabled | sort LastLogonDate | export-csv C:\temp\LastLogon.csv
2. This script will show who is logged in where. You can search by OU,All or Computer. It can take some time if you use the -ALL. you can run it in console or always export it to csv with the > asdf.csv
Powershell Get-UserLogon
3. Useful Commands
a. Get-ADDomain - Displays Domain Information
b. Get-ADDomainController -filter *| select hostname,operatingsystem - Gets all Domain Controller by Hostname and OS
c. invoke-command -ComputerName DC-Name -scriptblock {wbadmin start systemstateback up -backupTarget:"Backup-Path" -quiet} - This will back up the Domain Controllers system state data. Change DC-Name to your server name and change the path
d. Get-ADUser -SearchBase “OU=Mandysworld,dc=domain,dc=local” -Filter * - Get All Users From a Specific OU
e. Search-ADAccount -AccountDisabled | select name - Get All Disable User Accounts
f. Disable-ADAccount -Identity Kitiara - Disable User Account
g. Enable-ADAccount -Identity Tanis - Enable User Account
h. Search-ADAccount -LockedOut - Find all locked out users
i. Get-ADComputer -filter * | measure - Get a count of all computers in the domain
j. systeminfo | more - Get last boot time as well as additional info on hotfixes memory ect..