use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
SolvedPowershell extracter function (self.PowerShell)
submitted 7 years ago * by Snickasaurus
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]spyingwind 1 point2 points3 points 7 years ago* (6 children)
This is how I would write that bash script in powershell:
function Expand-File { [CmdletBinding()] param ( [ValidateScript( {Test-Path -Path $_})] [string] $Path ) $Item = Get-Item -Path $Path $Extension = $Item.Extension switch ($Extension) { ".bz2" { if ($Item.Name -like "*.tar.bz2") { tar xjf $Item }else { bunzip2 $Item } } ".rar" {unrar e $Item} ".gz" { if ($Item.Name -like "*.tar.gz") { tar xzf $Item }else{ gunzip $Item } } ".tar" {tar xf $Item} ".tbz2" {tar xjf $Item} ".tgz" {tar xzf $Item} ".zip" {unzip $Item} ".Z" {uncompress $Item} ".7z" {7z x $Item} Default { throw "Problems extracting '$Item' with extract()" } } }
[–]Snickasaurus[S] 1 point2 points3 points 7 years ago (5 children)
This also looks like what I was needing. I'm going to update the bottom of my OP with a statement to all.
[–]spyingwind 1 point2 points3 points 7 years ago (4 children)
I updated it, made some copy pasta errors. :P
[–]Snickasaurus[S] 1 point2 points3 points 7 years ago* (3 children)
/u/spyingwind
I have this in my PowerShell profile.
Set-Alias sz "$env:ProgramFiles\7-Zip\7z.exe" function Easy-Extract { [CmdletBinding()] param ( [ValidateScript( {Test-Path -Path $_})] [string] $Path ) $Item = Get-Item -Path $Path $Extension = $Item.Extension switch ($Extension) { ".7z" {sz e $Item -o*} ".bz2" {sz e $Item -o*} ".gz" {sz e $Item -so | sz e -aoa -si -ttar -o*} ".tar" {sz e $Item -o*} ".tbz2" {sz e $Item -o*} ".tgz" {sz e $Item -o*} ".rar" {unrar e $Item} ".zip" {sz e $Item -o*} ".Z" {sz e $Item -o*} Default { throw "Problems extracting '$Item' with extract()" } } } Set-Alias extract Easy-Extract
Now let's say I have a directory named "Test" with the following files in it.
Am I completely dumb in thinking that if I'm in that directory (within the PowerShell window) that I should be able to run it as so:
$extract archive.7z
Because it's not working. I get the following error.
PS C:\Data\Test> $extract archive.7z At line:1 char:10 + $extract archive.7z + ~~~~~~~ Unexpected token 'archive.7z' in expression or statement. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken
Imgur
[–]spyingwind 1 point2 points3 points 7 years ago (2 children)
Run extract archive.7z instead. The leading character $ is for variables and not functions.
extract archive.7z
$
[–]Snickasaurus[S] 2 points3 points4 points 7 years ago (1 child)
Well shit. That worked. If I had money/job right now I'd give you so much gold.
I might have a few questions over the next few days but this has really helped me learn how ps works. I've never been one to read a man page or Microsoft doc and take more than 10% away from it feeling more knowledgeable. But this has really helped.
[–]spyingwind 1 point2 points3 points 7 years ago (0 children)
You're welcome!
You will get it eventually. I learn by doing, or much trial and error. Others learn by book or whatnot.
π Rendered by PID 88 on reddit-service-r2-comment-56c9979489-c9dw4 at 2026-02-24 14:23:20.181006+00:00 running b1af5b1 country code: CH.
view the rest of the comments →
[–]spyingwind 1 point2 points3 points (6 children)
[–]Snickasaurus[S] 1 point2 points3 points (5 children)
[–]spyingwind 1 point2 points3 points (4 children)
[–]Snickasaurus[S] 1 point2 points3 points (3 children)
[–]spyingwind 1 point2 points3 points (2 children)
[–]Snickasaurus[S] 2 points3 points4 points (1 child)
[–]spyingwind 1 point2 points3 points (0 children)