====== Équivalent PowerShell et Batch ====== ===== Les attributs de fichiers ===== ==== Lire les attributs ==== **Batch**: attrib c:\intel\*.*\\ **PowerShell**: Get-ChildItem -Path c:\intel\\\ === Modifier les attributs ==== **Batch**:\\ Pour retirer l'attribut Read-only :attrib c:\intel\*.* -R\\ **PowerShell**:\\ Pour retirer l'attribut Read-only Get-ChildItem -Path c:\intel\ | ForEach-Object {$_.Attributes = "Archive"}\\ L'avantage est que si on veut modifier l'ensemble des fichiers dans un dossier et ces sous-dossiers, il suffit de le rendre récursif:Get-ChildItem -Path c:\intel\ -Recurse | ForEach-Object {$_.Attributes = "Archive"}\\ **Bonus**:\\ Sous PowerShell, si on veut connaître la liste de l'ensemble des attributs, il suffit de taper ceci: [enum]::GetNames("system.io.fileattributes") Voici l'ensembles des attributs: * ReadOnly * Hidden * System * Directory * Archive * Device * Normal * Temporary * SparseFile * ReparsePoint * Compressed * Offline * NotContentIndexed * Encrypted * IntegrityStream * NoScrubData ===== Lire cache DNS ===== **batch**: ipconfig /displaydns\\ **Powershell**: Get-DnsClientCache\\ ===== Nettoyer le cache DNS ===== **batch**: ipconfig /flushdns\\ **Powershell**: Clear-DnsClientCache\\ ===== DIR ===== Get-ChildItem -Recurse | Select-Object -ExpandProperty FullName gci -r | select -exp FullName Get-ChildItem -Recurse | ForEach-Object { $_.FullName } gci -r | % { $_.FullName } Get-ChildItem -Recurse | ForEach-Object { $_.FullName } gci -r | % FullName ===== Ping ===== ==== Test-NetConnection ==== if (Test-Connection -TargetName Server01 -Quiet) { New-PSSession -ComputerName Server01 } ==== [System.Net.DNS] ==== [String]$ipAddress=192.168.1.100 [System.Net.DNS]::Resolve($ipAddress) ===== Echo ===== Write-Host **Argument :**\\ [[-Object] ] [-NoNewline]\\ [-Separator ] [-ForegroundColor ] [-BackgroundColor ] [] plus d'information : [[https://docs.microsoft.com/fr-fr/powershell/module/microsoft.powershell.utility/write-host?view=powershell-6]] ===== Mkdir ===== **Exemple:** créer le dossier "C:\Scripts\newDir" New-Item -ItemType directory -Path C:\Scripts\newDir plus d'information : [[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-item?view=powershell-6]] ===== Rmdir / Delete ===== **Exemple:** supprimer le dossier "C:\Scripts\newDir" Remove-Item -Force -Recurse -Path "C:\Scripts\newDir" Il est possible que le paramètre -Recurse ne suffit pas, il faudra se servir de la commande "Get-ChildItem" Get-ChildItem "C:\Scripts\newDir" -Recurse | Remove-Item -Force plus d'information : [[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/remove-item?view=powershell-6]]\\ [[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-6]]\\ ===== Help ===== Get-Help Exemple: get-help get-help NOM Get-Help SYNTAXE Get-Help [[-Name] ] [-Path ] [-Category {Alias | Cmdlet | Provider | General | FAQ | Glossary | HelpFile | ScriptCommand | Function | Filter | ExternalScript | All | DefaultHelp | Workflow}] [-Component ] [-Functionality ] [-Role ] [-Full] [] ALIAS Aucun(e) REMARQUES Get-Help ne parvient pas à trouver les fichiers d'aide de cette applet de commande sur cet ordinateur. Il ne trouve qu'une aide partielle. -- Pour télécharger et installer les fichiers d'aide du module comportant cette applet de commande, utilisez Update-Help. -- Pour afficher en ligne la rubrique d'aide de cette applet de commande, tapez : «Get-Help Get-Help -Online» ou accédez à http://go.microsoft.com/fwlink/?LinkID=113316. ===== Dism ===== L'ensemble des actions **[[:application:DISM|DISM]]** possèdent une équivalence en Powershell, Microsoft les a documenté ici: [[https://docs.microsoft.com/en-us/powershell/module/dism/?view=win10-ps]] ==== Drivers ==== === Export-Driver === Pour l'export sur le poste en cours\\ CMD : DISM.exe /Online /Export-Driver /Destination: PowerShell : Export-WindowsDriver -Online -Destination L'export sur une image montée\\ CMD : DISM.exe /image: /Export-Driver /Destination: PowerShell : Export-WindowsDriver -Path -Destination