Limit number of folders script runs on in Powershell

Welcome Forums General PowerShell Q&A Limit number of folders script runs on in Powershell

Viewing 18 reply threads
  • Author
    Posts
    • #238379
      Participant
      Topics: 3
      Replies: 15
      Points: 50
      Rank: Member

      This script works great on a few test folders, but throws memory exception error if I run it on the full data set.  I set the memory to the max, still errors.

      How do I bypass the memory and send it straight to output, OR Limit the number of folders it runs on so I can run it in batches.  For example, start at level 2 like it does, but only run through 5 folders at level 2.  I can’t move the data around, it’s an Archive server.

    • #238388
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      You actually already asked this question. 😉 https://powershell.org/forums/topic/error-on-path-with-spaces-commas-parenthesis-and-slash/ And you did not even answer there.

      You may explain what the actual purpose of that code is. What is it what you try to achieve? And it’s still not a good idea to run a fomrat cmdlet and then pipe this to Out-File.

      If you get an error you should post this error completely (formatted as code as well, please)

    • #238934
      Participant
      Topics: 3
      Replies: 15
      Points: 50
      Rank: Member

      First, I apologize for being difficult.  I did take your advice and set the code to pre-formatted in my last post, so I’m learning……slowly.

      I have an Archive server with tons of data, I’m trying to run a script to start 2 folders down and scan through the sub-folders and bring back the path and the latest modified date.  If the project folders are old enough, legally we can delete it, which is why I need to know.

      Folder structure example:

      Program 1

      Projects 1-1000

      Project 1

      Project 2

      I need to start it at the Program level and have it run through Project 1, 2, etc.

      I did try your suggestion to run to csv in a test environment.  When I use the code below, and run it to csv I get two lines of data in the file.  If I run the same code to text I get hundreds of lines (in the test environment – same folder as the csv run).  I don’t know why.  I’d love to output to CSV.

      However, when I run to text file in the live Archive server I get the following error.

      Maybe I just need help running it to csv and figuring out why I only get two lines of data to csv and hundreds when I run to text.

       

    • #238967
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      I’m trying to run a script to start 2 folders down and scan through the sub-folders and bring back the path and the latest modified date.

      … latest modified date of what? If I got it right you can do a simple

      to get the folders of the level you’re after.

      But I’m still unsure what you’re actually trying to achieve.

    • #238973
      Participant
      Topics: 3
      Replies: 15
      Points: 50
      Rank: Member

      Ideally, what I’d have is a list of the the Project folder and the latest modified date of any object in that folder or any sub-folder of that project.

      For example:

      Under Projects 1-1000

      The final list would look like this:

      Project 1    July 21, 2000

      Project 2    May 22, 2017

      Project 3    Dec. 3, 2005

      etc.

      The date being the latest modified date of anything in the folder (Project 1) or any of the many sub-folders within Project 1 and so on for Project 2.

      So that our archiving team can delete all projects that are older than a date/year that our attorney chooses.  The attorney may say Projects 1 and 3 can be deleted based on their age.

      There are thousands of projects which is why they are grouped 1-1000, 1001-2000, etc.

       

       

    • #239105
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      … something like this?

    • #239225
      Participant
      Topics: 3
      Replies: 15
      Points: 50
      Rank: Member

      Thank you so much!!!!   That works great!!!!  Due to the volume of data, how do I push it csv?

       

    • #239228
      Participant
      Topics: 25
      Replies: 184
      Points: 657
      Helping Hand
      Rank: Major Contributor
    • #239231
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP
    • #239264
      Participant
      Topics: 3
      Replies: 15
      Points: 50
      Rank: Member

      Absolutely Perfect!  Thank you so much!

    • #239306
      Participant
      Topics: 3
      Replies: 15
      Points: 50
      Rank: Member

      I also have some Programs that need to start one layer down.

      Example of the folder structure:

      Program 1

      Projects 1-1000

      Project 1

      Project 1.1

      Project 1.2

       

      How can I run it at the Project 1-1000 level and have it list:

      Project 1.1  LastWriteTime

      Project 1.2 LastWriteTime

       

       

    • #239330
      Participant
      Topics: 0
      Replies: 11
      Points: 118
      Helping Hand
      Rank: Participant

      You will also want to include the -Depth parameter when you are running Get-ChildItem to implement the requirement in his original post.

    • #239369
      Participant
      Topics: 3
      Replies: 15
      Points: 50
      Rank: Member

      How do I add that in?

    • #239678
      Participant
      Topics: 3
      Replies: 15
      Points: 50
      Rank: Member

      I had the previous script which went through the folder depths, but how do I use the script below and start 2 levels down?

    • #240434
      Participant
      Topics: 3
      Replies: 15
      Points: 50
      Rank: Member

      I’m so close to getting this done and you have all been very helpful!

      Example of the folder structure:

      Program 1

      Projects 1-1000

      Project 1

      Project 1.1

      Project 1.2

      How do I add the -depth and run the code below at the Project 1-1000 level and have it list:

      Project 1.1  LastWriteTime

      Project 1.2 LastWriteTime

    • #240482
      Participant
      Topics: 3
      Replies: 15
      Points: 50
      Rank: Member

      I’ve been working on it all day and I just can’t get it.

      I need the output of this:

      $Result = Get-ChildItem -Path ‘.\Program 1\Projects 1-1000\*’ -Directory | ForEach-Object { $NewestItem = Get-ChildItem -Path $_.FullName -File -Recurse | Sort-Object -Property LastWriteTime | Select-Object -Last 1 [PSCustomObject]@{ Folder = $_.FullName NewestItem = $NewestItem.FullName NewestItemDate = $NewestItem.LastWriteTime } } $Result | Export-Csv -Path .\output.csv -NoTypeInformation

       

      but starting 2 folders deep like this script:

      $StartLevel = 2 # 0 = include base folder, 1 = sub-folders only, 2 = start at 2nd level $Depth = 20 # How many levels deep to scan $Path = “.” # starting path $ExportFolder = “C:\Users\mmsho\Documents” $folders = For ($i=$StartLevel; $i -le $Depth; $i++) { $Levels = “\*” * $i (Resolve-Path “$Path$Levels”).ProviderPath | Get-Item | Where PsIsContainer | Select FullName } $Folders.fullname | %{ Get-ChildItem -path $_ -Recurse | export-csv “$ExportFolder\testoutput.csv” }

    • #240485
      Participant
      Topics: 3
      Replies: 15
      Points: 50
      Rank: Member

      I formatted the script as pre-formatted, but it doesn’t look like it took.

    • #240539
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to you help making their work twice or more.

      https://social.technet.microsoft.com/Forums/en-US/225a2274-a42e-4759-b001-37f7d885baf8/search-last-date-modified-starting-2-folders-down?forum=winserverpowershell

      Thanks

    • #240593
      Participant
      Topics: 3
      Replies: 15
      Points: 50
      Rank: Member

      I can delete this post if that would be best, I have decided to pay someone to code it.

Viewing 18 reply threads
  • You must be logged in to reply to this topic.