Trucs¶
Ouvrir Windows Terminal en 3 panneaux:¶
wt -p "Debian" `; split-pane -p "PowerShell 7" `; split-pane -p "Invite de commandes"
Ouvrir en 3 onglets dans Windows Terminal:¶
wt -p "Debian" `; new-tab -p "PowerShell 7" `; new-tab -p "Invite de commandes"
Palette de commande:¶
Ctrl + Shift + P
Thèmes:¶
https://docs.microsoft.com/en-us/windows/terminal/tutorials/powerline-setup
Ne pas afficher de messages au lancement de PowerShell:¶
Lancer avec l'option --nolog: powerShell.exe --nolog
Ouvrir une nouvelle fenêtre Powershell en administrateur:¶
1.
Start-Process powershell -Verb runAs
https://stackoverflow.com/questions/7690994/running-a-command-as-administrator-using-powershell
2.
Win + Ctrl + Maj + 8
Si Powershell est en 8e position dans la barre des taches (le 1er étant l'Explorateur).
3.
# ouvre une nouvelle fenêtre de Windows Terminal en mode admin.
powershell "Start-Process -Verb RunAs cmd.exe '/c start wt.exe'"
4.
Installation:
choco install gsudo
winget install gsudo
# Dans PowerShell ou l'invite de commande:
# donne les droits admin à la console courante
gsudo
❯ 'Hello World' | Get-Member
   TypeName: System.String
Name                 MemberType            Definition
----                 ----------            ----------
Clone                Method                System.Object Clone(), System.Object ICloneable.Clone()
CompareTo            Method                int CompareTo(System.Object value), int CompareTo(string strB), int IComparable.CompareTo(System.Object obj), int IComparable[string].CompareTo(strin…
Contains             Method                bool Contains(string value), bool Contains(string value, System.StringComparison comparisonType), bool Contains(char value), bool Contains(char value…
CopyTo               Method                void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)
EndsWith             Method                bool EndsWith(string value), bool EndsWith(string value, System.StringComparison comparisonType), bool EndsWith(string value, bool ignoreCase, cultur…
EnumerateRunes       Method                System.Text.StringRuneEnumerator EnumerateRunes()
Equals               Method                bool Equals(System.Object obj), bool Equals(string value), bool Equals(string value, System.StringComparison comparisonType), bool IEquatable[string]…
GetEnumerator        Method                System.CharEnumerator GetEnumerator(), System.Collections.IEnumerator IEnumerable.GetEnumerator(), System.Collections.Generic.IEnumerator[char] IEnum…
GetHashCode          Method                int GetHashCode(), int GetHashCode(System.StringComparison comparisonType)
GetPinnableReference Method                System.Char&, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e GetPinnableReference()
GetType              Method                type GetType()
.../...
❯ 'Hello World'.ToLower()
hello world
❯ ping google.com
PING google.com (216.58.215.46): 56 data bytes
64 bytes from 216.58.215.46: icmp_seq=0 ttl=112 time=60.009 ms
64 bytes from 216.58.215.46: icmp_seq=1 ttl=112 time=156.384 ms
Request timeout for icmp_seq 2
64 bytes from 216.58.215.46: icmp_seq=3 ttl=112 time=131.664 ms
64 bytes from 216.58.215.46: icmp_seq=4 ttl=112 time=143.645 ms
64 bytes from 216.58.215.46: icmp_seq=5 ttl=112 time=77.214 ms
64 bytes from 216.58.215.46: icmp_seq=6 ttl=112 time=64.536 ms
64 bytes from 216.58.215.46: icmp_seq=7 ttl=112 time=64.478 ms
64 bytes from 216.58.215.46: icmp_seq=8 ttl=112 time=67.211 ms
64 bytes from 216.58.215.46: icmp_seq=9 ttl=112 time=62.654 ms
64 bytes from 216.58.215.46: icmp_seq=10 ttl=112 time=73.045 ms
^C
--- google.com ping statistics ---
11 packets transmitted, 10 packets received, 9.1% packet loss
round-trip min/avg/max/stddev = 60.009/90.084/156.384/35.969 ms
❯ Test-Connection google.com
   Destination: google.com
Ping Source           Address                   Latency BufferSize Status
                                                   (ms)        (B)
---- ------           -------                   ------- ---------- ------
   1 SilverBook.local 216.58.215.46                  77         32 Success
   2 SilverBook.local 216.58.215.46                  56         32 Success
   3 SilverBook.local 216.58.215.46                  75         32 Success
   4 SilverBook.local 216.58.215.46                  67         32 Success
❯ Get-Help Test-Connection
NAME
    Test-Connection
SYNTAX
    Test-Connection [-TargetName] <string[]> [-Ping] [-IPv4] [-IPv6] [-ResolveDestination] [-Source <string>] [-MaxHops <int>] [-Count <int>] [-Delay <int>] [-BufferSize <int>] [-DontFragment] [-TimeoutSeconds <int>] [-Quiet] [<CommonParameters>]
        Test-Connection [-TargetName] <string[]> -Traceroute [-IPv4] [-IPv6] [-ResolveDestination] [-Source <string>] [-MaxHops <int>] [-TimeoutSeconds <int>] [-Quiet] [<CommonParameters>]
        Test-Connection [-TargetName] <string[]> -MtuSize [-IPv4] [-IPv6] [-ResolveDestination] [-TimeoutSeconds <int>] [-Quiet] [<CommonParameters>]
        Test-Connection [-TargetName] <string[]> -TcpPort <int> [-IPv4] [-IPv6] [-ResolveDestination] [-Source <string>] [-TimeoutSeconds <int>] [-Quiet] [<CommonParameters>]
❯ [System.Collections.ArrayList]$testArray = @()
❯ $testArray.Add('yahoo.com') | Out-Null
❯ $testArray.Add('google.com') | Out-Null
❯ $testArray
google.com
yahoo.com
❯ Test-Connection -ComputerName $testArray
   Destination: google.com
Ping Source           Address                   Latency BufferSize Status
                                                   (ms)        (B)
---- ------           -------                   ------- ---------- ------
   1 SilverBook.local 172.217.18.206               3969         32 Success
   2 SilverBook.local 172.217.18.206                 60         32 Success
   3 SilverBook.local 172.217.18.206                 82         32 Success
   4 SilverBook.local 172.217.18.206                 62         32 Success
   Destination: yahoo.com
Ping Source           Address                   Latency BufferSize Status
                                                   (ms)        (B)
---- ------           -------                   ------- ---------- ------
   1 SilverBook.local 98.138.219.231               2068         32 Success
   2 SilverBook.local 98.138.219.231                208         32 Success
   3 SilverBook.local 98.138.219.231                312         32 Success
   4 SilverBook.local 98.138.219.231                204         32 Success
Comparer 2 fichiers texte:
❯ compare-object (get-content one.txt) (get-content two.txt)
Bash <-> PowerShell:
| Bash | PowerShell | Alias | 
|---|---|---|
| pwd | Get-Location | pwd, gl | 
| cd | Set-Location | cd, sl, chdir | 
| ls | Get-ChildItem | ls, dir | 
| ls -ltr | Get-ChildItem $env:USERPROFILE\Desktop | Sort-Object -Property LastWriteTime | |
| find | Get-ChildItem | |
| find . -type f -iname "azure" | Get-ChildItem -Filter "*azure*" -Recurse -File | |
| cp | Copy-Item | cp, copy, cpi | 
| cp -R Tools ~/ | Copy-Item -Path '.\Tools\' -Destination $env:USERPROFILE -Recurse | |
| Copy-Item '.\Tools\' $env:USERPROFILE -Recurse | ||
| rm | Remove-Item | rm, ri, rmdir, rd, del | 
| rm -rf | Remove-Item -Recurse -Force | |
| mkdir | New-Item -ItemType Directory -Name 'MyNewFolder' | |
| touch | New-Item | |
| touch newFile{1..3} | 1..3 | ForEach-Object | |
| cat | Get-Content | cat, gc, type | 
| tail -n7 ./MyFile1 | Get-Content -Tail 7 .\MyFile1 | |
| tail -f ./log1 | Get-Content -Wait .\log1 | |
| uname -a | \$Properties = 'Caption', 'CSName', 'Version', 'BuildType', 'OSArchitecture' Get-CimInstance Win32_OperatingSystem | Select-Object $Properties | Format-Table -AutoSize | |
| ping | Test-Connection | |
| Test-Connection google.com | Format-Table -AutoSize | ||
| man | Get-Help | |
| Get-Help Stop-Service -Full | ||
| cut | Get-ChildItem $env:USERPROFILE\Desktop -Filter "*.ps1" | >> Select-Object -Property 'Name', 'Length' | |
Réinitialiser Windows Store¶
1ere solution:
PS> PowerShell -ExecutionPolicy Unrestricted $manifest = (Get-AppxPackage Microsoft.WindowsStore).InstallLocation + ‘\AppxManifest.xml’ ; Add-AppxPackage -DisableDevelopmentMode -Register $manifest
2eme solution:
PS> sfc /scannow
puis reboot (fonctionne W11)
3eme solution:
DISM /Online /Cleanup-Image /ScanHealth
puis reboot
  
    
      Dernière mise à jour:
      September 15, 2021