PowerShell: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Gsdefender2 (discussione | contributi)
mNessun oggetto della modifica
Gsdefender2 (discussione | contributi)
fine traduzione
Riga 1:
{{T|lingua=inglese|argomento=informatica|data=novembre 2006}}
'''Windows PowerShell''', noto precedentemente come '''Microsoft Shell''' o '''MSH''' (o col nome in codice '''Monad''') è una [[shell]] caratterizzata dall'[[interfaccia a linea di comando]] (CLI) e da un [[linguaggio]] [[script]], sviluppata da [[Microsoft]]. Tale prodotto è basato sulla [[programmazione a oggetti]] e sul framework [[Microsoft .NET]].
 
Line 46 ⟶ 45:
Il nome in codice di PowerShell, ''Monad'', proviene dalla [[monadologia]] di [[Gottfried Leibniz]], una filosofia in cui l'universo è composto da elementi fondamentali, le ''[[monadi]]'', disposti in una "[[armonia prestabilita]]". In maniera simile, PowerShell è la combinazione di compiti complessi e di una serie di componenti, le ''cmdlets'' (''command lets'', serie di comandi), che sono classi .NET progettate per sfruttare le caratteristiche dell'ambiente. La differenza fondamentale tra l'approccio Unix e quello di PowerShell risiede nel fatto che piuttosto che creare una "pipeline" (lett. ''tubo'') basata su input ed output testuali, PowerShell fa passare i dati da una cmdlet all'altra come ''oggetti'' (dati dotati di una struttura ben precisa).
 
L'output di una cmdlet, se si tenta di accedervi tramite riga di coamndo, viene automaticamente convertito in testo; se, invece, si tenta di utilizzarlo in un'altra cmdlet, esso verrà convertito nell'oggetto più appropriato per l'input di quell'altra cmdlet. In questo modo, varie utility comunemente utilizzate nelle pipelines Unix, quali [[grep]] ed [[awk]], non sono più necessarie, e si permette una combinazione interattiva o in un ambiente di scripting dei singoli elementi, cosa che avrebbe, diversamente, richiesto un [[linguaggio di programmazione]] più complesso. Per esempio, una lista dei processi in esecuzione sarà costituita dal testo che li descrive, ma dagli oggetti che la compongono, sicchè è possibile invocare metodi su questi oggetti senza far esplicito riferimento ad alcuna struttura o [[libreria (informatica)|libreria]].
 
== Caratteristiche ==
<!--
 
* Linguaggio di scripting simile al [[C Sharp|C#]], con molte funzionalità dedicate agli utenti esperti, come il supporto diretto alle [[hashtable]]s, i costrutti switch basati su espressioni regolari, la scomposizione degli [[array]], la possibilità di memorizzare come dati [[metodo anonimo|metodi anonimi]] da eseguire in un secondo momento. Sono presenti, naturalmente, tutte le caratteristiche che ci si aspetta di trovare in un linguaggio di scripting, quali l'[[iterazione]] (for/foreach/while), i costrutti condizionali (if/switch), i campi di visibilità delle variabili (global/script/local/private) e la possibilità di definire funzioni.
Similarly, PowerShell is a composite of the complex tasks of a series of components. The components are special programs called ''cmdlets'' (pronounced ''command lets''), which are .NET classes designed to use the features of the environment. The key difference between the usual Unix approach and the PowerShell one is that rather than creating a "pipeline" based on ''textual'' input and output, PowerShell passes data between the various cmdlets as ''objects'' (structured data).
 
* Tutte le cmdlets ereditano alcune caratteristiche, cosa che permette all'utente di scegliere, ad esempio, il livello di interazione e la modalità di gestione degli errori; si consideri, come esempio, la "sospensione", che permette di entrare in una nuova shell di comando, indagare su un problema, e quindi continuare con il comando originale. Al programmatore viene fornito un semplice meccanismo integrato per definire le richieste da mostrare in situazioni del genere. Le cmdlet che restituiscono qualcosa all'esterno supportano le opzioni -WHATIF e -CONFIRM. -WHATIF simula l'esecuzione della procedura, comunicandone il possibile esito all'utente. -CONFIRM informa l'utente su ciò che sta per accadere e gli permette di decidere cosa fare.
If accessed individually from the command line, a cmdlet's output will automatically be converted into text, but if its output is to be used by another cmdlet, it will be converted into whatever form of object is most appropriate for that cmdlet's input. This has the advantage of eliminating the need for the many text-processing utilities which are common in Unix pipelines, such as [[grep]] and [[awk]], as well as allowing things to be combined interactively, or in a scripting environment, which would otherwise require a more complex [[programming language]]. For instance, a listing of processes will consist not of text describing them, but objects representing them, so that methods can be called on those objects without explicit reference to any outside structure or [[library (computer science)|library]].
 
* Un modello ''provider'' estendibile fornisce la possibilità di accedere e manipolare non solo il [[file system]], ma anche altre strutture dati gerarchiche. Ad esempio, PowerShell integra un provider per il [[Registro di Windows]] che consente l'accesso agli alberi "HKLM" (HKEY_LOCAL_MACHINE) e "HKCU" (HKEY_CURRENT_USER). In questo modo, il registro può essere visualizzato con comandi quali "dir HKLM:\SOFTWARE\Microsoft" dal prompt della shell. PowerShell fornisce provider per la libreria di certificati di sicurezza, le variabili d'ambiente e di shell, le funzioni e gli alias; gli utenti possono creare loro propri provider e integrarli in PowerShell.
 
* Le opzioni della riga di comando sono, in genere, parole intere, ma è possibile farvi riferimento più velocemente, specificando solo il numero minimo di lettere necessario a distinguerle dalle altre (ad esempio, l'opzione <code>-mostra-informazioni-dettagliate</code> può essere richiamata specificando solo <code>-m</code> se nessun'altra opzione comincia per 's').
 
* Completamento automatico dei comandi estendibile dall'utente. Si pensi che [[cmd.exe]] nelle versioni recenti di Windows può solo completare i nomi di file e directory, a differenza di ciò che accade in shell quali [[bash]] e [[zsh]].
 
* Possibilità di assegnare l'output di un comando ad una variabile, che diventa un oggetto o un array di oggetti visualizzabile in qualunque maniera si desideri.
 
==Caratteristiche==
Although still in development, a number of key features of PowerShell have already been revealed, including:
*A [[C Sharp|C#]]-like scripting language with many power user features such as direct support for [[hashtable]]s, [[switch statement]]s that can case on [[regular expression]]s, [[array]] slicing and [[anonymous method]]s (script blocks) that can be stored as data and then later executed. That is in addition to the normal scripting language features such as [[looping]] (for/foreach/while), [[conditional statement]]s (if/switch), [[variable scoping]] (global/script/local/private) and the abililty to define functions.
*Cmdlets all inherit certain options, allowing the user to choose things such as the level of interaction and how to deal with errors &mdash; including a "suspend" feature, which allows the user to enter a new command shell, investigate a problem, and then continue with the original command. A simple mechanism is built-in for the programmer to define the prompts to be shown in such circumstances. Cmdlets that produce side-effects support the options: -WHATIF and -CONFIRM. -WHATIF informs the user what would have happened but no action takes place. -CONFIRM informs the user what is about to happen and allows the user to control whether it takes place or not.
*An extensible ''provider'' model provides not only access to and manipulation of the [[file system]] but also other hierarchical stores. For instance, PowerShell comes with a [[Windows registry|registry]] provider that allows access to the registry via the "HKLM" and "HKCU" hives. With this, the registry can be browsed by executing commands like "dir HKLM:\SOFTWARE\Microsoft" at the shell prompt. PowerShell comes with providers for the certificate store as well as [[environment variable]]s, shell variables, local certification store, functions and aliases. Like cmdlets, the provider model is extensible, allowing third parties to create their own provider model and snap it into PowerShell.
*The command-line options are generally whole words, but can be specified as the minimum number of letters necessary (e.g. the option <code>-show-detailed-information</code> could be entered as <code>-s</code> if no other option began with 's')
*Comprehensive, user-extendable, [[tab completion]] features. The [[cmd.exe]] shell in current versions of Windows can only complete file or directory names, in contrast to the advanced completion in shells such as [[bash]] and [[zsh]].
*The ability to assign the output of a command to a variable, which will then be an object or array of objects inspectable in any way desired.
-->
==Esempi==
 
Line 101 ⟶ 99:
 
==Collegamenti esterni==
* {{en}} [http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx Homepage di PowerShell]
* {{en}}[http://channel9.msdn.com/tags/monad Channel9 Monad Interviews/Demos con Jeffrey Snover] - l'Architetto di Windows PowerShell
* {{en}}[http://www.microsoft.com/technet/scriptcenter/resources/interviews/snover.mspx TechNet Script Center Interview with Jeffrey Snover] - l'Architetto di Windows PowerShell
* {{en}}[http://www.microsoft.com/technet/technetmag/issues/2005/11/Scripting/default.aspx ''Monad: The Future of Windows Scripting''] - an article in TechNet Magazine by Thomas Lee.
* {{en}}[http://www.computerweekly.com/Article133957.htm ''Future Windows component could spur old-school script viruses - Monad's role in future security concerns''], by Paul Roberts, IDG News Service
* {{en}}[http://www.leeholmes.com/blog/MonadAndTheFirstVistaVirus.aspx ''Monad and the "First Vista Virus"], a clarification by Lee Holmes, a developer on the Windows PowerShell Team
* {{en}}[http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx Scripting with Windows PowerShell]
* {{en}}[http://blogs.msdn.com/powershell/ Windows PowerShell Team Blog]
* {{en}}[http://powershell.wik.is/Home The PowerShell Wiki], a collection of useful scripts for the newcomer as well as the advanced user
* {{en}}[http://www.primalscript.com Example of a commercial Windows PowerShell editing environment]
* {{en}}[http://prpi.blogspot.com/2006/11/even-better-odpnet-under-windows.html Oracle Data Provider for .NET under PowerShell]
* {{en}}[http://msdn2.microsoft.com/en-us/library/ms714658.aspx How Windows PowerShell Works]
 
[[Categoria:.NET]]