If you browse through a large folder structure, you may stumble across some folders that you don’t have access. It would be a lot helpful if you can do a quick scan and find all these Access Denied folders without manually go through every single of them.
Well, here is one way of doing it using the powerful PowerShell. See script as below:
$result = Get-ChildItem -Path $path2scan -Recurse -ErrorAction SilentlyContinue -ErrorVariable $myError Echo $myError.TargetObject
The following screenshot shows how it scans and finds out all folders in C:\Windows that I don’t have access to.
What the script does is to recursively scan the specified folder, hide and log all Access Denied errors into a variable stated with -ErrorVariable switch. And then display the error variable’s TargetObject parameter which lists all folder paths that I don’t have the right to access.
It’s a pretty nice trick that uses PowerShell to accomplish something that is very hard in Windows. Thanks to PowerShell.
nice one – only the error variable name should start with a $ (at the end of the first line.
It doesn’t need (or even work) if you specify a $ where you specified. Unintuitive, but true
Thank you. Indeed.
Pls update your post to include the need to not include the $ on the variable name.
Hi, doesn’t work for me.
I am not fond on p.shell, only old plane .bat scripts, sorry.
I put the two lines (one at a time or together) in the PowerShell ISE (run as administrator) and it doesn’t work: when it runs the second line, no output given anyway anywhere (that I can see).
The first line seems to run plain (disk usage ramps), only I can’t recover the output by next command.
What I have done wrong?
I dunno what the folks in other comments are saying about $ or not in variable names, apart I know they should probably have it.
Also, the added ability to run this command via a link, and get the output in something like a text console or window that can be saved, will probably be useful.
Thanks for any help.
(Privacy: pls don’t add me to mlists or spam)