# Commandes PowerShell #### Afficher le contenu du répertoire: ```powershell PS Get-ChildItem Répertoire : C:\Users\enzo2 Mode LastWriteTime Length Name d----- 12/04/2020 11:53 .config d----- 04/04/2020 09:38 .dotnet d----- 27/03/2020 21:12 .PyCharm2019.3 d ``` #### Changer de répertoire: ```powershell PS Set-Location "C:\" PS ls Répertoire : C:\ ``` ```powershell PS Set-Location "C:\WINDOWS\system32" ``` ```powershell PS D: PS ls Répertoire : D:\ ``` #### Piper une commande vers wsl: ```powershell PS Get-ChildItem | wsl grep .g* -a---- 02/04/2020 12:13 318 .gitconfig ``` ```powershell PS ipconfig | wsl grep IPv4 Adresse IPv4. . . . . . . . . . . . . .: 172.18.96.1 Adresse IPv4. . . . . . . . . . . . . .: 192.168.1.17 Adresse IPv4. . . . . . . . . . . . . .: 192.168.32.1 Adresse IPv4. . . . . . . . . . . . . .: 192.168.61.1 Adresse IPv4. . . . . . . . . . . . . .: 172.27.144.1 ``` #### Piper une commande depuis wsl: ```powershell PS wsl ls -la | Select-Object -First 5 total 1645992 drwxrwxrwx 1 enzo2 enzo2 512 Apr 13 15:08 . drwxrwxrwx 1 enzo2 enzo2 512 Mar 28 17:59 .. drwxrwxrwx 1 enzo2 enzo2 512 Mar 28 18:09 3D Objects drwxrwxrwx 1 enzo2 enzo2 512 Mar 28 18:07 AppData ``` #### Liste des commandes: ```powershell PS Get-Command CommandType Name Version Source ----------- ---- ------- ------ Alias Add-AppPackage 2.0.1.0 Appx Alias Add-AppPackageVolume 2.0.1.0 Appx .../... ``` ```powershell PS Get-Command -Name *IP* CommandType Name Version Source ----------- ---- ------- ------ Alias gip -> 1.0.0.0 NetTCPIP Alias ipal -> Import-Alias ``` #### Obtenir de l'aide: ```powershell PS Get-Help -Name Get-Process NOM Get-Process SYNTAXE Get-Process [[-Name] ] [] Get-Process [[-Name] ] [] Get-Process [] Get-Process [] Get-Process [] Get-Process [] ALIAS gps ps ``` #### Liste de Services: ```powershell PS Get-Service Status Name DisplayName ------ ---- ----------- Stopped AarSvc_6e14a Agent Activation Runtime_6e14a Running AdobeARMservice Adobe Acrobat Update Service Stopped AJRouter Service de routeur AllJoyn Stopped ALG Service de la passerelle de la couc... Running AMD External Ev... AMD External Events Utility ``` #### Uniquement les Services actifs: ```powershell PS Get-Service | Where-Object {$_.Status -eq "Running"} Status Name DisplayName ------ ---- ----------- Running AdobeARMservice Adobe Acrobat Update Service Running AMD External Ev... AMD External Events Utility Running Appinfo Informations d’application ``` #### Sortie HTML: ```powershell PS Get-Service | Where-Object {$_.Status -eq "Running"} | ConvertTo-Html | Out-File Services.html ``` #### Sortie .csv: ```powershell PS Get-Service | Where-Object {$_.Status -eq "Running"} | Select-Object Name, Status | Export-CSV Service.csv ``` #### Voir les erreurs dans les logs event: ```powershell PS Get-EventLog -LogName System -EntryType Error Index Time EntryType Source InstanceID Message ----- ---- --------- ------ ---------- ------- 11071 mai 01 09:40 Error volsnap 3221618724 Les clichés instantanés du volume C: ont été an... 10981 avr. 29 19:55 Error volsnap 3221618724 Les clichés instantanés du volume C: ont été an... 10833 avr. 28 07:30 Error volsnap 3221618724 Les clichés instantanés du volume C: ont été an... 10774 avr. 28 07:25 Error bowser 3221233475 Le maître explorateur a reçu une annonce de ser... 10766 avr. 28 07:22 Error Schannel 36871 Une erreur irrécupérable s'est produite lors de... ```