PSA: Do not use PowerShell scripts that you do not understand

Discussion in 'Windows 10' started by riahc3, Aug 15, 2015.

  1. riahc3

    riahc3 MDL Addicted

    Jul 29, 2009
    547
    34
    30
    #1 riahc3, Aug 15, 2015
    Last edited by a moderator: Apr 20, 2017
    This isnt a Windows 10 per say but....

    Im seeing more and more people posting PowerShell scripts (which is great) and random people executing it on their PC (which is not great)

    Even though it is scripting and automation of a lot of things you can do (and cannot do) in the GUI, PowerShell is VERY (excuse the pun) powerful. In WS2012R2 Server Core, much of the server is configured using PowerShell.

    This is why I recommend everyone to find out what exactly the command does. Microsoft has made this VERY easy. Just type in a PowerShell prompt

    Get-Help (commandyouwanttoknowabout)

    Example, one that is used a lot when piping is Get-Member (gm) to find out what you can do with a object. So I would type.

    Code:
    Get-Help Get-Member
    This would print out exactly what it does.

    If you want examples:

    Code:
    Get-Help Get-Member -examples
    Will show you common used ways of the command

    To get a technical explaination

    Code:
    Get-Help Get-Member -full
    This shows everything and then some

    If you want to see if Microsoft has any updated people

    Code:
    Get-Help Get-Member -online


    TL;RD: Always check a PowerShell command or ask about it, before running it. Because I can tell you, "hey this activates Windows 10":

    Do not run this
    Code:
    Get-Disk | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel "disk2" -Confirm:$false
    
    And you willl never know what hit you...
     
  2. dhjohns

    dhjohns MDL Guru

    Sep 5, 2013
    3,262
    1,731
    120
    #2 dhjohns, Aug 15, 2015
    Last edited by a moderator: Apr 20, 2017
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. KNARZ

    KNARZ MDL Addicted

    Oct 9, 2012
    895
    482
    30
    Why did you post an example to format the drive? Also if you want to warn people.... formating the drive as an example to not run "any" code is just dumb and discredit your thread.
     
  4. dhjohns

    dhjohns MDL Guru

    Sep 5, 2013
    3,262
    1,731
    120
    I don't think it discredits the thread, but someone, somewhere will want to see what happens. :weep::weep::weep:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. T-S

    T-S MDL Guru

    Dec 14, 2012
    3,984
    1,331
    120
    Not that using an old school batch or a GUI program you don't understand is a good thing...
     
  6. Smorgan

    Smorgan Glitcher

    Mar 25, 2010
    1,855
    1,051
    60
    Ummm this is common sense.

    However most of the users on MDL do not do coding all that regularly. In order to translate for them you post the code comments in the scripting. This shows what exactly is going on. However if those users do not take the time to learn the most basic things then they are just asking for trouble to happen.
     
  7. dhjohns

    dhjohns MDL Guru

    Sep 5, 2013
    3,262
    1,731
    120
    A good programmer will always use comments.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. riahc3

    riahc3 MDL Addicted

    Jul 29, 2009
    547
    34
    30
    This is a example of me saying This activates Windows 10 and someone randomly on the internet copies and pastes the code without looking what it does or even asking about certain parameters.

    I warn in bold NOT to run the code. If someone runs that, they deserve it.
     
  9. riahc3

    riahc3 MDL Addicted

    Jul 29, 2009
    547
    34
    30
    Exactly. Thats the point of this thread.