Avatar of compdigit44
compdigit44
 asked on

Powershell List all file with Archive and Offline attributes set

I am trying to run a powershell script to list the name and path of all files with the archive and offline attributes set. The problem is a number of our directory paths are very long and causing the script to skip those directories. Any suggestions on the best way to address this?
PowershellWindows Server 2012

Avatar of undefined
Last Comment
compdigit44

8/22/2022 - Mon
Michael B. Smith

You can create a share (or subst) in lower levels of the directory tree which can then be processed.
compdigit44

ASKER
I have to search a very drive that has thousand of sub folders so this would turn into a very manual process. Any other idea even outside of Powershell
Michael B. Smith

Yes, you can do it with robocopy. Robocopy allows you to search for files based on specific attributes and has a mode where it just outputs the file names instead of copying files. It also has no filename limitations.

Take a look at https://learn-powershell.net/2013/04/01/list-all-files-regardless-of-260-character-path-restriction-using-powershell-and-robocopy/ and use the /IA argument for specifying the "Include Attribute" to search for. "robocopy /?" for help.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
compdigit44

ASKER
I have not tried to us Robocopy to list / report on files only with a specific attribute and do not want to mess this up and delete files. What syntax would you suggest.
Michael B. Smith

I ran the command below and it did what I expected. If it's not exactly what you want, it's pretty darn close.

That is:
  • it started at C: root
  • it didn't copy anything
  • it included files with only A and O set
  • it listed the files
  • it didn't search empty subdirectories
  • it didn't give me a report I didn't want
  • it listed file sizes in bytes
  • etc.etc.

I ran this in PowerShell, and it must be an elevated PowerShell to recurse EVERYWHERE, but the results (list of files) are stored in $allfiles.

$allFiles = robocopy c:\ NULL /IA:AO /L /S /NJH /BYTES /FP /NC /NDL /TS /XJ /R:0 /W:0

Open in new window

compdigit44

ASKER
Just to confirm.. the follow switch logs all files only that have the attribute archive & offline set correct..... /IA:AO

Also when I run the script you post it seem to list all files and not just the offline archive ones
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Michael B. Smith

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
compdigit44

ASKER
This is great and we are really close. The exact attributes listed for the files I am looking for is APLO yet when I type this in for the attributes, it does not like it. When I search for AO only, it list some files but not all of them and includes some files that should not be listed.
Michael B. Smith

I'm sorry, I'm out of ideas. :(
compdigit44

ASKER
You have been a huge help!!!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
compdigit44

ASKER
I found that Junction64.exe is able to list junction / reparse files which seems to list all of file with the re-parse attribute set.

Thanks Again...