Combine Get-ChildItem and Test-Path

Welcome Forums General PowerShell Q&A Combine Get-ChildItem and Test-Path

  • This topic has 2 replies, 2 voices, and was last updated 2 weeks ago by
    Participant
    .
Viewing 2 reply threads
  • Author
    Posts
    • #271639
      Participant
      Topics: 1
      Replies: 1
      Points: 18
      Rank: Member

      Hi!

      I currently try to move some old cmd/batch scripts to PS, finally! Currently I have a script that finds all .bak-files and creates a 7ziped file along with it if it does not exist.

      My current script looks like this:

      So I’m trying to rewrite in PS.

      This will give me the list of all .back-files, but how do I add .7z to the filename and test it it does exist (Test-Path):

      And in the next step I’ll run the command to create the 7z-file:

      Should I store all found files in an array and iterate the array, or should I use the ‘|’ to chain the commands?

      Thanks for advice!

      • This topic was modified 2 weeks, 2 days ago by Zamb.
    • #271705
      Participant
      Topics: 5
      Replies: 341
      Points: 585
      Helping Hand
      Rank: Major Contributor
    • #272116
      Participant
      Topics: 1
      Replies: 1
      Points: 18
      Rank: Member

      Thanks for the guidance and ideas!

      My final PS looks like this:

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