Stella inattivaStella inattivaStella inattivaStella inattivaStella inattiva
 

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

Oppure
$tempo = Measure-Command { q.Dsp365Delegates -View 1 }
Write-Host "Tempo impiegato: $($tempo.Minutes)m e $($tempo.Seconds)s" -ForegroundColor Yellow

 

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"

  

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



VISUALIZZA COMBINAZIONI DA TASTIERA 

# Elenco completo
Get-PSReadLineKeyHandler
# Filtrare per la parola indicata
Get-PSReadLineKeyHandler | Where-Object {$_.Key -like "*RightArrow*"}

  

IMPOSTA IL TASTO TAB

# Imposta Tab - Menu Completo
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
# Imposta Tab - Rotazione Comandi
Set-PSReadLineKeyHandler -Key Tab -Function TabComplete

 

IMPOSTA F2 ATTIVO ALL'AVVIO

Inserendo questo comando nel $profile sarà attivo per default

# F2, lista ULTIMA 10 comandi da history
Set-PSReadLineOption -PredictionViewStyle ListView

 

VISUALIZZA I MODULI INSTALLATI

 $env:PSModulePath

 

 

 

- have fun - 

*** WIP - Work In Progress ***

DISQUS - Leave your comments here