In Questo Articolo
🔹 Basi
| Comando | Descrizione | Esempio |
|---|---|---|
Get-Command | Mostra tutti i comandi disponibili | Get-Command *service* |
Get-Help | Aiuto su un comando | Get-Help Get-Process -Examples |
Get-Alias | Elenco alias (nomi brevi) | Get-Alias ls |
Get-History | Cronologia dei comandi | Get-History |
Start-Transcript | Salva la sessione in un file | Start-Transcript -Path log.txt |
🔹 Lavorare con oggetti
| Comando | Descrizione | Esempio |
|---|---|---|
Get-Member | Visualizza proprietà e metodi di un oggetto | `Get-Service |
Select-Object | Selezione di campi | `Get-Process |
Where-Object | Filtraggio | `Get-Service |
Sort-Object | Ordinamento | `Get-Process |
Measure-Object | Conteggio valori | `Get-ChildItem |
🔹 File e cartelle
| Comando | Descrizione | Esempio |
|---|---|---|
Get-ChildItem (ls) | Elenco di file/cartelle | Get-ChildItem C:Temp |
New-Item | Crea file/cartella | New-Item file.txt -ItemType File |
Remove-Item (rm) | Elimina file/cartella | Remove-Item file.txt |
Copy-Item (cp) | Copia | Copy-Item file.txt file2.txt |
Move-Item (mv) | Sposta | Move-Item file.txt C:Backup |
Set-Location (cd) | Vai alla cartella | Set-Location C:Windows |
🔹 Processi e servizi
| Comando | Descrizione | Esempio |
|---|---|---|
Get-Process | Elenco processi | Get-Process chrome |
Stop-Process | Termina processo | Stop-Process -Name notepad |
Start-Process | Avvia processo | Start-Process notepad.exe |
Get-Service | Elenco servizi | Get-Service |
Start-Service | Avvia servizio | Start-Service Spooler |
Stop-Service | Arresta servizio | Stop-Service Spooler |
🔹 Rete
| Comando | Descrizione | Esempio |
|---|---|---|
Test-Connection | Test ping | Test-Connection google.com -Count 4 |
Test-NetConnection | Test porta | Test-NetConnection google.com -Port 443 |
Invoke-WebRequest (wget) | Scarica file/HTML | Invoke-WebRequest https://example.com -OutFile page.html |
Get-NetAdapter | Schede di rete | Get-NetAdapter |
Get-NetIPAddress | Indirizzi IP | Get-NetIPAddress |
🔹 Sistema
| Comando | Descrizione | Esempio |
|---|---|---|
Get-Date | Data e ora | Get-Date -Format "yyyy-MM-dd HH:mm:ss" |
Get-EventLog | Log eventi | Get-EventLog -LogName System -Newest 20 |
Restart-Computer | Riavvia computer | Restart-Computer -Force |
Get-ComputerInfo | Informazioni sistema | Get-ComputerInfo |
Get-LocalUser | Elenco utenti locali | Get-LocalUser |
🔹 Variabili e script
| Comando | Descrizione | Esempio |
|---|---|---|
$var = "Hello" | Crea variabile | $name = "User" |
Write-Output | Stampa testo | Write-Output "Hello $name" |
Read-Host | Input utente | $x = Read-Host "Enter value" |
If (...) { } Else { } | Condizione | If ($x -gt 10) { "Big" } Else { "Small" } |
ForEach-Object | Ciclo sugli oggetti | `1..5 |
Function | Definizione funzione | Function Say-Hello { param($n) "Hello $n" } |
🔹 Moduli
| Comando | Descrizione | Esempio |
|---|---|---|
Get-Module | Elenco moduli | Get-Module -ListAvailable |
Import-Module | Importa modulo | Import-Module ActiveDirectory |
Install-Module | Installa modulo | Install-Module Az |
Update-Module | Aggiorna modulo | Update-Module Az |