Newbie help with very simple function

Hi,

I am relativly new into scripting and powershell. I would be very nice to get help for this:

I would like to create a function (kind of an “alias”), for compressing a folder into a 7z archive. Under linux this simple alias works just fine:

alias zz=“7z a -t7f -mx=9”

With that I can create my archive like so:

zz myarchive.7z /pathtofolderiwanttoarvhive

I tried to put this line in my Microsoft.PowerShell_profile.ps1:
(7z.exe is in the Systems path)

function zz { 7z a -t7z -mx=9 }

The function/alias per se works, when I try:

zz myarchive.7z MYFOLDERTOARCHIVE

But then 7z gives me the error message:

Command line error. Cannot find archive name.

I have no idea how to solve this.

It would be very kind if you could help me with this.

Kind regards

Pragomer,
Welcome to the forum. :wave:t4:

You can create aliasses in PowerShell as well. But that does not allow to add parameters. It’s just a way to shorten a long name of a cmdlet.

Really? Wow. Then you could simply ignore the error!? :man_shrugging:t4: :wink:

I’d recommend to put a little more complexity to your function by adding parameters for the command line arguments you want to process.

The available help is actually quite complete and comprehensive.

A little wile ago MSFT released a new module called " Crescendo". It makes it easier to wrap external tools into a PowerShell cmdlet.

BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink:

1 Like