Il mio pollice in su: Powershell è uno dei miei linguaggi di scripting di shell preferiti. Probabilmente riceverò un sacco di critiche da quelli di Linux/bash/perl/python, ma Powershell ottiene punti per:
- Leggibilità: si può avere un codice conciso che sia leggibile e usare parole come Where, Select, Replace contro parole come sed, awk, tr
- Librerie: PowerShell Gallery permette di installare moduli
- Dati: Tratta nativamente i tipi di dati JSON e XML (YAML disponibile come modulo)
- Crea funzioni ben definite
Prima di tutto per rispondere alla tua domanda. L'uso principale di powershell è quello di applicare modifiche al vostro sistema senza una GUI. Questo permette di eseguire l'automazione da script, in modo da non dover ricordare la sequenza di point & click per creare lo stato desiderato.
Degno di nota è anche l'ultimo gusto, Powershell DSC (Desired State Configuration). 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 🙂