Back to Resources
Level
Script
Security
When a Windows device is lost, stolen, decommissioned, or repurposed, IT professionals need a reliable way to erase sensitive data. This script automates secure device erasure, reducing the risk of unauthorized access to corporate or personal information. It ensures that credentials, system logs, and other sensitive data are removed quickly and efficiently.
This script securely wipes critical user and system data, including:
This script is highly destructive and should only be used in scenarios where complete data removal is required.
<#
This resource is provided as a convenience for Level users. We cannot
guarantee it will work in all environments. Please test before deploying
to your production environment. We welcome contributions to our community
library
Level Library
https://level.io/library/script-windows-device-erase-script
#>
# WARNING: Dangerous operation - Recursively delete files and directories for all users
Get-ChildItem -Path "C:\Users" -Recurse | Remove-Item -Force -Recurse
Get-CimInstance -ClassName Win32_UserProfile | Where-Object { -not $_.Special } | Remove-CimInstance
# Clear Browser Data (Example for Chrome, modify for other browsers as needed)
Remove-Item "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\*" -Recurse -Force
# Clear Outlook Data (Modify the path if different)
Remove-Item "$env:APPDATA\Microsoft\Outlook\*" -Recurse -Force
# Remove VPN Credentials (Example for a specific VPN client, modify as needed)
Remove-Item "Path\To\VPN\Credentials\Store" -Force
# Remove Saved Wi-Fi Networks
netsh wlan delete profile name="*"
# Remove Windows Credentials
cmdkey /list | ForEach-Object {if ($_ -like "*Target:*") {cmdkey /delete:($_ -replace " ","" -replace "Target:","")}}
# Remove SSH Keys (if applicable)
Remove-Item "$env:USERPROFILE\.ssh\*" -Force -Recurse
# Clear all System Restore Points.
Disable-ComputerRestore -Drive "C:\"
vssadmin Delete Shadows /All /Quiet
# Clear all event logs.
Get-EventLog -LogName * | ForEach { Clear-EventLog -LogName $_.Log }
# WARNING: Highly destructive operation. Proceed with caution.
# The script will attempt to wipe all fixed drives.
Get-WmiObject -Class Win32_LogicalDisk | Where-Object { $_.DriveType -eq 3 } | ForEach-Object {
$drive = $_.DeviceID
Write-Host "Wiping $drive..."
Remove-Item "$drive\*" -Recurse -Force
}
Windows - Erase Device
This Windows PowerShell script performs a comprehensive remote device wipe, removing user profiles, applications, credentials, system restore points, event logs, and drive contents to secure data when a device is compromised.
PowerShell
1200
Local system
Explore more automations, scripts, and policies to further enhance your IT operations.