Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8862437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:43:45+00:00 2026-06-14T15:43:45+00:00

I am writing a script which will basically do the following: Read from a

  • 0

I am writing a script which will basically do the following:

Read from a text file some arguments:

DriveLetter ThreeLetterCode ServerName VolumeLetter Integer

Eg. W MSS SERVER01 C 1

These values happen to form a folder destination W:\MSS\, and a filename which works in the following naming convention:

SERVERNAME_VOLUMELETTER_VOL-b00X-iYYY.spi - Where The X is the Integer above

The value Y I need to work out later, as this happens to be the value of the incremental image (backups) and I need to work out the latest incremental.

So at the moment –> Count lines in file, and loop for this many lines.

$lines = Get-Content -Path PostBackupCheck-Textfile.txt  | Measure-Object -Line
for ($i=0; $i -le $lines.Lines; $i++)

Within this loop I need to do a Get-Content to read off the line I am currently looking at i.e. line 0, line 1, line 2, as there will be multiple lines in the format I wrote at the beginning and split the line into an array, whereby each part of the file, as seen above naming convention, is in a[0], a[1], a[2]. etc

The reason for this is because, I need to then sort the folder that contains these, find the latest file, by date, and take the _iXXX.spi part and place this into the array value a[X] so I then have a complete filename to mount. This value will replace iYYY.spi

It’s a little complex because I also have to make sure when I do a Get-ChildItem with -Include before I sort it all by date, I am only including the filename that matches the arguments fed to it from the text file :

So,

SERVER01_C_VOL-b001-iYYY.spi and not anything else. 
i.e. not  SERVER01_D_VOL-b001-iYYY.spi

Then take the iYYY value from the sort on the Get-ChildItem -Include and place that into the appropriate array item.

I’ve literally no idea where to start, so any ideas are appreciated!

Hopefully I’ve explained in enough detail. I have also placed the code on Pastebin: http://pastebin.com/vtFifTW6

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:43:46+00:00Added an answer on June 14, 2026 at 3:43 pm

    This doesn’t need to be that complex. You can start by operating over lines in your file with a simple pipeline:

    Get-Content PostBackupCheck-Textfile.txt |
      Foreach-Object {
        $drive, $folder, $server, $volume, [int]$i = -split $_
        ...
      }
    

    The line inside the loop splits the current input line at spaces and assigns appropriate variables. This saves you the trouble of handling an array there. Everything that follows needs to be in said loop as well.

    You can then construct the file name pattern:

    $filename = "$server_$drive_VOL-b$($i.ToString('000'))-i*.spi"
    

    which you can use to find all fitting files and sort them by date:

    $lastFile = Get-ChildItem $filename | sort LastWriteTime | select -last 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a shell script which will rsync files from remote machines, some linux,
I'm writing a bash script in which I read single characters from the input.
I'm writing a shell script which performs some operation on files. This script will
I am writing a shell script which will read a user input and do
I am writing a small script which will set focus to the filter text
I am currently writing a script which parses the ServiceTage, Computername and Username from
I'm writing a script which is to be executed hourly. It basically works as:
I am writing python script which gets links from website. But when I tried
I'm writing a script and at some point I call to command1 which does
I am writing a Tcl script which will be used on an embedded device.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.