Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

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.

  • Beginner
  • 20 minutes
  • Examples run with Python 3.14.8 and Pyodide 314.0.7
  • By MySmartCoPilot
Free lesson, Pro answers: 20 minutes
Free: the whole lesson. With a pass: the model answers to its 2 interview questions.

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:

Reading a sample `ipconfig /all` into adapter records and flags Python · ipconfig/ipconfig_parse.py
# 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

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

  1. Question 1 of 2 In PowerShell, which command lists the files of the current directory?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: Get-ChildItem

    Every PowerShell command is a cmdlet of the form Verb-Noun. Get-ChildItem is the cmdlet for listing files, and dir and ls are built-in aliases of it, so all three work in PowerShell today.

  2. Question 2 of 2 ipconfig /all shows the IPv4 169.254.112.68 on the Wi-Fi adapter, and the default gateway line is empty. What does that mean?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: The adapter never heard back from a DHCP server and gave itself a link-local address

    169.254.x.x is APIPA, which Windows assigns when DHCP does not answer; the adapter can talk to its own link only. The next step is ipconfig /release and /renew, after checking cable, Wi-Fi and the DHCP server itself.

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:

Interactive · stage by stage The connectivity ladder a help desk runs in order Step through one connectivity ticket from the PC's own address to the service, and see which step rules out which layer.
The network checks a help desk runs in order, step 5 of 5. Showing ipconfig /all, ping the gateway, nslookup, Test-NetConnection, tracert. In focus: tracert.APIPA? renewNo replyOther DNSipconfig /allAddress and DNSping the gatewayLink alive?nslookupResolve the nameTest-NetConnectionTCP port open?tracertWhere it stops

The drawing shows the whole scene; its 5 steps are listed below.

Every step as text
  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.example asks the configured server for the address of the host, and Resolve-DnsName is 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 443 opens a TCP connection and reports TcpTestSucceeded : True or False; the Microsoft page’s example 3 shows the full output with -InformationLevel Detailed.
  • Where it fails, tracert names each router on the way and pathping measures 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 -ano lists 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 use lists the drives mapped in the current session, and net use Z: \\fileserver\share maps one; Microsoft’s reference lists /persistent:yes for a mapping that should come back at the next sign-in.

Checkpoint

Check: The connectivity ladder

  1. Question 1 of 2 A user cannot open the office intranet. ipconfig /all shows a routable IPv4 and a gateway. What is the next check?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: ping the default gateway

    The connectivity ladder goes one rung at a time. After reading the state with ipconfig /all, ping the default gateway: a reply confirms the local subnet, and silence stops the ladder on cable or Wi-Fi before anything else.

  2. Question 2 of 2 A service refuses to start because "port 8080 is already in use". Which command names the process holding the port?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: netstat -ano

    Microsoft's netstat page describes -o as adding the process id to each connection. From there, the Details tab of Task Manager (or Get-Process -Id <pid>) says which program is holding the port, so the fix is to stop it.

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

  1. One question Which command prints the Group Policy settings a PC has applied for the signed-in user?

    Choose one answer.

    Show the answer: One question

    Answer: gpresult /r

    gpresult /r is the report half of the pair; gpupdate /force is the apply half. The output names the OU, the security groups, the applied GPOs and the ones filtered out, which is the quickest answer to "did the change reach this user".

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:

Interactive · stage by stage DISM, then sfc, then sfc again, with chkdsk at the next restart Step through what the help desk runs in order when sfc reports damaged files it could not repair. Each step says what the previous one left.
The repair order for a damaged Windows installation, step 6 of 6. Showing DISM /ScanHealth, DISM /RestoreHealth, sfc /scannow, Reboot, sfc /scannow again, chkdsk /f at restart. In focus: chkdsk /f at restart.DISM /ScanHealthoptional, read-onlyDISM /RestoreHealthrefresh the component storesfc /scannowreplace damaged system filesRebootrelease locked filessfc /scannow againexpect no violationschkdsk /f at restartfile system, at next boot

The drawing shows the whole scene; its 6 steps are listed below.

Every step as text
  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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

  1. One question Why does the lesson say to run DISM before sfc, rather than starting with sfc /scannow?

    Choose one answer.

    Show the answer: One question

    Answer: sfc copies clean files from the component store, so the store itself has to be clean first

    sfc replaces damaged protected files with clean copies from the component store. If the store is also damaged, sfc has nothing clean to copy from, so DISM /RestoreHealth is the first command to run.

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

  1. One question A technician plans to run robocopy C:\Projects D:\Backup\Projects /mir. What is the safe first run?

    Choose one answer.

    Show the answer: One question

    Answer: robocopy C:\Projects D:\Backup\Projects /mir /L

    Robocopy's /L option lists what would happen without doing it, and /mir mirrors a tree, which means it deletes destination files that are missing from the source. A list-only run is the standing routine before every real one.

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

  1. One question Which PowerShell command returns the computer's BIOS serial number, as a replacement for wmic bios get serialnumber?

    Choose one answer.

    Show the answer: One question

    Answer: (Get-CimInstance Win32_BIOS).SerialNumber

    Get-CimInstance reads from the same CIM class library as WMIC did. The class and the property names are the ones WMIC used, so the pattern "(Get-CimInstance <class>).<Property>" translates every one-value WMIC query directly.

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.

  • adapters is a list of records in the order the adapters appear, one dict per adapter:
    • name: the heading after adapter (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: True for Yes, False for No, None when 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: True when the adapter has Media State . . . : Media disconnected, else False.
  • flags is 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" when dhcp is False and ipv4 is 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.

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.

  1. Question 1 of 15 Which line in whoami /groups says the current window is elevated?

    Choose one answer.

    Show the answer: Question 1 of 15

    Answer: Mandatory Label\High Mandatory Level

    Elevation shows up in the token as a High (or System) mandatory integrity level, which whoami /groups prints as the Mandatory Label line. The accounts and UAC lesson covers the integrity levels in depth.

  2. Question 2 of 15 What does ipconfig /? print?

    Choose one answer.

    Show the answer: Question 2 of 15

    Answer: The help text with every switch and short examples

    /? is the Command Prompt tradition for help; its PowerShell neighbour is Get-Help, which reads the help topic beside each cmdlet. Both let a technician look up a switch rather than guess.

  3. Question 3 of 15 ipconfig /flushdns changes which of the following?

    Choose one answer.

    Show the answer: Question 3 of 15

    Answer: Only the DNS client resolver cache

    /flushdns resets the resolver cache on the PC, so the next lookup goes back to the configured DNS servers. The servers, the hosts file, the DHCP lease and open connections are all untouched by the command.

  4. Question 4 of 15 Which ipconfig field names the computer's own IPv4 address when DHCP worked?

    Choose one answer.

    Show the answer: Question 4 of 15

    Answer: IPv4 Address

    Microsoft's ipconfig page documents IPv4 Address for a working lease and Autoconfiguration IPv4 Address for the APIPA case; the parser in the lesson's example reads both into the same ipv4 field.

  5. Question 5 of 15 Which netstat switch adds the process id of each connection to the output?

    Choose one answer.

    Show the answer: Question 5 of 15

    Answer: -o

    Microsoft's netstat page lists -o as "Displays active TCP connections and includes the process ID (PID) for each connection"; this is the switch most help desks reach for first.

  6. Question 6 of 15 ping to intranet.corp.example succeeds, but the web page does not open. Which Test-NetConnection run isolates the next layer?

    Choose one answer.

    Show the answer: Question 6 of 15

    Answer: Test-NetConnection intranet.corp.example -Port 443

    Microsoft's Test-NetConnection reference shows -Port opening a TCP connection and reporting TcpTestSucceeded; the pair "ping works, TCP fails" places the problem at the server or a firewall, not at the network.

  7. Question 7 of 15 Why would a help desk run gpupdate /force rather than gpupdate alone?

    Choose one answer.

    Show the answer: Question 7 of 15

    Answer: To reapply every policy setting instead of only the ones that changed

    Policies refresh in the background on their own, and gpupdate alone applies the ones that changed. /force reapplies every setting, so a value that was already written is overwritten with the current one from the GPO.

  8. Question 8 of 15 gpresult /r prints a section "The following GPOs were not applied because they were filtered out". What usually puts a GPO there?

    Choose one answer.

    Show the answer: Question 8 of 15

    Answer: The user or the computer is not in the security group the GPO is scoped to

    Security filtering (the Delegation tab in Group Policy Management) and WMI filtering are the two common reasons a GPO is read but not applied; gpresult names each one in its filtered-out list and that answers "why didn't it reach me" without opening the console.

  9. Question 9 of 15 Why does chkdsk C: /f schedule itself for the next restart on a running PC?

    Choose one answer.

    Show the answer: Question 9 of 15

    Answer: The system volume cannot be locked while Windows is using it

    Microsoft's chkdsk reference describes the lock requirement for /f and says the command asks to run at the next restart when the volume is in use; that is why repairs on C: happen between the "Preparing to restart" screen and the sign-in.

  10. Question 10 of 15 What is the expected output of a second sfc /scannow after a successful first repair and a reboot?

    Choose one answer.

    Show the answer: Question 10 of 15

    Answer: "Windows Resource Protection did not find any integrity violations"

    The sfc support article lists the four possible result lines; "did not find any integrity violations" is the good one and the second scan after a reboot is what moves a ticket to Closed.

  11. Question 11 of 15 A PC without internet needs DISM /RestoreHealth, with a mounted Windows image at C:\mount\windows. Which command uses it?

    Choose one answer.

    Show the answer: Question 11 of 15

    Answer: DISM /Online /Cleanup-Image /RestoreHealth /Source:C:\mount\windows /LimitAccess

    The DISM repair guide shows the full form with /Source and /LimitAccess; the mounted image provides the clean files, and /LimitAccess keeps the command from trying Windows Update after the source misses a file.

  12. Question 12 of 15 Which Command Prompt command removes a folder and every file and sub-folder in it, with no further prompts?

    Choose one answer.

    Show the answer: Question 12 of 15

    Answer: rd /s /q <folder>

    rd /s /q wipes a folder and everything under it without asking. The safety routine is a dir /s or a Get-ChildItem -Recurse first; the list is exactly what rd will remove.

  13. Question 13 of 15 Which routine shows what del *.log or rd /s <folder> will remove before it runs?

    Choose one answer.

    Show the answer: Question 13 of 15

    Answer: Run dir /s on the same pattern first and read the list

    The destructive-commands table pairs each command with its look-first form: robocopy /mir with /L, del and rd /s with dir /s (or Get-ChildItem -Recurse), and format with diskmgmt.msc or Get-Disk. The list is exactly what the real run will act on.

  14. Question 14 of 15 Microsoft's deprecated-features page says WMIC is removed from which Windows 11 version onward?

    Choose one answer.

    Show the answer: Question 14 of 15

    Answer: Windows 11, version 24H2

    Microsoft's "Deprecated features for Windows client" page says WMIC is removed on Windows 11, version 24H2 and later. Scripts that still rely on wmic have to be rewritten with Get-CimInstance (or Get-WmiObject) before an upgrade.

  15. Question 15 of 15 How would you print the name of every enabled network adapter in PowerShell?

    Choose one answer.

    Show the answer: Question 15 of 15

    Answer: Get-CimInstance Win32_NetworkAdapter -Filter "NetEnabled=true" | Select-Object Name

    Get-CimInstance's reference lists -Filter as a CIM query-dialect expression; the Win32_NetworkAdapter class documents NetEnabled, and the pipe to Select-Object chooses the columns the ticket needs.

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.

  1. 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?

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page. First step and follow-ups

  2. 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?

    Model answer, Pro. First step and follow-ups

Flashcards · 7 cards

Recall it, then check

Say the answer to yourself before you look: recalling it is what makes it stick.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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 and Get-Help for 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 with nslookup or Resolve-DnsName, test the port with Test-NetConnection, and follow the path with tracert or pathping.
  • gpresult /r is the fastest answer to “did my policy change reach this user”, and gpupdate /force reapplies every setting rather than only the changed ones.
  • The repair order is DISM first to refresh the component store, then sfc /scannow, with a second sfc after a restart to confirm the result; chkdsk C: /f runs 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, del previewed with dir, 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-CimInstance reads the same classes, so (Get-CimInstance Win32_BIOS).SerialNumber replaces wmic 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

Related tools

Report a problem with this lesson

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.