CMD
Here are 5 useful CMD scripts for system administrators that can help automate common tasks and improve efficiency:
- Check Disk Space Usage
This script checks the available disk space on all drives and outputs the results in a readable format.
wmic logicaldisk get deviceid, volumename, description, freespace, size
This command will display the drive letter (DeviceID), volume name, description, free space, and total size for all connected disks.
- List Installed Programs
This script retrieves a list of all installed programs from the system.
wmic product get name, version
This command lists the names and versions of installed software, useful for inventory management or troubleshooting.
- System Information Report
This script generates a detailed system information report, including the OS, CPU, RAM, and more.
systeminfo
It will display detailed system configuration information, including the OS build, memory, network adapter, and more.
- Ping Multiple Servers
This script pings multiple servers or IP addresses to check their connectivity.
for %i in (server1.com, server2.com, 192.168.1.1) do ping %i
Replace server1.com, server2.com, and 192.168.1.1 with your server names or IPs. This command will loop through and ping each one, showing whether the servers are online or not.
- Export Active Directory Users (if using AD)
This script exports a list of Active Directory users to a text file.
dsquery user “OU=Users,DC=example,DC=com” -limit 0 > C:\AD_Users.txt
This command will export all users from the specified Organizational Unit (OU) in Active Directory and save it to C:\AD_Users.txt. Modify the OU and domain accordingly.
PowerShell
Here are 5 useful PowerShell scripts for system administrators that can help with various administrative tasks:
- Check Disk Space Usage
This script checks the available disk space on all drives and displays the results.
Get-PSDrive -PSProvider FileSystem
This command will display the used and free space on all drives, including file system drives, helping you monitor disk usage.
- List Installed Programs
This script lists all installed programs on the system along with their versions.
Get-WmiObject -Class Win32_Product | Select-Object Name, Version
This command fetches the names and versions of all installed software on the system, useful for software inventory.
- System Information Report
This script generates a detailed system information report, including OS, CPU, RAM, and more.
Get-ComputerInfo
This command provides detailed information about the system, including OS version, CPU, RAM, network adapter, and more.
- Ping Multiple Servers
This script pings multiple servers or IP addresses to check their connectivity.
$servers = “server1.com”, “server2.com”, “192.168.1.1”
foreach ($server in $servers) {
Test-Connection -ComputerName $server -Count 1
}
This script pings multiple servers or IP addresses, one by one, and checks whether they are reachable. Replace the server names/IPs with your actual servers.
- Export Active Directory Users (Requires Active Directory Module)
This script exports a list of Active Directory users to a CSV file.
Get-ADUser -Filter * -Property DisplayName | Select-Object DisplayName, SamAccountName | Export-Csv “C:\AD_Users.csv” -NoTypeInformation
This command retrieves all users from Active Directory and exports their DisplayName and SamAccountName to a CSV file located at C:\AD_Users.csv. Make sure the A
Bash
Here are 5 useful Bash scripts for system administrators that can help with a variety of tasks:
- Check Disk Space Usage
This script checks the available disk space on all mounted filesystems.
df -h
This command will display the disk usage in a human-readable format (-h), showing the total, used, and available space for all mounted drives.
- List Installed Packages (Debian/Ubuntu-based)
This script lists all installed packages on a Debian/Ubuntu-based system.
dpkg –get-selections | grep -v deinstall
This command lists all installed packages (excluding uninstalled ones) on systems like Debian and Ubuntu.
For Red Hat/CentOS/Fedora systems, use:
rpm -qa
- System Information Report
This script provides detailed information about the system, including the OS, CPU, and memory.
uname -a && lscpu && free -h
uname -a: Displays system information like the kernel version and OS.
lscpu: Shows detailed information about the CPU.
free -h: Displays memory usage in a human-readable format.
- Ping Multiple Servers
This script pings multiple servers or IP addresses to check their connectivity.
for server in server1.com server2.com 192.168.1.1; do
ping -c 1 $server && echo “$server is reachable” || echo “$server is unreachable”
done
This command pings each server/IP address listed and prints whether the server is reachable or not. You can replace the servers with your actual server names or IPs.
- List and Export Active Directory Users (Using LDAP)
This script exports a list of Active Directory users using LDAP queries.
ldapsearch -x -b “dc=example,dc=com” “(objectClass=user)” cn | grep “cn:” > AD_Users.txt
This command queries an Active Directory server (replace dc=example,dc=com with your domain's details) to fetch all users' Common Names (cn). The output is saved to AD_Users.txt.
You will need to have ldap-utils installed and access to an LDAP server (typically your domain controller).