/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Simple Show-Image function for Monad "," MSH out-zip Function "," get a Users LastLogontime and Domaincontroller fro... "," Some fun With Monads Add-Member, MP3 files and COM "," MSH snap-in to Translate IADsLargeInteger to Int64 "," Commandline editing with MSH. "," MSH Scroll-host function "," Series about Monad on Computerworld "," Watching FSRM Quota and filescreen events from Monad "," More ACL and MSH on MSH for Fun "," ")

Monday, January 30, 2006

 


Dir, Dir and more Dir in MSH



Dir Replacement for MSH, with Attribute support, like dir in CMD does.

so now you can do things like this :

dir -ar
dir -ard
dir -ah -force
etc.

and if you take a good look.

and even one more as the CMD one does ;-)

you should remove the alias DIR first, like this :

del alias:dir

(you still will have LS or GCI, I would not replace GCI but you could also pick LS to replace)

for more info en tips about getting a directorylist from Monad see this thread :
get-childitem and file attributes...

that made me write this script, maybe I will add some more parameters later,
or autoadd -Force if H or S is found, and combine it with the colored Dir replacement elswhere on my blog)

gr /\/\o\/\/
Tags :


# Dir Function replacement with attributefilter
# /\/\o\/\/ 2006
# http://mow001.blogspot.com

function dir {
  if($args.length -ne 0) { 
    $Script:NewArgs = @()
    $Script:filters = @()
    foreach ($arg in $args) {
      Switch ($arg) {
       {$_ -match '-a'} {
          if ($_ -match 'r'){$Script:filters += ' | where { $_.attributes -match "ReadOnly"}'}
          if ($_ -match 'd'){$Script:filters += ' | where { $_.attributes -match "Directory"}'}
          if ($_ -match 'h'){$Script:filters += ' | where { $_.attributes -match "Hidden"}'}
          if ($_ -match 's'){$Script:filters += ' | where { $_.attributes -match "System"}'}
          if ($_.remove(0,2) -match 'a'){$Script:filters += ' | where { $_.attributes -match "Archive"}'}
          if ($_ -match 'n'){$Script:filters += ' | where { $_.attributes -match "NotContentIndexed"}'}
       } 
       {$_ -eq '-d'} {$Script:filters += ' | where { $_.mshiscontainer}'}
       default {$Script:NewArgs += $_}
      }
    }
    invoke-command("gci $Script:NewArgs $Script:filters")
  } else {
    gci
  }
}



Comments: Post a Comment



<< Home

Archives

October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Google
 
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?