Windows PowerShell vs. bash examples - Ubuntu

This is a discussion on Windows PowerShell vs. bash examples - Ubuntu ; The claims that PowerShell is better than bash piqued my curiosity, so I decided to check PowerShell out. I am bowed to the genius of PowerShell creators. Here's one example: http://www.microsoft.com/technet/scr...0305a.mspx#EHC Let's call our input text file hosts.txt and put ...

+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 20 of 27

Thread: Windows PowerShell vs. bash examples

  1. Windows PowerShell vs. bash examples

    The claims that PowerShell is better than bash piqued my curiosity, so
    I decided to check PowerShell out.

    I am bowed to the genius of PowerShell creators.

    Here's one example:

    http://www.microsoft.com/technet/scr...0305a.mspx#EHC

    Let's call our input text file hosts.txt and put one computer name per
    line. These computers need to be accessible on the network and you
    must have Administrator privileges on them (as is usually true when
    you run a script against a remote machine [*** Cool gem
    here!***]). Our file should look something like this:

    client1
    client2
    client3
    client4

    We extract the computer names from the file with the trusty
    FileSystemObject, part of Script Runtime (included with Windows Script
    Host). Here's what the code looks like (we hope this will be
    sleep-inducingly familiar to many of you).

    Const FOR_READING = 1
    strFilename = "hosts.txt"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextStream = objFSO.OpenTextFile(strFilename, FOR_READING)
    Do Until objTextStream.AtEndOfStream
    strComputer = objTextStream.ReadLine
    Wscript.Echo "Use WMI to get OS and SP versions from " & strComputer
    Loop

    What we get back from the OpenTextFile method of FileSystemObject is
    actually an object representing a text stream. This object has handy
    properties such as AtEndOfStream and methods such as ReadLine that we
    use here to pull out one line at a time.

    Very "sleep inducingly" indeed.

    ##############################

    And here's how you do it with bash:

    awk '{print "Use WMI to get OS and SP versions from " $1}' < hosts.txt

    You see now how PowerShell is so superior? So much easier to read?

    Let's go to the next one:

    ################################################## ####################
    http://www.microsoft.com/technet/scr...0305a.mspx#EUC

    Retrieving operating system version and Service Pack

    To find out the operating system and service pack of computers, we use
    three properties of theWMI class Win32_OperatingSystem: Version,
    ServicePackMajorVersion and ServicePackMinorVersion.

    To get these, we connect to WMI on the computer in question and query
    for instances of the Win32_OperatingSystem class. (This query always
    returns only one instance, the operating system that is currently
    running.) Then we display these three properties, concatenating
    together ServicePackMajorVersion and ServicePackMinorVersion with a
    period in between.

    'Get strComputer from each line of text file.
    Set objWMIService = GetObject("winmgmts://" & strComputer)
    Set colOSes = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_OperatingSystem")
    For Each objOS in colOSes
    Wscript.Echo
    Wscript.Echo strComputer
    Wscript.Echo "OS Version: " & objOS.Version
    Wscript.Echo "Service Pack: " & objOS.ServicePackMajorVersion & _
    "." & objOS.ServicePackMinorVersion
    Next

    If we ran this, we would get output something like the following.

    client1
    OS Version: 5.1.2600
    Service Pack: 2.0

    If we wanted to display the name of the operating system rather than
    the version number, we could use the Caption property, which might be
    a bit more legible, rather than Version. In any case, in this script,
    we're only interested in Windows XP.

    We could put the two components we've created together and get the OS
    version and service pack on those four machines. The output would look
    like this:

    C:\scripts>xpsplist-wmi.vbs

    client1
    OS Version: 5.1.2600
    Service Pack: 1.0

    client2
    OS Version: 5.1.2600
    Service Pack: 2.0

    client3
    OS Version: 5.1.2600
    Service Pack: 2.0

    client4
    OS Version: 5.1.2600
    Service Pack:

    This is straightforward WMI, and many of you are no doubt yawning and
    craving that second cup of coffee at this point. But that's part of
    the beauty of scripting technologies: once you learn them, they're
    routine and easy to use. In this column, we're going to try to put the
    pieces of them together in slightly more complex and practical ways,
    but most of the building blocks are the same old stuff. Remember
    Dr. Scripto's timeless wisdom: "Be lazy (IT managers should read
    'productive'). Don't reinvent the wheel."

    ##############################

    Now onto bash and Linux examples:

    (using remote query)

    for server in $(echo "select hostname from servers" | mysql -uusername -ppassword); do
    ssh -l userid $server lsb_release -a
    done

    or (SQL only)

    echo "select os, spackminor, spackmajor from Win32_OperatingSystem" \
    | mysql -uusername -ppassword \
    | awk '{print "\nOS Version: " $1 "\nService Pack: " $3 "." $2;}'


    One more gem:

    ################################################## ####################
    http://www.microsoft.com/technet/scr...0305a.mspx#EMD

    Const FOR_APPENDING = 8
    strOutputFile = "xpsp.txt"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FileExists(strOutputFile) Then
    Set objTextStream = objFSO.OpenTextFile(strOutputFile, FOR_APPENDING)
    Else
    Set objTextStream = objFSO.CreateTextFile(strOutputFile)
    End If

    objTextStream.WriteLine "Inventory of Windows XP Service Packs"
    objTextStream.WriteLine "Taken " & Now
    objTextStream.WriteLine vbCrLf & "Computers Running Windows XP"
    objTextStream.WriteLine "============================"
    objTextStream.WriteLine "Total number: " & (intSP2 + intSP1 + intSP0)

    objTextStream.WriteLine vbCrLf & "Service Pack 2"
    objTextStream.WriteLine "--------------"
    objTextStream.WriteLine strSP2
    objTextStream.WriteLine "Total number: " & intSP2

    objTextStream.WriteLine vbCrLf & "Service Pack 1"
    objTextStream.WriteLine "--------------"
    objTextStream.WriteLine strSP1
    objTextStream.WriteLine "Total number: " & intSP1

    objTextStream.WriteLine vbCrLf & "No Service Pack"
    objTextStream.WriteLine "---------------"
    objTextStream.WriteLine strSP0
    objTextStream.WriteLine "Total number: " & intSP0

    objTextStream.WriteLine vbCrLf & "Computers Not Running Windows XP"
    objTextStream.WriteLine "================================"
    objTextStream.WriteLine "Total number: " & intNotXP

    objTextStream.WriteLine vbCrLf & "Could Not Connect To Computer"
    objTextStream.WriteLine "============================="
    objTextStream.WriteLine "Total number: " & intErr
    objTextStream.WriteLine

    objTextStream.Close

    ##############################

    This perfect example would look terrible in bash, of course

    (
    cat << _EOB_
    Inventory of Windows XP Service Packs
    Taken `date`
    Computers Running Windows XP
    ============================
    Total number: $(echo $intSP2+$intSP1+$intSP0|bc -l)

    Service Pack 2
    --------------
    $strSP2
    Total number: $intSP

    Service Pack 1
    --------------
    $strSP1
    Total number: $intSP1

    No Service Pack
    ---------------
    $strSP0
    Total number: $intSP0

    Computers Not Running Windows XP
    ================================
    Total number: $intNotX

    Could Not Connect To Computer
    =============================
    Total number: $intEr
    _EOB_
    ) >> xpsp.txt

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    Jokes aside, it is obvious to me that PowerShell is nowhere near
    actually being able to use it effectively for daily stuff.

  2. Re: Windows PowerShell vs. bash examples

    Ignoramus22113 wrote:
    > The claims that PowerShell is better than bash piqued my curiosity, so


    Are the following crossposts really needed here> :-)

    comp.os.linux.advocacy
    comp.os.linux.misc

  3. Re: Windows PowerShell vs. bash examples

    Ignoramus22113 wrote:
    > The claims that PowerShell is better than bash piqued my curiosity, so
    > I decided to check PowerShell out.
    > (...)
    > Jokes aside, it is obvious to me that PowerShell is nowhere near
    > actually being able to use it effectively for daily stuff.


    I was a bit perplexed when I first saw PowerShell examples. It looked so
    verbose, so unlike a scripting language. If I had PowerShell back in
    Windows 2000 I might have continued to administer Windows system but that
    ship as sailed (or should I say has sunk or was scrapped).

    Now I have enough GNU/Linux systems to keep me busy scripting for.

    Regards.

  4. Re: Windows PowerShell vs. bash examples

    In propman:

    [Snip...]

    > crossposts really needed here


    Hell no. I plonked the "Ignoramus" entity for this nonsense long ago, and
    will be plonking this thread for the same reason, too.

    --
    Regards, Weird (Harold Stevens) * IMPORTANT EMAIL INFO FOLLOWS *
    Pardon any bogus email addresses (wookie) in place for spambots.
    Really, it's (wyrd) at airmail, dotted with net. DO NOT SPAM IT.
    I toss GoogleGroup posts from gitgo (http://improve-usenet.org).

  5. Re: Windows PowerShell vs. bash examples

    > I was a bit perplexed when I first saw PowerShell examples. It looked so
    > verbose, so unlike a scripting language. If I had PowerShell back in
    > Windows 2000 I might have continued to administer Windows system but that
    > ship as sailed (or should I say has sunk or was scrapped).


    They are intended for Visual Basic people...

    --
    @~@ Might, Courage, Vision, SINCERITY.
    / v \ Simplicity is Beauty! May the Force and Farce be with you!
    /( _ )\ (Xubuntu 8.04.1) Linux 2.6.26.7
    ^ ^ 20:53:01 up 5 days 21:12 2 users load average: 1.11 1.18 1.09
    不*伅U! 不詐騙! 不援交! 不打交! 不打劫! 不自殺! 請考慮綜援 (CSSA):
    http://www.swd.gov.hk/tc/index/site_...sub_addressesa

  6. Re: Windows PowerShell vs. bash examples

    Man-wai Chang ToDie (33.6k) wrote:

    >> I was a bit perplexed when I first saw PowerShell examples. It looked so
    >> verbose, so unlike a scripting language. If I had PowerShell back in
    >> Windows 2000 I might have continued to administer Windows system but that
    >> ship has sailed (or should I say has sunk or was scrapped).

    >
    > They are intended for Visual Basic people...


    Microsoft "programmers" seem to think that Visual Basic is a *programming*
    *language*

    C.


  7. Re: Windows PowerShell vs. bash examples

    On 2008-11-03, Christopher Hunter wrote:
    > Man-wai Chang ToDie (33.6k) wrote:
    >
    >>> I was a bit perplexed when I first saw PowerShell examples. It looked so
    >>> verbose, so unlike a scripting language. If I had PowerShell back in
    >>> Windows 2000 I might have continued to administer Windows system but that
    >>> ship has sailed (or should I say has sunk or was scrapped).

    >>
    >> They are intended for Visual Basic people...

    >
    > Microsoft "programmers" seem to think that Visual Basic is a *programming*
    > *language*


    Or that "powershell" is *convenient*.

    --
    Due to extreme spam originating from Google Groups, and their inattention
    to spammers, I and many others block all articles originating
    from Google Groups. If you want your postings to be seen by
    more readers you will need to find a different means of
    posting on Usenet.
    http://improve-usenet.org/

  8. Re: Windows PowerShell vs. bash examples

    In article ,
    nomail@nomail.not (LusoTec) writes:

    > I was a bit perplexed when I first saw PowerShell examples. It looked
    > so verbose, so unlike a scripting language.


    It looks more like Visual Basic to me.

    --
    /~\ cgibbs@kltpzyxm.invalid (Charlie Gibbs)
    \ / I'm really at ac.dekanfrus if you read it the right way.
    X Top-posted messages will probably be ignored. See RFC1855.
    / \ HTML will DEFINITELY be ignored. Join the ASCII ribbon campaign!


  9. Re: Windows PowerShell vs. bash examples

    On Sun, 02 Nov 2008 22:37:57 -0600, Ignoramus22113 wrote:

    > And here's how you do it with bash:
    >
    > awk '{print "Use WMI to get OS and SP versions from " $1}' < hosts.txt


    You cheated. You are supposed to do it in bash, not use bash to call
    awk.

    sf

  10. Re: Windows PowerShell vs. bash examples

    On 2008-11-03, jellybean stonerfish wrote:
    > On Sun, 02 Nov 2008 22:37:57 -0600, Ignoramus22113 wrote:
    >
    >> And here's how you do it with bash:
    >>
    >> awk '{print "Use WMI to get OS and SP versions from " $1}' < hosts.txt

    >
    > You cheated. You are supposed to do it in bash, not use bash to call
    > awk.


    Try to cheat like this in PowerShell.

    --
    Due to extreme spam originating from Google Groups, and their inattention
    to spammers, I and many others block all articles originating
    from Google Groups. If you want your postings to be seen by
    more readers you will need to find a different means of
    posting on Usenet.
    http://improve-usenet.org/

  11. Re: Windows PowerShell vs. bash examples

    On Sun, 02 Nov 2008 22:37:57 -0600, Ignoramus22113 wrote:
    > And here's how you do it with bash:
    > awk '{print "Use WMI to get OS and SP versions from " $1}' < hosts.txt


    In comp.os.linux.misc jellybean stonerfish wrote:
    > You cheated. You are supposed to do it in bash, not use bash to call
    > awk.


    You mean like this (one liner)? ;-)

    while read H; do echo "Use WMI to get OS and SP versions from $H"; \
    done
    Chris

  12. Re: Windows PowerShell vs. bash examples

    Christopher Hunter wrote in
    news:6n8c6lFk90rfU1@mid.individual.net:

    > Man-wai Chang ToDie (33.6k) wrote:
    >
    >>> I was a bit perplexed when I first saw PowerShell examples. It
    >>> looked so verbose, so unlike a scripting language. If I had
    >>> PowerShell back in Windows 2000 I might have continued to administer
    >>> Windows system but that ship has sailed (or should I say has sunk or
    >>> was scrapped).

    >>
    >> They are intended for Visual Basic people...

    >
    > Microsoft "programmers" seem to think that Visual Basic is a
    > *programming* *language*


    It's not ?

    (You are either saying VB is junk, or that VB is an IDE/Compiler, and not a
    language in itself. Unfortunately, I can't tell.....but VB (not.Net) *is* a
    very capable Windows programming environment/compiler/language.)

  13. Re: Windows PowerShell vs. bash examples

    DanS wrote:

    > It's not ?
    >
    > (You are either saying VB is junk, or that VB is an IDE/Compiler, and not a
    > language in itself. Unfortunately, I can't tell.....but VB (not.Net) *is* a
    > very capable Windows programming environment/compiler/language.)


    HAHAHAHAHA!

  14. Re: Windows PowerShell vs. bash examples

    On 2008-11-03, Chris Davies wrote:
    > On Sun, 02 Nov 2008 22:37:57 -0600, Ignoramus22113 wrote:
    >> And here's how you do it with bash:
    >> awk '{print "Use WMI to get OS and SP versions from " $1}' < hosts.txt

    >
    > In comp.os.linux.misc jellybean stonerfish wrote:
    >> You cheated. You are supposed to do it in bash, not use bash to call
    >> awk.

    >
    > You mean like this (one liner)? ;-)
    >
    > while read H; do echo "Use WMI to get OS and SP versions from $H"; \
    > done >
    > Chris


    I do not see how one can have any "bash vs. PowerShell" contest
    without using the rest of GNU utilities, which usually come with
    bash.

    The whole point of bash is to NOT be a bloated pig like powershell,
    and instead use I/O intelligently to use numerous helper processes
    like awk, date, ls, etc, and to not crash if those helpers develop a
    fatal error.

    --
    Due to extreme spam originating from Google Groups, and their inattention
    to spammers, I and many others block all articles originating
    from Google Groups. If you want your postings to be seen by
    more readers you will need to find a different means of
    posting on Usenet.
    http://improve-usenet.org/

  15. Re: Windows PowerShell vs. bash examples

    On 2008-11-03, Ignoramus7766 wrote:
    > On 2008-11-03, Chris Davies wrote:
    >> On Sun, 02 Nov 2008 22:37:57 -0600, Ignoramus22113 wrote:
    >>> And here's how you do it with bash:
    >>> awk '{print "Use WMI to get OS and SP versions from " $1}' < hosts.txt

    >>
    >> In comp.os.linux.misc jellybean stonerfish wrote:
    >>> You cheated. You are supposed to do it in bash, not use bash to call
    >>> awk.

    >>
    >> You mean like this (one liner)? ;-)
    >>
    >> while read H; do echo "Use WMI to get OS and SP versions from $H"; \
    >> done >>
    >> Chris

    >
    > I do not see how one can have any "bash vs. PowerShell" contest
    > without using the rest of GNU utilities, which usually come with
    > bash.


    Agreed. Bash vs. PowerShell is a pointless comparison. Nobody
    installs Bash on a Unix system without any other command-line
    utilities. Bash is is only one component of a Unix
    command-line environment. The proper comparison is PowerShell
    vs. Unix-command-line-tools.

    > The whole point of bash is to NOT be a bloated pig like
    > powershell, and instead use I/O intelligently to use numerous
    > helper processes like awk, date, ls, etc, and to not crash if
    > those helpers develop a fatal error.


    Yup.

    --
    Grant Edwards grante Yow! Why is it that when
    at you DIE, you can't take
    visi.com your HOME ENTERTAINMENT
    CENTER with you??

  16. Re: Windows PowerShell vs. bash examples

    On Sun, 02 Nov 2008 22:37:57 -0600, Ignoramus22113 wrote:

    > The claims that PowerShell is better than bash piqued my curiosity, so
    > I decided to check PowerShell out.
    >
    > I am bowed to the genius of PowerShell creators.
    >
    > Here's one example:
    >
    > http://www.microsoft.com/technet/scr...0305a.mspx#EHC


    Uhh.. dude. Are you an idiot?

    That's wscript, which has been in Windows since IE4. That's not
    PowerShell.

    All your examples are wscript examples, not Powershell. What kind of a
    moron are you? Oh right, you're an Ignoramus.

  17. Re: Windows PowerShell vs. bash examples

    Christopher Hunter wrote in
    news:6n8q8bFk9kfmU1@mid.individual.net:

    > DanS wrote:
    >
    >> It's not ?
    >>
    >> (You are either saying VB is junk, or that VB is an IDE/Compiler, and
    >> not a language in itself. Unfortunately, I can't tell.....but VB
    >> (not.Net) *is* a very capable Windows programming
    >> environment/compiler/language.)

    >
    > HAHAHAHAHA!


    By that reply, I'm guessing your comment was a slam. Any programming
    language can suck, if the programmer sucks.

    You're still wrong though. Anything, except for some very low-level
    memory manipulation, can be written in VB. I've written a complete shell
    replacement for Windows that is used instead of Explorer. It works well,
    has a memory footprint of about 6 Megs, and offers complete
    functionality, except for a desktop, which is by design. I did author a
    desktop 'module', but don't use it, and have ripped it from the package.

  18. Re: Windows PowerShell vs. bash examples

    On Sun, 02 Nov 2008 22:37:57 -0600, Ignoramus22113 wrote:

    > And here's how you do it with bash:
    >
    > awk '{print "Use WMI to get OS and SP versions from " $1}' < hosts.txt


    And here's one of any number of ways you can do it in PowerShell:

    gc hosts.txt | Foreach-object {echo "Use WMI to get OS and SP versions from $_"}

  19. Re: Windows PowerShell vs. bash examples

    On Tue, 04 Nov 2008 09:12:27 +0900, Ian Hilliard wrote:

    > They can't help themselves at Microsoft. Everything has to look like Visual Basic.


    Actually, the examples Ignoramus gave *WERE* Visual Basic. 10 year old VB
    at that, and not PowerShell at all.

    Native PowerShell scripting, which can use VB, does not look anything like
    VB. So your comment is false.

  20. Re: Windows PowerShell vs. bash examples


    "jellybean stonerfish" wrote in message
    news:490f1b62$0$31742$bd467cd0@news.dslextreme.com ...
    > On Sun, 02 Nov 2008 22:37:57 -0600, Ignoramus22113 wrote:
    >
    >> And here's how you do it with bash:
    >>
    >> awk '{print "Use WMI to get OS and SP versions from " $1}' < hosts.txt

    >
    > You cheated. You are supposed to do it in bash, not use bash to call
    > awk.
    >
    > sf


    It wasn't cheating. Awk is part of the things bash can call. Using any one
    of a dozen different ways is up to the author. But if you must:

    while read line; do echo "Use WMI to get OS and SP versions from ${line}";
    done < hosts.txt

    One liner. Why make it more (Microsoft) complex and slower than it needs to
    be.

    Next issue, UNIX/Linux people have more fun on dates too. MS-Windows for
    boys, X-Windows for men.

    Go back toy your MS-Windows pond.
    --------
    {man;look;for;cat;nice;gawk;find;whois;init;sed;ta lk;date;grep;touch;finger;
    flex;unzip;head;tail;mount;workbone;fsck;yes;gasp; fsck;more;yes;yes;
    eject;umount;makeclean;zip;sort;done;cu;split;exit :xargs!!}











+ Reply to Thread
Page 1 of 2 1 2 LastLast