Skip to content

🔹 Gestione remota

ComandoDescrizioneEsempio
Enter-PSSession -ComputerNameAvvia sessione remotaEnter-PSSession -ComputerName Server01
Invoke-Command -ComputerNameEsegui comando remotoInvoke-Command -ComputerName Server01 -ScriptBlock { Get-Process }

🔹 Gestione errori

ComandoDescrizioneEsempio
try { ... } catch { ... }Gestione delle eccezionitry { Get-Item "nonexistent.txt" } catch { Write-Output "Error: $_" }

🔹 Espressioni regolari

ComandoDescrizioneEsempio
-matchControllo corrispondenza"Hello123" -match "\d+"
-replaceSostituzione di caratteri"abc123" -replace "\d+", ""

🔹 JSON e XML

ComandoDescrizioneEsempio
ConvertFrom-Json / ConvertTo-JsonLeggere e scrivere JSON`$json = Get-Content file.json
[xml]Lettura XML[xml]$xml = Get-Content file.xml$xml.DocumentElement.ElementName

🔹 Job in background

ComandoDescrizioneEsempio
Start-JobAvvia job in backgroundStart-Job -ScriptBlock { Get-Process }
Get-JobVisualizza job attiviGet-Job
Receive-JobOttieni risultati del jobReceive-Job -Id 1
Remove-JobElimina jobRemove-Job -Id 1

🔹 Attività pianificate

ComandoDescrizioneEsempio
Register-ScheduledTaskCrea attività pianificataRegister-ScheduledTask -Action (New-ScheduledTaskAction -Execute "notepad.exe") -Trigger (New-ScheduledTaskTrigger -At 12pm -Daily) -TaskName "NotepadTask"

🔹 Sicurezza e credenziali

ComandoDescrizioneEsempio
Get-CredentialRichiesta credenzialiGet-Credential
Invoke-CommandComando remoto con credenzialiInvoke-Command -ComputerName Server01 -Credential (Get-Credential) -ScriptBlock { Get-Service }

🔹 Prestazioni e logging

ComandoDescrizioneEsempio
Measure-CommandMisura il tempo di esecuzioneMeasure-Command { Get-Process }
Start-TranscriptAvvia registrazione della sessioneStart-Transcript -Path log.txt
Stop-TranscriptFerma registrazioneStop-Transcript

Leave a Reply

Your email address will not be published. Required fields are marked *