PowerShell and DOS commands?

Author Message
Dark Water Streams

  • Total Posts : 5
  • Scores: 0
  • Reward points : 0
  • Joined: 8/13/2011
  • Status: offline
PowerShell and DOS commands? Sunday, August 14, 2011 6:10 AM (permalink)
0
Dear old Dad who is a coding enthusiast and does I.T. security was telling me all about Power Shell. Now, does Power Shell let you run all the prompt commands as if it were still DOS 6.22? Do power shell files still run under .VBS or should they be given a new extension? [/style]

Say I wanted to create a .m3u list of all my MP3 files. [/style]
Under cmd.exe I would just do a dir /b C:\MP3_Directory\*.mp3 > "C:\Users ... Desktop\mp3list.m3u" [/style]

Can I call any executable I want on the PC with any parameters? How would that work? [/style]

To you guys that's probably child's play. Are all DOS commands essentially still supported under power shell. Man just reading through some of the stuff makes me feel like the Forrest Gump of coders. Please don't hurt me because I'm a newb.[/style]

[/style][/style][/style]
<message edited by Dark Water Streams on Sunday, August 14, 2011 6:18 AM>
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    Re:PowerShell and DOS commands? Monday, August 15, 2011 3:25 AM (permalink)
    0
    So the answer is a resounding sometimes. First let's start with the fact that the powershell prompt is most definitely *not* the dos cmd prompt. However the developers of powershell wanted to make it as inviting as possible to both people accustom to DOS prompts and for that matter to people accustom to *nix shells. To this end powershell has very robust aliasing. So in powershell, the command to do the equivalent of dir is Get-ChildItem. To fully do what your DOS command does would be:
     
    Get-ChildItem C:\MP3_Directory\* -Include *.mp3 -Recurse > "C:\Users ... Desktop\mp3list.m3u"
     
    In an effort to make it feel more familiar to DOS users, the developers include a default alias Dir->Get-ChildIte. So you could do:
     
    Dir C:\MP3_Directory\* -Include *.mp3 -Recurse > "C:\Users ... Desktop\mp3list.m3u"
     
    But you are still running Get-ChildItem and not the DOS dir command.
     
    Yes you can call any executeable with any parameters. So this would work fine:
     
    Notepad.exe C:\Temp\file.txt
     
    As for whether DOS commands work in Powershell, if they are actual executeables that are in the path and there is not an existing powershell alias with the same name then yes they work. For instance edlin works fine.
     
    Powershell scripts end with a PS1 extension not VBS. For that matter DOS scripts are batch files (BAT extension) not Visual Basic Scripts (VBS extension). VBS files run in the Windows Script Host (WSH) not DOS.
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      59cobalt

      • Total Posts : 979
      • Scores: 91
      • Reward points : 0
      • Joined: 7/17/2011
      • Status: offline
      Re:PowerShell and DOS commands? Monday, August 15, 2011 4:24 AM (permalink)
      0
      ebgreen
      Powershell scripts end with a PS1 extension not VBS. For that matter DOS scripts are batch files (BAT extension) not Visual Basic Scripts (VBS extension). VBS files run in the Windows Script Host (WSH) not DOS.

      While we're at it: batch files are by no means "DOS scripts". On NT-based Windows versions (NT, 2000, XP, Vista, 7, and all server versions), batch scripts run in a 32-bit command interpreter (CMD.exe) that has nothing whatsoever to do with DOS or its 16-bit command interpreter (COMMAND.COM). The NT-based versions even use a different default extension (.cmd), because CMD.exe has far more features than COMMAND.COM (loops, conditionals, string operations, ...). For compatibility reasons .bat is also supported as an extension for batch scripts, though.
       
      #3
        ebgreen

        • Total Posts : 8227
        • Scores: 98
        • Reward points : 0
        • Joined: 7/12/2005
        • Status: offline
        Re:PowerShell and DOS commands? Monday, August 15, 2011 4:58 AM (permalink)
        0
        Good point.
        "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
        Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
        http://www.visualbasicscript.com/m_47117/tm.htm
         
        #4

          Online Bookmarks Sharing: Share/Bookmark

          Jump to:

          Current active users

          There are 0 members and 2 guests.

          Icon Legend and Permission

          • New Messages
          • No New Messages
          • Hot Topic w/ New Messages
          • Hot Topic w/o New Messages
          • Locked w/ New Messages
          • Locked w/o New Messages
          • Read Message
          • Post New Thread
          • Reply to message
          • Post New Poll
          • Submit Vote
          • Post reward post
          • Delete my own posts
          • Delete my own threads
          • Rate post

          2000-2012 ASPPlayground.NET Forum Version 3.9