I had a rough night and jumped straight into PowerShell in the morning without fully waking up. Unfortunately, I cleared my screen with the 'cls' command right after I was removing mailbox import requests from Exchange. Now I've lost track of which requests were still in progress or had failed because I accidentally deleted that information. Is there any way to undo the cls command or recover the output I lost?
11 Answers
You can’t undo cls, but you can make your own version of the Clear-Host function to prevent it from being too destructive in the future. Just a little coding tweak can go a long way.
You might just be able to scroll your terminal back up to see what you did—if only your environment supports it!
Did those requests automatically go to a 'deleted' status?
No, they wouldn't!
You know, if only there was a way to take snapshots of everything you're doing, we might not run into this issue. Too bad it's just a dream!
Right? If such a system existed, we'd definitely trade the usual for something smarter!
Isn't there an exchange audit log? That's what I was thinking. If you have that enabled, it might help you track what happened, even though I don't work with Exchange myself.
Yeah, Exchange Audit Logs are usually enabled by default. You can also check Unified Audit Logs for a detailed history.
I always enable PowerShell script logging on my servers, and trust me, it pays off!
For next time, consider starting a transaction which can be really useful! Also, PowerShell script logging can help keep track of what you’re doing.
You can use `Get-History` or even `Ctrl+R` after using cls. While it won’t bring back what was on your screen, it might help you know what commands you ran.
I was hoping for the output of a specific command, but I just need a better strategy next time.
You should really be storing outputs in variables, especially for critical operations. It's a good practice to log everything in detail when running commands that might be destructive. Seriously, I've made the same mistake multiple times when half-asleep!
Absolutely! Just last week, I was running scripts late at night and regretted it in the morning. The Boy Scout motto really applies here—always be prepared!
Instead of recovering from CLS, try checking the status of an import directly with `Get-MailboxImportRequest | Get-MailboxImportRequestStatistics` for some guidance.
Definitely! Check out this helpful link for more pointers on managing PST files.
If you were using VS Code, the PowerShell extension can clear the screen without losing your command history—kinda annoying though! But for your current issue, using transcript logging would be really helpful.
I get that! Unfortunately, I was on an Exchange server far away from my usual setup. I reran the import and found it doesn’t duplicate, so maybe I’m in the clear.

Yeah, that works on Linux, but sadly not this time.