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

  • SEARCH
  • Home
  • 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 8277633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:44:35+00:00 2026-06-08T08:44:35+00:00

My first excursion into a real app in Powershell; I could write the code

  • 0

My first excursion into a real app in Powershell; I could write the code in a traditional .Net language, but I think Powershell is ideal for console apps like this. I’ve searched StackOverflow and found the (nearly) exact script I need; my issue is that I want to take a folder of files (on server fsA) and create 7-Zip archives on fsB named by the file date. For instance, all the files that were last written on 7/21/12 would be found in archive 20120721.7z. I’m basing this on the solution found here: Create a 7z Archive for files created by date using Powershell

Here is what I have so far:

$prog_dir = "C:\Progra~1\7-Zip\7z.exe"
$archive_dir = "\\fsa\Backup"
$input_dir = "\\fsb\Xml\Archive\"
$7zOpts = "-m0=PPMd:o32:mem192M"
$groups = dir $input_dir | group-object -property {$_.LastWriteTime.Date}
$groups | foreach{$cmd = $prog_dir + " a " + $archive_dir + "\$((Get-Date $_.Name).ToString(`"yyyyMMdd`")).7z $([string]::join(`" `", $_.Group)) " + $7zOpts} #; invoke-expression $cmd}
#
#Where to put this: "+ $input_dir +"???
#
$cmd

I can’t seem to find a way to specify the input directory in the foreach line; I can put it at the beginning of the join statement, but it only adds the input directory to the first file in the list. For instance:

$groups | foreach{$cmd = $prog_dir + " a " + $archive_dir + "\$((Get-Date $_.Name).ToString(`"yyyyMMdd`")).7z " + $input_dir + "$([string]::join(`" `", $_.Group)) " + $7zOpts} #; invoke-expression $cmd}

produces the output

C:\Progra~1\7-Zip\7z.exe a \\fsa\Backup\20120722.7z \\fsb\Xml\Archive\255IQR.xml 2573WV.xml 257RMC.xml

where the last two files do not have the full path prepended? What am I doing wrong?

  • 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-08T08:44:36+00:00Added an answer on June 8, 2026 at 8:44 am

    PowerShell is a shell, so running commands is pretty much the thing it should do well. So generally, if you resort to Invoke-Expression when running commands you’re doing something very wrong. Let’s try a different way:

    $prog_dir = 'C:\Progra~1\7-Zip\7z.exe' # you don't need 8.3 names here, by the way
    $archive_dir = '\\fsa\Backup'
    $input_dir = '\\fsb\Xml\Archive\'
    $7zOpts = '-m0=PPMd:o32:mem192M'
    $groups = dir $input_dir | group-object -property {$_.LastWriteTime.Date}
    $groups | foreach {
        $files = $_.Group | select -expand FullName
        $date = (Get-Date $_.Name).ToString('yyyyMMdd')
        & $prog_dir a $archive_dir\$date.7z $files $7zOpts
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first take a look on this picture from localScope app : i have 2
first off I'm a noob to PHP but here is my problem. I am
First you should know I have looked into many questions and none of them
first sorry if its a stupid question but im lost a bit. So when
first I used onDestroy() method as below to make something when my app is
First, my question might sound like a duplicate, but I have been going through
First is the code #include <stdio.h> typedef wchar_t* BSTR; wchar_t hello[] = LHello; class
First, the general situation... a 3rd-party library loaded through a DLL does rendering into
First method $start = microtime(true); // code $end = microtime(true); echo 'This page loaded
First of all, my app builds and runs perfectly well, with no exceptions. When

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.