Lesson -3 : Using the command line for Administration
General Server Management
>>> Get-ComputerInfo // same as systeminfo
What is Get-WindowsFeature?
Get-WindowsFeature is a PowerShell cmdlet used to:
✔️ View all Windows Server roles and features
✔️ Check which features are installed or available
✔️ Manage server components
It’s part of Windows Server administration tools.
What does Add-Computer do?
👉 It allows you to:
- Join a PC to an Active Directory domain
- Move a computer to a different domain
- Add it to a workgroup
What does Remove-Computer do?
👉 It:
- Disconnects the PC from an Active Directory domain
- Moves it to a workgroup
- Requires a restart to complete
What does Rename-Computer do?
👉 It:
- Changes the system (host) name
- Can be used on local or remote computers
- Usually requires a restart
Rename-Computer -NewName "NewPCName"
Restart-Computer -ComputerName <server_name> -Wait -For PowerShell ; Write-Host "DONE"
Restart-Computer -ComputerName
check the connectivity
What is Test-ComputerSecureChannel?
Test-ComputerSecureChannel is a PowerShell cmdlet used to:
Test-ComputerSecureChannel -Repair 👉 Check if a computer’s secure connection with a domain is working properly
It is used in Windows domain environments (Active Directory).
🔐 What is a Secure Channel?
When a computer joins a domain, it creates a secure trust relationship with the domain controller.
👉 This cmdlet checks:
- Is the trust still valid?
-
Can the computer authenticate with the domain?
>>> Test-ComputerSecureChannel
>>> Test-ComputerSecureChannel -Repair
What does Get-Date do?
👉 It shows:
- Current date
- Current time
- System’s time zone info
What does Get-TimeZone do?
👉 It shows:
- Current time zone name
- Offset from UTC
- Whether Daylight Saving Time (DST) is used
What does Set-Date do?
👉 It allows you to:
- Set a new date
- Set a new time
- Adjust system clock manually
>>> Set-Date -Date "YYYY-MM-DD HH:MM:SS"
Set full date and time
>>> Set-Date -Date "2026-04-15 10:30:00"
Change only date
>>> Set-Date -Date "2026-12-25"
Change only time
>>> Set-Date -Time "14:00:00"
Add or subtract time
Set-Date -Adjust (New-TimeSpan -Days 1)
Network Settings
What is Get-NetIPAddress?
Get-NetIPAddress is used in PowerShell to:
👉 View IP address configuration of your system
What is Get-NetAdapterStatistics?
👉 It shows data traffic details such as:
- Bytes sent & received
- Packets sent & received
- Errors and discards
What is Get-DnsClient?
Get-DnsClient is used in PowerShell to:
👉 View DNS client settings for your network adapters
What is Get-DnsClientServerAddress?
Get-DnsClientServerAddress is used in PowerShell to:
👉 View the DNS server IP addresses configured on your computer
What is Get-NetFirewallRule?
Get-NetFirewallRule is a PowerShell cmdlet used to:
👉 View firewall rules configured on your system
It works in PowerShell with the built-in Windows firewall.
ping , works on powershell
What is Test-Connection?
In PowerShell,
👉 Test-Connection works like the ping command
It sends network requests to see if a server or computer is reachable.
What is Test-NetConnection?
👉 It checks:
- If a server/website is reachable
- Port connectivity (very important)
- DNS resolution
- Network route (traceroute-like info)
>>> Test-NetConnection <ComputerName> -Port 80
Traceroute (PowerShell / Windows)
Traceroute is a network diagnostic tool used to track the path (route) that data takes from your computer to a destination server.
In PowerShell, the equivalent command is:
👉 tracert (Command Prompt)
👉 or Test-NetConnection -TraceRoute (PowerShell)
>>> Test-NetConnection google.com -TraceRoute
similar to > tracert google.com
Overview of Hyper -V
1. Check Hyper-V feature
>>> Get-WindowsFeature -Name Hyper-V
2. Install Hyper-V
>>> Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart
Virtual Machine (VM) Commands
List all VMs
>>> Get-VM
Create a new VM
>>> New-VM -Name "TestVM" -MemoryStartupBytes 2GB -Generation 2 -NewVHDPath "C:\VMs\TestVM.vhdx" -NewVHDSizeBytes 20GB
Start a VM
>>> Start-VM -Name "TestVM"
Stop a VM
>>> Stop-VM -Name "TestVM"
Restart VM
>>> Restart-VM -Name "TestVM"
Delete VM
>>> Remove-VM -Name "TestVM"
Disk & Storage Commands
9. Create virtual hard disk
>>> New-VHD -Path "C:\VMs\disk.vhdx" -SizeBytes 50GB -Dynamic
10. Attach disk to VM
>>>Add-VMHardDiskDrive -VMName "TestVM" -Path "C:\VMs\disk.vhdx"
Network Commands
11. List virtual switches
Get-VMSwitch
12. Create virtual switch
>>> New-VMSwitch -Name "ExternalSwitch" -NetAdapterName "Ethernet" -AllowManagementOS $true
13. Connect VM to switch
>>> Connect-VMNetworkAdapter -VMName "TestVM" -SwitchName "ExternalSwitch"
Snapshot (Checkpoint) Commands
14. Create checkpoint
>>> Checkpoint-VM -Name "TestVM"
15. View checkpoints
>>> Get-VMSnapshot -VMName "TestVM"
16. Restore checkpoint
>>> Restore-VMSnapshot -VMName "TestVM" -Name "CheckpointName"
Useful Monitoring Commands
17. VM status
>>> Get-VM | Select Name, State, CPUUsage, MemoryAssigned
18. Detailed VM info
>>> Get-VM -Name "TestVM" | Format-List *
Powershell comparison operators
| Operator | Meaning | Example |
|---|---|---|
-eq | Equal to | 5 -eq 5 → True |
-ne | Not equal | 5 -ne 3 → True |
-gt | Greater than | 10 -gt 5 → True |
-lt | Less than | 2 -lt 5 → True |
-ge | Greater or equal | 5 -ge 5 → True |
-le | Less or equal | 3 -le 5 → True |
Querying Active Directory
Requirement
👉 Install/import AD module in PowerShell
>>> Import-Module ActiveDirectory
Basic AD Query Commands
Get all users
>>> Get-ADUser -Filter *
Get specific user
Show user properties
>>> Get-ADUser -Identity "john" -Properties *
Get selected properties (human readable)
>>> Get-ADUser -Filter * | Select Name, SamAccountName, Enabled

Comments
Post a Comment