IT Support & Help Desk Fundamentals Module 5 – Windows client administration
Windows command line for support work
Read a PC's network, user and policy state with ipconfig and gpresult, run sfc, DISM and chkdsk in order, and swap WMIC for Get-CimInstance.
What you will learn
- Navigate, copy and remove files safely from Command Prompt and PowerShell
- Run ipconfig, whoami and gpresult to read a PC's network, user and policy state
- Run System File Checker, DISM and chkdsk in the right order and interpret what they report
- Replace removed WMIC commands with their Get-CimInstance equivalents
Before you start
What you’ll learn · Before you start
What you will learn
- Navigate, copy and remove files safely from Command Prompt and PowerShell
- Run ipconfig, whoami and gpresult to read a PC's network, user and policy state
- Run System File Checker, DISM and chkdsk in the right order and interpret what they report
- Replace removed WMIC commands with their Get-CimInstance equivalents
Before you start
On this page
A support ticket arrives: 4 of 8 project laptops cannot reach the file share after a weekend update. The technician who takes the call never sits at any of them. Three minutes later the desk knows which layer is wrong, because the first commands are the same every time: ipconfig to see each adapter’s state, ping to the gateway, nslookup against the office DNS and a Test-NetConnection to the share.
Windows ships two shells, Command Prompt and PowerShell, and most of a help desk’s work happens in one of them: reading a PC’s network, user and policy state, running the three repair commands in the right order, and copying files without ever losing one. You will do each of those on sample output written in the layouts Windows prints, in the order the desk follows them, and finish by swapping the old WMIC commands for their PowerShell replacements.
Command Prompt and PowerShell: two shells, the same tasks
Windows gives you two shells and both are built in. The Command Prompt: Windows' older command-line shell, cmd.exe, which runs built-in commands and classic utilities such as ipconfig and sfc, uses backslash paths, and prints help for each command when the command is called with /? at the end. runs the built-in commands that have shipped with Windows for decades, plus every classic utility such as ipconfig, whoami, sfc and chkdsk. PowerShell adds a second language on top: every command there is a PowerShell cmdlet: A PowerShell command of the shape Verb-Noun (Get-Process, Set-Location, Test-NetConnection), implemented in .NET and returning objects another cmdlet can take as input; Get-Help names its parameters and shows examples. of the form Verb-Noun (Get-Process, Test-NetConnection, Resolve-DnsName), each returning an object another cmdlet can take as input.
Most of a desk’s day is in Command Prompt because the muscle memory of dir, cd and copy is quick; PowerShell comes out when you need a filter the old commands cannot express (“every process whose name starts with Teams and uses more than 1 GB of memory”). The two shells share the same disk, so a file created in one is visible in the other at once.
The same work in the two shells, side by side:
| Task | Command Prompt | PowerShell |
|---|---|---|
| Change directory | cd C:\Users\lab-user |
Set-Location C:\Users\lab-user |
| List files | dir |
Get-ChildItem (ls is an alias) |
| Copy a file | copy report.docx .\backup\ |
Copy-Item report.docx .\backup\ |
| Delete a file | del notes.txt |
Remove-Item notes.txt |
| Show a file | type notes.txt |
Get-Content notes.txt |
| Help for a command | ipconfig /? |
Get-Help Test-NetConnection -Examples |
Microsoft’s Get-Help cmdlet is the PowerShell neighbour of /?: it reads the help topic that ships beside each cmdlet, and the -Examples switch jumps straight to the ones you can copy. For a Command Prompt utility, /? at the end prints the same information. Nobody memorises every switch; everybody looks them up.
Some commands need more rights than a normal sign-in gives. An elevated prompt: A Command Prompt or PowerShell window started with administrator rights, so commands that touch system files or settings succeed instead of being refused; whoami /groups prints a Mandatory Label of High Mandatory Level in such a window. is a Command Prompt or PowerShell window started with “Run as administrator”: sfc, DISM, chkdsk /f and anything that writes to HKEY_LOCAL_MACHINE need one. whoami /groups in that window lists Mandatory Label\High Mandatory Level, which is the quick way to tell. The Windows accounts, UAC and user profiles lesson goes into why.
One safety habit for every destructive command
Before del *.log, rd /s or Remove-Item -Recurse, list the same pattern with dir /s or Get-ChildItem -Recurse,
and before robocopy /mir run the same line once with /L. The list is what will go.
ipconfig shows the state of every adapter at once
The first command on nearly every connectivity ticket is ipconfig /all. Microsoft’s reference page says it “displays all current TCP/IP network configuration values and refreshes DHCP and DNS settings”; without parameters, it prints the IPv4 and IPv6 address, mask and default gateway for every adapter. The /all form adds the DNS servers, the physical (MAC) address and whether DHCP is on.
The output is a block of key-value lines per adapter, so a short script can turn it into records a technician can scan or a ticket system can file. The program below reads a sample in the layout ipconfig /all prints, with addresses from the documentation ranges (RFC 5737) and MAC addresses from the RFC 9542 documentation range, and returns one record per adapter and a list of flags for any adapter whose state is wrong:
# Read a sample of what `ipconfig /all` prints and summarise every adapter,
# with the three flags a help desk looks for: an APIPA address (RFC 3927,
# the 169.254.0.0/16 link-local range), an adapter with an IPv4 but no
# default gateway, and DHCP switched off on an adapter that has no address.
# The sample follows the field names Microsoft's ipconfig page documents
# (Description, DHCP Enabled, IPv4 Address, Subnet Mask, Default Gateway,
# DNS Servers, Media State, Autoconfiguration IPv4 Address). It is a sample
# written in that layout, with addresses from the documentation ranges
# (RFC 5737: 192.0.2.0/24, 198.51.100.0/24) and MAC addresses from RFC 9542.
SAMPLE = r"""Windows IP Configuration
Host Name . . . . . . . . . . . . : LAB-PC-07
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
Ethernet adapter Ethernet:
Connection-specific DNS Suffix . : corp.example
Description . . . . . . . . . . . : Intel(R) Ethernet Connection
Physical Address. . . . . . . . . : 00-00-5E-00-53-10
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IPv4 Address. . . . . . . . . . . : 192.0.2.47(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.0.2.1
DNS Servers . . . . . . . . . . . : 192.0.2.53
198.51.100.53
Wireless LAN adapter Wi-Fi:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Intel(R) Wi-Fi 6 AX201
Physical Address. . . . . . . . . : 00-00-5E-00-53-11
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Autoconfiguration IPv4 Address. . : 169.254.112.68(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . :
DNS Servers . . . . . . . . . . . :
Ethernet adapter Ethernet 2:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Realtek USB GbE Adapter
Physical Address. . . . . . . . . : 00-00-5E-00-53-12
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
"""
def _clean_key(part):
# The documented layout spells each key with trailing dot fillers,
# for example "DHCP Enabled. . . . . . . . . . . ". Strip the dots and
# spaces off the right so a plain name is left.
return part.strip().rstrip(". ").strip()
def _clean_value(value):
# Microsoft marks preferred and tentative addresses with a parenthesised
# note; the IPv4 for a parser is the address before the parenthesis.
return value.split("(", 1)[0].strip()
def parse_ipconfig(text):
"""Turn one `ipconfig /all` output into adapter records and flags.
Each adapter record is a dict with these keys:
name the heading after "adapter " (Ethernet, Wi-Fi, ...)
description the Description line
ipv4 IPv4 Address or Autoconfiguration IPv4 Address, as text
mask Subnet Mask, as text
gateway Default Gateway, as text ("" when the line is empty)
dhcp True for Yes, False for No, None when the key is missing
dns every DNS server listed under this adapter, in order
disconnected True when Media State says "Media disconnected"
The flags list holds (name, reason) tuples: APIPA (RFC 3927), an adapter
whose IPv4 is set but whose gateway is empty, and DHCP off with no IPv4.
Disconnected adapters are left out of the flags: they are off, not sick.
"""
adapters = []
current = None
expect_dns = False
for line in text.splitlines():
stripped = line.strip()
if not stripped:
expect_dns = False
continue
if (
line == line.lstrip()
and " adapter " in line
and line.endswith(":")
):
if current is not None:
adapters.append(current)
name = line.split(" adapter ", 1)[1].rstrip(":").strip()
current = {
"name": name,
"description": "",
"ipv4": "",
"mask": "",
"gateway": "",
"dhcp": None,
"dns": [],
"disconnected": False,
}
expect_dns = False
continue
if current is None:
continue
if ":" in line:
key_part, _, value = line.partition(":")
key = _clean_key(key_part)
value = value.strip()
if key == "DNS Servers":
expect_dns = True
if value:
current["dns"].append(value)
else:
expect_dns = False
if key == "Description":
current["description"] = value
elif key == "DHCP Enabled":
current["dhcp"] = value.lower() == "yes"
elif key in ("IPv4 Address", "Autoconfiguration IPv4 Address"):
current["ipv4"] = _clean_value(value)
elif key == "Subnet Mask":
current["mask"] = value
elif key == "Default Gateway":
current["gateway"] = value
elif key == "Media State" and value.lower() == "media disconnected":
current["disconnected"] = True
elif expect_dns:
current["dns"].append(stripped)
if current is not None:
adapters.append(current)
flags = []
for adapter in adapters:
if adapter["disconnected"]:
continue
if adapter["ipv4"].startswith("169.254."):
flags.append((adapter["name"], "APIPA: no DHCP reply, link-local address"))
if adapter["ipv4"] and not adapter["gateway"]:
flags.append((adapter["name"], "no default gateway"))
if adapter["dhcp"] is False and not adapter["ipv4"]:
flags.append((adapter["name"], "DHCP off and no address"))
return {"adapters": adapters, "flags": flags}
result = parse_ipconfig(SAMPLE)
print(f"{'adapter':<12}{'ipv4':<17}{'gateway':<12}{'dhcp':<6}dns")
for adapter in result["adapters"]:
if adapter["disconnected"]:
state = "down"
elif adapter["dhcp"] is False:
state = "off"
else:
state = "on"
dns = ", ".join(adapter["dns"]) or "-"
gateway = adapter["gateway"] or "-"
ipv4 = adapter["ipv4"] or "-"
print(f"{adapter['name']:<12}{ipv4:<17}{gateway:<12}{state:<6}{dns}")
print()
if not result["flags"]:
print("No flags: every connected adapter has an address and a gateway.")
for name, reason in result["flags"]:
print(f"{name}: {reason}") Output
adapter ipv4 gateway dhcp dns Ethernet 192.0.2.47 192.0.2.1 on 192.0.2.53, 198.51.100.53 Wi-Fi 169.254.112.68 - on - Ethernet 2 - - down - Wi-Fi: APIPA: no DHCP reply, link-local address Wi-Fi: no default gateway
Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 ipconfig_parse.py
Runs on this device, in your browser. The first run downloads Python (about 13.5 MB), which is kept for the next runs.
Your run, in this browser
Three things worth noticing in the run. The Ethernet adapter has a routable IPv4 and a gateway, and both of its DNS servers are listed under the one key: a classic working lease. The Wi-Fi adapter has the address 169.254.112.68, which is in the IPv4 link-local range 169.254.0.0/16 defined by RFC 3927; Microsoft calls it APIPA: Automatic Private IP Addressing, Windows' name for the IPv4 link-local range 169.254.0.0/16 defined by RFC 3927, which an adapter uses when DHCP cannot reach a server and which allows communication only on the same physical link. and gives it to an adapter when DHCP cannot reach a server. The script’s second flag, “no default gateway”, says the same thing from a different angle: an adapter with an IPv4 but no gateway can talk to its own subnet and nothing beyond it. The third adapter is physically disconnected, so it has no address and no flag; a disconnected adapter is off, not sick.
The companion commands fill in what ipconfig leaves out. hostname prints the computer name (useful before a remote command). systeminfo prints the Windows edition, build and the installed memory. whoami /upn is the one-line answer to “who am I signed in as”. Two MySmartCoPilot tools help with what ipconfig cannot see: what is my IP shows the public address the office’s traffic leaves from, and the subnet calculator works out which addresses a mask such as 255.255.255.0 puts on the same subnet.
Share only what the ticket needs
ipconfig /all prints MAC addresses, host names and connection-specific DNS suffixes. Those are tracking surfaces,
so redact them before you paste the output into a shared ticket. The PII redactor masks them
in text you are about to paste.
Checkpoint
Check: Command Prompt and PowerShell · Reading network state with ipconfig
Each rung of the connectivity ladder rules out one layer
The commands above read the PC’s own state; the next few test whether that state actually works. The order matters: each step rules out one layer, so skipping ahead means skipping evidence. The figure below walks the ladder in the order a help desk follows:
The drawing shows the whole scene; its 5 steps are listed below.
Every step as text
- Start with the PC's own address. ipconfig /all shows every adapter, its IPv4 address, mask, default gateway, DNS servers and whether DHCP is on. An APIPA address 169.254.x.x means no DHCP server answered, so check the link and the DHCP service before anything further up the ladder.
- Ping the gateway. ping 192.0.2.1 proves the link to the router is alive. A reply means the local subnet works; silence usually means a cable, Wi-Fi or switch problem, so going on to DNS or a web test would waste time.
- Resolve the name. nslookup intranet.corp.example, or Resolve-DnsName in PowerShell, asks the configured DNS server for the address of the service. A missing answer separates a name problem from a routing one, and names the DNS server that failed.
- Try the port. Test-NetConnection intranet.corp.example -Port 443 opens a TCP connection and reports TcpTestSucceeded True or False. Success rules out the firewall between PC and server; failure, after a good ping, points at the server or a firewall.
- Follow the path. tracert prints each router the packets pass, so a path that stops at a particular hop names the layer-3 device at fault; pathping measures loss on each hop over a few minutes, which catches a flaky link.
The first branch happens before the ladder even begins. An APIPA address or an empty one sends you back to DHCP, and a name that still points at an old address sends you to the DNS cache:
| Command | What it changes |
|---|---|
ipconfig /release, then /renew |
asks the DHCP server for a new lease |
ipconfig /flushdns |
empties the DNS resolver cache, nothing else |
Microsoft’s reference describes /flushdns as resetting the resolver cache; it does not touch the configured DNS
servers, the hosts file or an existing TCP connection.
Once the PC has an address, ping the default gateway. A reply says the local subnet works, and the problem is somewhere further out; silence says to look at cables, Wi-Fi, the switch or the VLAN first. Pinging an address outside the office that your network lets through, after that, separates “we can route” from “we cannot resolve names”.
Names move the ladder to DNS, then to the port, then along the path:
nslookup intranet.corp.exampleasks the configured server for the address of the host, andResolve-DnsNameis the PowerShell equivalent, returning objects you can filter. Both name the server that answered, so when a lookup fails the ticket already carries the DNS server to open with the next team; for a public name, the DNS lookup tool gives a second opinion from outside the office.Test-NetConnection intranet.corp.example -Port 443opens a TCP connection and reportsTcpTestSucceeded : TrueorFalse; the Microsoft page’s example 3 shows the full output with-InformationLevel Detailed.- Where it fails,
tracertnames each router on the way andpathpingmeasures loss on each hop over a few minutes, which catches a flaky link that a single ping misses.
Two more commands belong on this rung for a desk:
netstat -anolists every TCP connection and listening port on the PC with the owning process id (PID), so a “port 8080 is already in use” message leads straight to the application holding it; the Task Manager’s Details tab shows which program the PID belongs to, and the port number lookup says what a number such as 445, SMB’s own port, is used for.net uselists the drives mapped in the current session, andnet use Z: \\fileserver\sharemaps one; Microsoft’s reference lists/persistent:yesfor a mapping that should come back at the next sign-in.
Checkpoint
Check: The connectivity ladder
gpresult shows which policies reached a user, and gpupdate reapplies them
A domain-joined PC inherits settings from A directory-based system of settings for computers and users on a Windows domain or Microsoft Entra network, where an administrator writes rules once and every PC applies them. when it starts and when a user signs in, and refreshes them in the background between those times. When a change does not seem to have taken, two commands tell you where it is:
| Command | What it does |
|---|---|
gpupdate |
applies the policy settings that changed |
gpupdate /force |
reapplies every policy setting |
gpupdate /target:user |
refreshes only the user’s settings |
gpresult /r |
prints the Resultant Set of Policy summary |
gpresult /scope user |
limits the output to the user’s part |
gpresult /h report.html |
writes the same data as a web page |
gpupdate /force reapplies every policy setting rather than only the ones that changed, and Microsoft’s reference lists /boot and /logoff for the few settings that need a restart or a sign-out to apply.
gpresult /r is the second half of the pair. It prints the Resultant Set of Policy for the PC and the user: the computer object, the Organisational Unit, the security groups and, most useful of all, “Applied Group Policy Objects” and “The following GPOs were not applied because they were filtered out”. When a user says “the shortcut didn’t appear”, gpresult /r says whether the GPO reached them; gpresult /h report.html writes the same information as a web page the ticket can carry. /scope user and /scope computer narrow the output when it is long.
Reading the output together with a map of the organisation’s OUs is the technique: a policy applied at the OU above the user still appears here, with the OU named. Deeper directory lessons later in the track cover domain, OU and inheritance; here it is enough to know the pair of commands and that the output names every GPO that touched the sign-in.
Checkpoint
Check: Group Policy from the client
DISM repairs the store before sfc repairs the files
When a PC starts behaving as if a system file is damaged (features refuse to open, settings pages fail to load, the sign-in page is slow), Windows ships two tools that fix it, and the order Microsoft gives in its own support article is DISM first, then System File Checker: The Windows tool sfc, which scans every protected system file against its cached original and replaces any copy it finds damaged; sfc /scannow runs the whole scan from an elevated prompt and reports the result when it finishes. (sfc). The reason is that sfc /scannow copies clean files out of the component store, so the store itself has to be clean first:
The drawing shows the whole scene; its 6 steps are listed below.
Every step as text
- Scan the image, read only. An elevated prompt runs DISM /Online /Cleanup-Image /ScanHealth to see whether the component store is damaged. Nothing is changed; the report tells the technician whether a repair is needed before anything is downloaded.
- Refresh the component store. DISM /Online /Cleanup-Image /RestoreHealth asks Windows Update for a fresh copy of the component store that sfc will copy from. On a PC without internet, point /Source at a known-good Windows image with /LimitAccess.
- Replace the damaged files. sfc /scannow walks every protected system file and replaces any copy that no longer matches, using the store DISM just refreshed. It reports no violations, repairs made, or files it could not repair for the technician to decide on.
- Reboot to release locked files. Restart the PC once the repairs are done, so that Windows is running on the repaired files before you check the result.
- Run sfc once more. A second sfc /scannow after the restart is the check before the ticket closes. The line to expect is Windows Resource Protection did not find any integrity violations.
- Fix the file system on restart. If the first scan listed file-system errors, chkdsk C: /f runs at the next restart with the drive locked, because an online fix cannot repair a volume Windows is using. On an HDD, add /r to recover readable data from bad sectors.
Each step has one line to look for. DISM /Online /Cleanup-Image /ScanHealth ends with “No component store corruption detected” or “The component store is repairable”. DISM /Online /Cleanup-Image /RestoreHealth ends with “The restore operation completed successfully”. sfc /scannow ends with one of four lines Microsoft’s support article names: no violations found, could not perform the requested operation, found corrupt files and successfully repaired them, or found corrupt files but was unable to fix some of them. Each line has its own next step on that same page.
Rebuilding the component store with DISM: Deployment Image Servicing and Management, the Windows tool that services system images and the component store; Dism /Online /Cleanup-Image /RestoreHealth asks Windows Update for a fresh copy of the store so that sfc has clean files to copy from. is the step that takes several minutes and that needs internet, because its source is Windows Update. For a PC that cannot reach it, DISM ... /RestoreHealth /Source:<path> /LimitAccess points at a mounted Windows image instead, and the Microsoft page gives the exact form.
chkdsk is a different family. Microsoft’s page notes that it “checks the file system and file system metadata of a volume for logical and physical errors”. chkdsk C: with no switches is read-only. chkdsk C: /f fixes errors, but the volume must be locked, so Windows asks to schedule it at the next restart. /r on an HDD finds bad sectors and recovers readable data; on an SSD, the reference page says it is “faster but still requires reading every single sector”, and warns that repeated full-surface scans slightly reduce an SSD’s lifespan. On an NTFS volume chkdsk /scan runs an online scan without a lock, which fits a server that must stay up.
Key idea
DISM comes first, because sfc copies its clean files from the component store DISM repairs; a second sfc after a restart shows the clean result, and chkdsk is scheduled only when there are file-system errors to fix.
Checkpoint
Check: The repair order
A destructive command runs as a list first
A handful of commands can erase thousands of files, format a drive or wipe a volume. Each is useful, and each has a way to show what it would touch before it touches anything:
| Command | What it removes | Look first with |
|---|---|---|
robocopy /mir |
destination files missing from the source | the same line with /L |
del *.log, rd /s |
matching files, a whole folder tree | dir /s or Get-ChildItem -Recurse |
format D: |
everything on drive D | diskmgmt.msc or Get-Disk |
clean in diskpart |
the partitions of the selected disk | list disk: the asterisk marks it |
The most common of the four is robocopy. Microsoft’s reference says /mir “mirrors a directory tree”, which means it both copies new or changed files and deletes files in the destination that are missing from the source. That second half is why a wrong source turns a mirror job into a bulk delete. The safe routine is to run robocopy <source> <destination> /mir /L first; /L is “list only, do not copy, timestamp or delete any files” (from the Logging options), so the printout is exactly the file list the real run would act on. Only when that list is right is the /L removed.
The other three live in Command Prompt. del with a wildcard removes files but keeps the folder; rd /s removes a folder and everything under it. Try the pattern as dir /s or Get-ChildItem -Recurse first and read the list. format D: writes a fresh file system on a drive, so the first thing to check is the drive letter against diskmgmt.msc or Get-Disk. diskpart’s clean command removes the partitions of the disk it has selected, and clean all writes zeros over the whole disk. After select disk 1, diskpart answers that disk 1 is now the selected disk, and list disk marks the selected one with an asterisk; reading that line out loud before pressing Enter has saved more than one weekend.
/mir without /L
Wrong: robocopy C:\Projects \\backup\projects /mir run with the source and destination swapped by habit. Right:
the same command with /L first prints “Extra File …” for every file about to be deleted, so swapping the two is
caught before anything is lost. The default /r:1000000 /w:30 also means a single refused file can hold the job for
1,000,000 retries 30 seconds apart, about 347 days, so set /r:3 /w:5 for an interactive run.
Checkpoint
Check: Destructive commands and safety
WMIC is gone: Get-CimInstance replaces it
For many years the quick way to read a Windows PC’s hardware was WMIC: wmic bios get serialnumber or wmic cpu get name. Microsoft’s deprecated-features page says the Windows Management Instrumentation command-line utility is removed and is no longer available as a Feature on Demand on Windows 11, version 24H2 and later. WMI itself is unaffected; only the WMIC command is gone.
The replacement is PowerShell’s Get-CimInstance, which reads from the same CIM class: A Common Information Model class, such as Win32_BIOS, Win32_Processor or Win32_LogicalDisk, that PowerShell's Get-CimInstance cmdlet reads; each class has a documented set of properties the cmdlet returns for every instance. catalogue. The class and the property name are the same words:
| Old WMIC command | Replacement in PowerShell |
|---|---|
wmic bios get serialnumber |
(Get-CimInstance Win32_BIOS).SerialNumber |
wmic cpu get name |
(Get-CimInstance Win32_Processor).Name |
wmic computersystem get model |
(Get-CimInstance Win32_ComputerSystem).Model |
wmic logicaldisk get name,freespace |
Get-CimInstance Win32_LogicalDisk | Select-Object DeviceID, FreeSpace |
wmic nic where netenabled=true get name |
Get-CimInstance Win32_NetworkAdapter -Filter "NetEnabled=true" | Select-Object Name |
A few habits travel. The class name and the property name are what Microsoft’s reference lists, so a spelling you cannot remember is three clicks on the Get-CimInstance page away. Get-CimInstance -ClassName <class> | Format-List * prints every property of one object, which is quick when you need to find the right name. For reading the same values from another PC, add -ComputerName <name>, and the cmdlet uses the modern WS-Management protocol instead of DCOM.
Checkpoint
Check: WMIC removed, Get-CimInstance in its place
Practise: parse a sample ipconfig output
Every connectivity ticket starts with the same block of adapter lines. Write the parser that turns it into records a help desk can scan, and the three flags that catch the common cases: an APIPA address, an adapter with an IPv4 but no gateway, and DHCP switched off with no address. The sample tests include every one of those cases plus an adapter with two DNS servers.
Exercise · Easy · Python
Parse a sample ipconfig output
Write parse_ipconfig(text) so that it turns the text of one ipconfig /all output into a summary a help desk can scan. The function returns a dict with two keys, adapters and flags.
adaptersis a list of records in the order the adapters appear, one dict per adapter:name: the heading afteradapter(Ethernet,Wi-Fi,Ethernet 2, …);description: the Description line (empty string when missing);ipv4: the IPv4 Address or Autoconfiguration IPv4 Address, with any(Preferred)or similar note removed;mask: the Subnet Mask (empty when missing);gateway: the Default Gateway (empty when the line is blank);dhcp:TrueforYes,FalseforNo,Nonewhen the DHCP Enabled line is missing;dns: every DNS server listed under the adapter, as strings in order (including the second one on its own line for a two-server adapter);disconnected:Truewhen the adapter hasMedia State . . . : Media disconnected, elseFalse.
flagsis a list of(name, reason)tuples for the common states a help desk looks for. Use these exact reasons:"APIPA"when the adapter's IPv4 is in the 169.254.0.0/16 range (RFC 3927);"no default gateway"when the adapter has an IPv4 but the gateway is empty;"DHCP off and no address"whendhcpisFalseandipv4is empty.
A disconnected adapter has no flag: it is off, not sick.
Only the headings that match the layout <Type> adapter <Name>: start a new adapter (the Windows IP Configuration header is not an adapter). The sample tests cover an APIPA adapter, a missing gateway, a two-server DNS list, DHCP off with no address and a disconnected adapter.
Starter code · parse_ipconfig.py
def parse_ipconfig(text):
"""Return adapter records and flags for one `ipconfig /all` output."""
return {"adapters": [], "flags": []} The sample tests · test_parse_ipconfig.py
from parse_ipconfig import parse_ipconfig
APIPA_SAMPLE = r"""Windows IP Configuration
Host Name . . . . . . . . . . . . : LAB-PC-07
Wireless LAN adapter Wi-Fi:
Description . . . . . . . . . . . : Intel(R) Wi-Fi 6 AX201
Physical Address. . . . . . . . . : 00-00-5E-00-53-11
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration IPv4 Address. . : 169.254.112.68(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . :
DNS Servers . . . . . . . . . . . :
"""
ETHERNET_SAMPLE = r"""Ethernet adapter Ethernet:
Description . . . . . . . . . . . : Intel(R) Ethernet Connection
Physical Address. . . . . . . . . : 00-00-5E-00-53-10
DHCP Enabled. . . . . . . . . . . : Yes
IPv4 Address. . . . . . . . . . . : 192.0.2.47(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.0.2.1
DNS Servers . . . . . . . . . . . : 192.0.2.53
198.51.100.53
"""
DISCONNECTED_SAMPLE = r"""Ethernet adapter Ethernet 2:
Media State . . . . . . . . . . . : Media disconnected
Description . . . . . . . . . . . : Realtek USB GbE Adapter
DHCP Enabled. . . . . . . . . . . : No
"""
STATIC_NO_GATEWAY = r"""Ethernet adapter Ethernet 3:
Description . . . . . . . . . . . : Static-only adapter
DHCP Enabled. . . . . . . . . . . : No
IPv4 Address. . . . . . . . . . . : 203.0.113.9
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
"""
def test_apipa_flags_an_adapter_without_dhcp():
"""169.254.x.x and an empty gateway each raise a flag"""
result = parse_ipconfig(APIPA_SAMPLE)
assert len(result["adapters"]) == 1
adapter = result["adapters"][0]
assert adapter["name"] == "Wi-Fi"
assert adapter["ipv4"] == "169.254.112.68"
assert adapter["gateway"] == ""
assert ("Wi-Fi", "APIPA") in result["flags"]
assert ("Wi-Fi", "no default gateway") in result["flags"]
def test_ethernet_captures_two_dns_servers():
"""both DNS servers come back, in order"""
result = parse_ipconfig(ETHERNET_SAMPLE)
adapter = result["adapters"][0]
assert adapter["name"] == "Ethernet"
assert adapter["ipv4"] == "192.0.2.47"
assert adapter["mask"] == "255.255.255.0"
assert adapter["gateway"] == "192.0.2.1"
assert adapter["dhcp"] is True
assert adapter["dns"] == ["192.0.2.53", "198.51.100.53"]
assert result["flags"] == []
def test_disconnected_adapter_has_no_flag():
"""a disconnected adapter is off, not sick"""
result = parse_ipconfig(DISCONNECTED_SAMPLE)
adapter = result["adapters"][0]
assert adapter["disconnected"] is True
assert result["flags"] == []
def test_static_adapter_with_missing_gateway():
"""an adapter with a static IPv4 and no gateway still raises the gateway flag"""
result = parse_ipconfig(STATIC_NO_GATEWAY)
adapter = result["adapters"][0]
assert adapter["name"] == "Ethernet 3"
assert adapter["ipv4"] == "203.0.113.9"
assert adapter["gateway"] == ""
assert adapter["dhcp"] is False
assert result["flags"] == [("Ethernet 3", "no default gateway")], "a static address is not 'DHCP off and no address'"
def test_dhcp_off_with_no_address_flags_the_adapter():
"""DHCP off and no IPv4 raises the DHCP flag"""
text = r"""Ethernet adapter Ethernet 4:
Description . . . . . . . . . . . : Unused onboard adapter
DHCP Enabled. . . . . . . . . . . : No
Default Gateway . . . . . . . . . :
"""
result = parse_ipconfig(text)
assert ("Ethernet 4", "DHCP off and no address") in result["flags"]
def test_three_adapters_are_returned_in_order():
"""every adapter heading starts a new record"""
combined = APIPA_SAMPLE + "\n" + ETHERNET_SAMPLE + "\n" + DISCONNECTED_SAMPLE
result = parse_ipconfig(combined)
names = [adapter["name"] for adapter in result["adapters"]]
assert names == ["Wi-Fi", "Ethernet", "Ethernet 2"]
reasons = [reason for _, reason in result["flags"]]
assert "APIPA" in reasons
assert "no default gateway" in reasons A hint
An adapter line starts in column 0, contains adapter and ends with :. Everything else is indented. Inside an adapter, split a line on the first :: strip the trailing dot filler from the key (.rstrip('. ')) and compare the key names to the ones Microsoft documents. The DNS Servers key is followed by one indented line without a colon for every extra server, so remember that the last key seen was DNS Servers and append those lines to the current adapter's dns list.
Results of the sample tests
| Test | Result | Details |
|---|
What your code printed
The sample tests run on this device, in your browser (Pyodide): nothing is sent to mysmartcopilot.com. The first run downloads Python (about 13.5 MB), which is kept for the next runs. A check in your browser is feedback for you, not proof that the code is right for every input.
Practice that adapts to you
Practise this lesson
15 questions about 7 ideas of this lesson. Each answer is explained at once, and what you get right is kept in this browser.
Interview questions
Warm-up (fresher): what does ipconfig /flushdns actually change, and what does it leave alone?
It clears the DNS client resolver cache on the PC, so the next name lookup goes back to the configured DNS servers rather than reusing a cached answer. It changes nothing about the servers themselves, the hosts file, any adapter’s IP configuration or an open TCP connection, and it does not release or renew a DHCP lease; those are ipconfig /release and ipconfig /renew. The usual case is a service that moved to a new IP: once the cache is empty, the next nslookup or Resolve-DnsName returns the fresh answer. If a lookup still fails after a flush, the DNS server itself is the next thing to check, not the cache.
Two harder cases follow: a PC where sfc reports files it could not repair and that must stay online, and a mapped drive that works for one user and fails for the next on the same PC. Pick the first command you would run on each, then line it up against the opening step on its page:
Model answers open with any pass: ₹79 for 1 week ($2.99), one payment that never renews.
-
Mid to senior
A help desk runs sfc /scannow on a shared PC that must stay available during working hours. The scan ends with "Windows Resource Protection found corrupt files but was unable to fix some of them." What do you do next, and in what order?
-
Fresher to mid
Two users share one Windows PC. Z:\, mapped by net use at sign-in to \\fileserver\share, is there for one and missing for the other. Both sign in with their own domain accounts. Where do you look first, and what do you check in order?
Flashcards · 7 cards
Recall it, then check
Say the answer to yourself before you look: recalling it is what makes it stick.
-
How do you look up the switches of a classic command and of a PowerShell cmdlet?
Type /? after a classic command such as ipconfig, and use Get-Help for a cmdlet.
-
What does ipconfig /flushdns change, and what does it leave alone?
It clears the PC's DNS client cache, so the next lookup asks the configured DNS servers again. It leaves the servers, the hosts file, the adapter's IP settings, open connections and the DHCP lease alone; the lease is ipconfig /release and /renew.
-
What is the order of the connectivity ladder at the command line?
ipconfig /all for the PC's state, a ping to the gateway, a name lookup with nslookup or Resolve-DnsName, a port test with Test-NetConnection, then the path with tracert or pathping.
-
Which commands show whether a policy change reached a user, and apply it again?
gpresult /r lists the policies that applied, and gpupdate /force reapplies every setting rather than only the changed ones.
-
In what order do DISM, sfc and chkdsk run for a damaged Windows?
DISM first to refresh the component store, then sfc /scannow, then a second sfc after a restart to confirm. chkdsk C: /f is booked for the next restart, and only when there are file-system errors to fix.
-
How does a destructive command run safely?
Its listing form runs first, such as robocopy /L, dir before del, or diskpart's selected line read aloud. The list shows exactly what the real run will touch.
-
WMIC is gone from Windows 11, version 24H2. What replaces wmic bios get serialnumber?
Get-CimInstance, which reads the same classes: (Get-CimInstance Win32_BIOS).SerialNumber.
Key takeaways
- Command Prompt and PowerShell share the same disk and most of a desk’s commands have an equivalent in each;
/?after a classic command andGet-Helpfor a cmdlet are the two ways to look up switches. - The connectivity ladder is one order: read the PC’s state with
ipconfig /all, ping the gateway, resolve a name withnslookuporResolve-DnsName, test the port withTest-NetConnection, and follow the path withtracertorpathping. gpresult /ris the fastest answer to “did my policy change reach this user”, andgpupdate /forcereapplies every setting rather than only the changed ones.- The repair order is DISM first to refresh the component store, then
sfc /scannow, with a secondsfcafter a restart to confirm the result;chkdsk C: /fruns at the next restart because the system volume cannot be locked while Windows is on it. - Every destructive command runs its listing form first:
robocopy /L,delpreviewed withdir,diskpart’s “selected” line read out loud; the list is exactly what the real run will touch. - WMIC is removed from Windows 11, version 24H2 and later;
Get-CimInstancereads the same classes, so(Get-CimInstance Win32_BIOS).SerialNumberreplaceswmic bios get serialnumber.
Terms in this lesson
- APIPA
- Automatic Private IP Addressing, Windows' name for the IPv4 link-local range 169.254.0.0/16 defined by RFC 3927, which an adapter uses when DHCP cannot reach a server and which allows communication only on the same physical link.
- CIM class
- A Common Information Model class, such as Win32_BIOS, Win32_Processor or Win32_LogicalDisk, that PowerShell's Get-CimInstance cmdlet reads; each class has a documented set of properties the cmdlet returns for every instance.
- Command Prompt
- Windows' older command-line shell, cmd.exe, which runs built-in commands and classic utilities such as ipconfig and sfc, uses backslash paths, and prints help for each command when the command is called with /? at the end.
- DISM
- Deployment Image Servicing and Management, the Windows tool that services system images and the component store; Dism /Online /Cleanup-Image /RestoreHealth asks Windows Update for a fresh copy of the store so that sfc has clean files to copy from.
- elevated prompt
- A Command Prompt or PowerShell window started with administrator rights, so commands that touch system files or settings succeed instead of being refused; whoami /groups prints a Mandatory Label of High Mandatory Level in such a window.
- PowerShell cmdlet
- A PowerShell command of the shape Verb-Noun (Get-Process, Set-Location, Test-NetConnection), implemented in .NET and returning objects another cmdlet can take as input; Get-Help names its parameters and shows examples.
- System File Checker
- The Windows tool sfc, which scans every protected system file against its cached original and replaces any copy it finds damaged; sfc /scannow runs the whole scan from an elevated prompt and reports the result when it finishes.
References
- ipconfig (Microsoft)
- whoami (Microsoft)
- gpresult (Microsoft)
- gpupdate (Microsoft)
- sfc (Microsoft)
- Use the System File Checker tool to repair missing or corrupted system files (Microsoft)
- Repair a Windows Image (Microsoft)
- chkdsk (Microsoft)
- netstat (Microsoft)
- Net use (Microsoft)
- Test-NetConnection (Microsoft)
- Resolve-DnsName (Microsoft)
- Get-Help (Microsoft)
- Robocopy (Microsoft)
- Deprecated features for Windows client (Microsoft)
- Get-CimInstance (Microsoft)
- RFC 3927: Dynamic Configuration of IPv4 Link-Local Addresses (RFC Editor (IETF))
Related tools
Report a problem with this lesson
Kept only in this browser. Your Learn progress