Results 1 to 15 of 15
  1. #1
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,539
    Thanks
    87
    Thanked 13 Times in 12 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
    24,271
    Thanks
    5
    Thanked 1,197 Times in 1,042 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,539
    Thanks
    87
    Thanked 13 Times in 12 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,953
    Thanks
    422
    Thanked 1,606 Times in 1,450 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
    9,013
    Thanks
    63
    Thanked 1,117 Times in 1,040 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,556
    Thanks
    36
    Thanked 212 Times in 189 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

    milliHelen (sub-unit): that quantity of female facial beauty sufficient to launch a single ship

  9. #7
    Administrator Rick Corbett's Avatar
    Join Date
    Dec 2009
    Location
    South Glos., UK
    Posts
    3,240
    Thanks
    142
    Thanked 847 Times in 682 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,953
    Thanks
    422
    Thanked 1,606 Times in 1,450 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
    848
    Thanks
    211
    Thanked 108 Times in 95 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.
    ~
    Dell Alienware Aurora R6 (new 2017)
    Windows 10 Home x64 1703; Office 365 x32
    GeForce GTX 1060; 16GB DDR4 2400
    256G SSD, 1TB HD

  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
    848
    Thanks
    211
    Thanked 108 Times in 95 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 05:42.
    Lugh.
    ~
    Dell Alienware Aurora R6 (new 2017)
    Windows 10 Home x64 1703; Office 365 x32
    GeForce GTX 1060; 16GB DDR4 2400
    256G SSD, 1TB HD

  14. #11
    Banned Member
    Join Date
    Dec 2009
    Posts
    349
    Thanks
    13
    Thanked 35 Times in 33 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,539
    Thanks
    87
    Thanked 13 Times in 12 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,539
    Thanks
    87
    Thanked 13 Times in 12 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,539
    Thanks
    87
    Thanked 13 Times in 12 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,539
    Thanks
    87
    Thanked 13 Times in 12 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
  •