MS releases PowerShell RC1

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Microsoft released PowerShell RC1 today, as reported on Slashdot. PowerShell was formerly known as MSH, and is the .Net 2.0 replacement for cmd.exe.

Get it here.

Update:

Some cool things I have found so far playing with it.

Objects. The cmdlets are objects, and you have full access to the .Net classes as well. Pipes work as you expect, whether using cmdlet output or piping property values from one cmdlet to another.

ipconfig | findstr "Address"

will run the ipconfig cmdlet and then search the output for the address parameter, for example.

Unified "volume" model for accessing drives and the registry. Typing "cd hklm:" puts you at the root of the HKEY_LOCAL_MACHINE registry hive. Typing "dir" or "gci" or "get-childitem" at that prompt lists the available keys, etc.

More as I dig into it.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
What they need to do is release a new console app that allows you to resize it normally like all other windows.
 

Bluestealth

Senior member
Jul 5, 2004
434
0
0
Oooo *.msi package... I like it when they use those.... /i /quiet

<--- obsesive compulsive automated installer

Hmmm.... just thought about this for a second....

SU.bat:
runas /user:administrator cmd

hmm.... that'll make my life hundred of times easier running as a user :)

grrr.... cant just use /q.... FINE!
msiexec /i PowerShell_Setup-i386.msi TRANSFORMS=PowerShell_Setup-i386.mst /q
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Oooo *.msi package... I like it when they use those.... /i /quiet

Except for the fact that if you don't have .Net 2.0 installed it just says "You need .Net 2.0, go download it and try again" I feel like I'm back in the RH7 days of package management :/
 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
A simple dir command shows a ton of stuff. Can I just get it to show the directories?
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
dir -name

Directories only...

dir *. -name

Edit: nope, doesn't work. trying to figure out how to filter for the d attribute.
 

imported_lacan

Junior Member
Apr 29, 2006
2
0
0
Good to see others using this.
This shell is something that once it clicks (I'd say a few hours of determined use), the implications for automating simple (or even not so simple) tasks are astounding.

I have used cygwin for a long time to get access to bash, since it was/is SOO much better than cmd.exe. I will probably use both now, but I suspect I'll shift more and more towards PowerShell as I become more familiar with how to get information. Still love cygwin too though.

A simple dir command shows a ton of stuff. Can I just get it to show the directories?

One way to do this:

To get the attribute list in its object display form:

dir|format-table name,attributes

Now you can see that one of the attributes types is "Directory", so we can match on this as one way to grab the directories:

dir|WHERE {$_.Attributes -match "Directory"}

$_ is used to denote the current object as we iterate through a list.
So in this case it is the object for each file or directory as we iterate through the output of the "dir" command.
------------------------

You can make it wider too, it's just a PITA.
You're statement implies that you already know how to do this, but for those that don't know:

To allow it to give you a much larger and sizable window for the console you have to edit the "Layout" tab in the properties for the shortcut to powershell. (Maybe add the quickedit option too while you're in the properties)

I use 1152x864 resolution, and my console layout properties are set to:
Width: 140
Height: 65
For both the Screen Buffer Size AND Window Size.
----------------------

Finally, a much better option will exist soon (through a third party):
http://www.karlprosser.com/coder/

He will provider an analyzer (similar to using query analyzer for MSSQL) to give a much improved interface to using PowerShell.
Check out the flash demos, this is going to be very cool.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Cool tips, thanks. The directory listing command works, but is a little cumbersome. When I tried to make an alias for it using new-alias, with a name of 'ddir' and a value of 'dir | where {$_.Attributes -match "Directory"}' (without quotes) the alias was accepted. But when I ran it I got the following error:

Alias not resolved because alias 'ddir' referenced command 'dir | where {$_.Att
ributes -match "Directory"}', this command is not recognized as a cmdlet, funct
ion, operable program, or script file.

Despite the fact that the command works as it should from the command line. So I'm still missing something about aliases, I think.
 

imported_lacan

Junior Member
Apr 29, 2006
2
0
0
I think you are looking for a function instead of an alias:

> function DirWithAttrib([string]$attrib) {dir|WHERE {$_.Attributes -match $attrib}}
> function ddir() {DirWithAttrib Directory}

> ddir
(Returns just dirs)

> DirWithAttrib System
(Returns System entries)

I think (I could be wrong) an alias gives you a short name for a cmdlet only
Whereas a function gives you a short name for one or more statements (which usually use a cmdlet or cmdlets)

As a side note, you can see the definitions for your aliases and functions like this:

>dir alias:
>dir function:

I think there are probably other, better ways to do the dir only listing, but this is the first one that came to mind for me.