Results 1 to 15 of 15
  1. #1
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts

    Powershell or CMD?

    I read an article that talked about all the advantages of Powershell...Well that would be fine if I could even get a foothold on how it works. I know there are a bunch of Google links, but are there any that are fairly basic and quick starts?

    Chuck Billow
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  2. #2
    Administrator
    Join Date
    Mar 2001
    Location
    St Louis, Missouri, USA
    Posts
    23,580
    Thanks
    5
    Thanked 1,058 Times in 927 Posts
    Here's a TechNet link - Scripting with Windows PowerShell. There are several other links on that page from very basic to more advanced.

    There's also this blog - Hey, Scripting Guy! Blog. It is a resource which has many, many scripts and tips.
    Joe

  3. The Following User Says Thank You to JoeP517 For This Useful Post:

    mrjimphelps (2016-06-21)

  4. #3
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts
    Thanks Joe.

    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  5. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Chuck,

    Joe provided you with some very good links, I've used them extensively.

    The two biggest differences between CMD and PS IMHO are:
    1. Powershell is much much more powerful.
    2. Powershell code is much more readable (easier to understand, especially 6 months later or when reading others' scripts).


    If you'll check out the Windows Programming section of the Lounge I've been chronicling my learning experience with PS.

    With PS Google is definitely your friend as well as the helpful people in the Lounge.

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  6. The Following User Says Thank You to RetiredGeek For This Useful Post:

    CWBillow (2016-07-05)

  7. #5
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,188
    Thanks
    47
    Thanked 983 Times in 913 Posts
    PS requires you to make changes on each PC before you can run scripts - single lines can be typed and run without changes to the PC - batch files don't.

    cheers, Paul

  8. #6
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,414
    Thanks
    33
    Thanked 195 Times in 175 Posts
    If you have enough time left in your life to understand and become expert in PowerShell, go ahead!

    RG: BATch files can be quite intelligible using comment lines.
    :: my BATch files are about 50% comments!
    BATcher

    Time prevents everything happening all at once...

  9. #7
    Super Moderator Rick Corbett's Avatar
    Join Date
    Dec 2009
    Location
    South Glos., UK
    Posts
    2,143
    Thanks
    101
    Thanked 579 Times in 464 Posts
    Chuck,

    Without knowing what you want to do, I would suggest that it's impossible to advise you whether PowerShell or CMD would be best for you. Depending on your needs, it could well be... neither, if a different scripting language (VBS? AutoHotkey? AutoIt?) was better suited.

  10. #8
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Rick,

    +1 - Wish I'd said that!
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  11. #9
    5 Star Lounger Lugh's Avatar
    Join Date
    Jun 2010
    Location
    Indy
    Posts
    620
    Thanks
    166
    Thanked 77 Times in 68 Posts
    PS is on my bucket list too, here are some links I've collected:

    Getting started with PowerShell 3.0 Jump Start – a free Microsoft Virtual Academy course.

    PowerShell Tutorial Online – a free site aimed mainly at scripting beginners.

    A beginner’s introduction to Windows PowerShell – free, but registration requested.

    6 Basic PowerShell Commands To Get More Out Of Windows

    Boost Your Productivity With Windows PowerShell Scripts

    Windows PowerShell scripting – a free TechNet library of PowerShell-related webcasts, articles, guides, sample scripts, and so forth.

    PowerShell Pro! – site; free, though it’s best if you already know a bit of VBScript.
    Lugh.
    ~
    Windows 10 Pro x64 1607; Office 2016 (365 Home) x32; Win Defender, MBAM Pro

    ASRock H97 Anniversary; Xeon E3-1231V3 (like i7)
    Gigabyte GeForce GTX 970; 12GB Crucial DDR3 1600
    Logitech MX Master mouse; Roccat Isku kb

  12. The Following User Says Thank You to Lugh For This Useful Post:

    RetiredGeek (2016-06-22)

  13. #10
    5 Star Lounger Lugh's Avatar
    Join Date
    Jun 2010
    Location
    Indy
    Posts
    620
    Thanks
    166
    Thanked 77 Times in 68 Posts
    There are 5 free PowerShell PDFs on this page--the 4 DOCXs aren't available anymore [the page is a couple of years old]. The PS section is less than 1/4 down the page, jic your browser doesn't have a page search.

    300 free Microsoft eBooks

    "Windows 8.1, Windows 8, Windows 7, Office 2013, Office 365, Office 2010, SharePoint 2013, Dynamics CRM, PowerShell, Exchange Server, Lync 2013, System Center, Azure, Cloud, SQL Server, and much more".
    Last edited by Lugh; 2016-06-23 at 06:42.
    Lugh.
    ~
    Windows 10 Pro x64 1607; Office 2016 (365 Home) x32; Win Defender, MBAM Pro

    ASRock H97 Anniversary; Xeon E3-1231V3 (like i7)
    Gigabyte GeForce GTX 970; 12GB Crucial DDR3 1600
    Logitech MX Master mouse; Roccat Isku kb

  14. #11
    3 Star Lounger djohnson's Avatar
    Join Date
    Dec 2009
    Location
    Delaware City, Delaware
    Posts
    323
    Thanks
    13
    Thanked 32 Times in 30 Posts
    If you want to make a ps1 (PowerShell) script to always run as administrator, simply put this before your command line
    Code:
    param([switch]$Elevated)
    
    function Test-Admin {
      $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
      $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
    }
    
    if ((Test-Admin) -eq $false)  {
        if ($elevated) 
        {
            # tried to elevate, did not work, aborting
        } 
        else {
            Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
    }
    
    exit
    }
    
    'running with full privileges'

  15. The Following User Says Thank You to djohnson For This Useful Post:

    CWBillow (2016-07-05)

  16. #12
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts
    Cool! Thanks.

    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  17. #13
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts
    Thanks.

    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  18. #14
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts
    As always, thanks RG.

    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  19. #15
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts
    Quote Originally Posted by djohnson View Post
    If you want to make a ps1 (PowerShell) script to always run as administrator, simply put this before your command line
    Code:
    param([switch]$Elevated)
    
    function Test-Admin {
      $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
      $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
    }
    
    if ((Test-Admin) -eq $false)  {
        if ($elevated) 
        {
            # tried to elevate, did not work, aborting
        } 
        else {
            Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
    }
    
    exit
    }
    
    'running with full privileges'
    Totally cool. Thanks.

    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •