Clear-Content
Use Clear-Content to empty a file without deleting it, leaving a zero-length file behind.
Documentation: Microsoft Learn — Clear-Content
Syntax
See the command anatomy
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
Clear-Content [-Path] <String[]> [-Force] [-Filter <String>] [-WhatIf] [<CommonParameters>]- Stage 1Clear-Content
-Path -Force -Filter -WhatIf
Try it
PowerShell example · browser support is limited.
Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.
Follow the objects
Run the command to inspect each stage.
Examples
Clear-Content -Path 'C:\Temp\run.log'
Show reference output
Sample output · fictional data, shaped like the real thing
Directory: C:\Temp Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 10/9/2026 2:14 PM 0 run.log
Clear-Content -Path 'C:\Temp\*.log'
Show reference output
Sample output · fictional data, shaped like the real thing
Directory: C:\Temp Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 10/9/2026 2:14 PM 0 app.log -a---- 10/9/2026 2:14 PM 0 run.log -a---- 10/9/2026 2:15 PM 0 debug.log
Select Name, Length
Show reference output
Sample output · fictional data, shaped like the real thing
Name Length ------- ------ app.log 0
Parameters
Parameter definitions:
-Path-Force-Filter-WhatIf
Practical use and troubleshooting
Practical scenario: Use Clear-Content when you need to empty a file without deleting it, leaving a zero-length file behind. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.
Common error and fix: Access denied while emptying a file requires checking the file ACL and whether another process has an exclusive handle. Do not assume -Force grants missing permissions. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.
See also: Remove-Item. Clear-Content leaves the item in place but removes its content; Remove-Item deletes the item. Emptying a log and deleting a directory are different operations. Read the linked command before substituting it; similar names do not imply identical inputs or output.
Recap
Clear-Content Use Clear-Content to empty a file without deleting it, leaving a zero-length file behind.
Next: Add-Content