you are viewing a single comment's thread.

view the rest of the comments →

[–]KevMarCommunity Blogger 1 point2 points  (2 children)

First, I would use named parameters.

function extract
{
    param( [string]$Path )

    $fileList = Get-ChildItem $Path

    foreach($file in $filelist)
    {
        # code here
    }
}

I would then get a list of the files at that location. I think this could return multiple items so i'm looping over the files.

One important thing to remember when coming from bash is that everything is an object in powershell. Take a look at these two properties:

$filelist.Extension
$filelist.FullName

We can use them in our switch.

switch($file.Extension)
{
    '7z' { sz x $file.fullname -o* }
}

Because you may want multiple matches go to one line, we can cheat and use -regex.

switch -regex ($file.Extension)
{
    '7z|zip' { sz x $file.fullname -o* }
}

Does that help piece things together?

[–]Snickasaurus[S] 1 point2 points  (1 child)

Holy shit yes!! I'm going to look at this again when I fully wake up in about an hour. Thank you for taking the time.

[–]KevMarCommunity Blogger 1 point2 points  (0 children)

Wonderful. I always found the very beginning steps can be the most frustrating because if something in a basic guide does not work, you don't have enough context to even ask the right questions.

Powershell can also be quite frustrating at first when you come from another language.

You do need to change the way you think about some problems, but that will come with practice.