Queste non sono altre che le mie note personali su Powershell di Windows condivise per chi ne potrebbe aver bisogno. Non hanno ancora un ordine ben preciso. Le scrivo man mano che le scopro e ritengo di doverle inserire qui.
CANCELLA FILE
Cancella tutti i file presenti nella cartella Owncloud e sotto cartella.
Get-ChildItem ... -Recurse รจ come una dir /s. Il suo output viene rediretto al comado Remove-Item.
PS C:\ownCloud> Get-ChildItem -Path "C:\ownCloud" -Filter "*(conflicted copy 202*.lnk" -Recurse | Remove-Item -Force
PS C:\ownCloud> Get-ChildItem -Path "C:\ownCloud" -Filter "__pycache__" -Recurse | Remove-Item -Force -Recurse
MISURARE IL TEMPO DI ESECUZIONE
# Misuriamo il tempo di recupero help massivo per tutte le 'q.*'
Measure-Command { $allHelp = Get-Help q.* } | Select-Object TotalSeconds
TotalSeconds
------------
0,18
VISUALIZZA LA VERSIONE DI UN ESEGUIBILE
PS C:\Owncloud\Appx\Disk\WinRARPortable\App> $file = "C:\Owncloud\Appx\Disk\WinRARPortable\App\WinRAR-x64\WinRAR.exe"
PS C:\Owncloud\Appx\Disk\WinRARPortable\App> (Get-Item $file).VersionInfo | Select-Object FileDescription, ProductVersion, FileVersion, ProductMajorPart | Format-List
FileDescription : Gestione archivi WinRAR
ProductVersion : 7.20.0
FileVersion : 7.20.0
ProductMajorPart : 7
RICERCA UN TESTO
Get-ChildItem -Path "C:\MyScript" -Filter *.ps1 -Recurse | Select-String "Set-PSReadLineKeyHandler"
LISTA TASTI
Get-PSReadLineKeyHandler
IMPOSTA IL TASTO TAB
# Imposta Tab - Menu Completo
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
# Imposta Tab - Rotazione Comandi
Set-PSReadLineKeyHandler -Key Tab -Function TabComplete
LEGGE LA VERSIONE DA UN PROGRAMMA EXE
$file = "C:\Owncloud\Appx\Disk\WinRARPortable\App\WinRAR-x64\WinRAR.exe"
(Get-Item $file).VersionInfo | Select-Object FileDescription, ProductVersion, FileVersion, ProductMajorPart | Format-List
MOSTRA CONNESSIONI SMB
Get-SmbConnection | Select-Object ServerName, ShareName, UserName
ServerName ShareName UserName
---------- --------- --------
ServerXYZ CondivisioneKZY MIOPC\UTENTECORRENTE
VISUALIZZA VARIABILI, FUNZIONI
# Variabili
Get-ChildItem Variable:\
# Funzioni
Get-ChildItem Function:\
# Funzioni che iniziano per q. Get-ChildItem Function:\q.*
# Visualizza Variabili Globali
Get-Variable -Scope Global
VISUALIZZA TUTTI I PROFILI
$profile | Select-Object *
| Nome | Descrizione | Percorso Tipico |
| CurrentUserCurrentHost | Il "tuo" profilo standard | ...\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 |
| CurrentUserAllHosts | Per tutti i terminali (anche VSCode) | ...\Documents\PowerShell\profile.ps1 |
| AllUsersCurrentHost | Per tutti gli utenti del PC | ...\PowerShell\Microsoft.PowerShell_profile.ps1 |
| AllUsersAllHosts | Globale assoluto | ...\PowerShell\profile.ps1 |
- have fun -
