In Questo Articolo
🔹 Gestione remota
| Comando | Descrizione | Esempio |
|---|---|---|
Enter-PSSession -ComputerName | Avvia sessione remota | Enter-PSSession -ComputerName Server01 |
Invoke-Command -ComputerName | Esegui comando remoto | Invoke-Command -ComputerName Server01 -ScriptBlock { Get-Process } |
🔹 Gestione errori
| Comando | Descrizione | Esempio |
|---|---|---|
try { ... } catch { ... } | Gestione delle eccezioni | try { Get-Item "nonexistent.txt" } catch { Write-Output "Error: $_" } |
🔹 Espressioni regolari
| Comando | Descrizione | Esempio |
|---|---|---|
-match | Controllo corrispondenza | "Hello123" -match "\d+" |
-replace | Sostituzione di caratteri | "abc123" -replace "\d+", "" |
🔹 JSON e XML
| Comando | Descrizione | Esempio |
|---|---|---|
ConvertFrom-Json / ConvertTo-Json | Leggere e scrivere JSON | `$json = Get-Content file.json |
[xml] | Lettura XML | [xml]$xml = Get-Content file.xml$xml.DocumentElement.ElementName |
🔹 Job in background
| Comando | Descrizione | Esempio |
|---|---|---|
Start-Job | Avvia job in background | Start-Job -ScriptBlock { Get-Process } |
Get-Job | Visualizza job attivi | Get-Job |
Receive-Job | Ottieni risultati del job | Receive-Job -Id 1 |
Remove-Job | Elimina job | Remove-Job -Id 1 |
🔹 Attività pianificate
| Comando | Descrizione | Esempio |
|---|---|---|
Register-ScheduledTask | Crea attività pianificata | Register-ScheduledTask -Action (New-ScheduledTaskAction -Execute "notepad.exe") -Trigger (New-ScheduledTaskTrigger -At 12pm -Daily) -TaskName "NotepadTask" |
🔹 Sicurezza e credenziali
| Comando | Descrizione | Esempio |
|---|---|---|
Get-Credential | Richiesta credenziali | Get-Credential |
Invoke-Command | Comando remoto con credenziali | Invoke-Command -ComputerName Server01 -Credential (Get-Credential) -ScriptBlock { Get-Service } |
🔹 Prestazioni e logging
| Comando | Descrizione | Esempio |
|---|---|---|
Measure-Command | Misura il tempo di esecuzione | Measure-Command { Get-Process } |
Start-Transcript | Avvia registrazione della sessione | Start-Transcript -Path log.txt |
Stop-Transcript | Ferma registrazione | Stop-Transcript |