Mis pulgares arriba: Powershell es uno de mis lenguajes de shell scripting favoritos. Probablemente recibiré muchas críticas de la gente de Linux/bash/perl/python, pero Powershell obtiene puntos por:
- Lecturabilidad: puedes tener un código conciso que sea legible y usar palabras como Where, Select, Replace frente a palabras como sed, awk, tr
- Bibliotecas: La Galería PowerShell permite instalar módulos
- Datos: Trata de forma nativa los tipos de datos JSON y XML (YAML disponible como módulo)
- Crea funciones bien definidas
Primero para responder a tu pregunta. El uso principal de powershell es aplicar cambios a su sistema sin una GUI. Esto le permite ejecutar la automatización de la secuencia de comandos, por lo que no tiene que recordar su secuencia de apuntar y hacer clic para crear su estado deseado.
También vale la pena mencionar es el último sabor, Powershell DSC (Configuración de Estado Deseado). This is picking up on configuration management systems like Chef / Puppet / Ansible by using a configuration file to set the state of the machine.
Some Powershell 101:
- # if you are running configuration scripts on your system,
- # you usually want to Run as Administrator
- # by default, your system doesn't allow you to run Powershell scripts,
- # this command opens that up
- Set-ExecutionPolicy Bypass ;
- # this command sets it back
- Set-ExecutionPolicy Restricted ;
- # my favourite command, installing the package manager called Chocolatey,
- # you can pretty much find every popular utility available for Windows here
- # https://chocolatey.org/install
- # Install Chocolatey: Don't have Windows 10? (Powershell 1/2)
- iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) ;
- # Install Chocolatey: Windows 10 (Powershell 3+)
- iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex ;
- # my favourite chocolatey installs
- # find more packages here: https://chocolatey.org/packages
- choco install -y powershell ; # make sure powershell is up to date
- choco install -y @(
- "PSWindowsUpdate",
- "visualstudiocode",
- "googlechrome",
- "openssh",
- "putty",
- "vagrant",
- "virtualbox"
- ) ; # or install more than one using an array
- # Windows Update from the command-line
- Import-Module PSWindowsUpdate ; # notice above we've installed the package
- Get-WUInstall -AcceptAll ;
- # need to do a simple curl?
- # e.g. Save etsy's Code as Craft logo as a file.
- # https://codeascraft.com/wp-content/uploads/2014/12/codeascraft_black_on_white.png
- iwr "https://codeascraft.com/wp-content/uploads/2014/12/codeascraft_black_on_white.png" -outfile "codeascraft.png" ;
- # read some JSON data?
- # e.g. People in Space right now
- # https://github.com/jdorfman/awesome-json-datasets#nasa
- $url = "http://api.open-notify.org/astros.json"
- # get entire JSON and convert to Object[]
- $data = iwr $url | ConvertFrom-JSON ;
- # displays all the people on the ISS right now
- $data.people | Where { $_.craft -eq "ISS" } ;
Another plus is having access to anything in .NET, which makes Powershell extremely powerful. Additionally, to vex the Linux folks even more, PowerShell is open sourced and is available on Linux 🙂