Site Tools


informatique:windows:powershell

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
informatique:windows:powershell [2022/03/04 14:34] yahikoinformatique:windows:powershell [2025/01/23 14:58] (current) yahiko
Line 3: Line 3:
  
 ===== Autoriser l'exécution des scripts : ===== ===== Autoriser l'exécution des scripts : =====
-<codedoc code:powershell>+<code powershell>
 set-executionpolicy remotesigned set-executionpolicy remotesigned
-</codedoc>+</code>
  
 ===== Lancer un script Powershell à partir d'un Batch ===== ===== Lancer un script Powershell à partir d'un Batch =====
-<codedoc code:batch>+<code code:batch>
 Powershell.exe -executionpolicy remotesigned -File NOMDUSCRIPT.ps1 Powershell.exe -executionpolicy remotesigned -File NOMDUSCRIPT.ps1
-</codedoc>+</code>
  
 ===== Lancer un script Powershell à partir d'un chemin UNC ===== ===== Lancer un script Powershell à partir d'un chemin UNC =====
 Attention, c'est très sale :  Attention, c'est très sale : 
-<codedoc code:batch>+<code batch>
 Powershell.exe -NoProfile -ExecutionPolicy bypass -File "\\IP_DU_SERVEUR\OU\EST\LE\script.ps1" Powershell.exe -NoProfile -ExecutionPolicy bypass -File "\\IP_DU_SERVEUR\OU\EST\LE\script.ps1"
-</codedoc>+</code>
 Source : [[https://superuser.com/questions/106360/how-to-enable-execution-of-powershell-scripts]] Source : [[https://superuser.com/questions/106360/how-to-enable-execution-of-powershell-scripts]]
  
 ===== Tester la présence d'un dossier ===== ===== Tester la présence d'un dossier =====
-<codedoc code:powershell>+<code powershell>
 $dossier = "%userprofile%\path\le\chien" $dossier = "%userprofile%\path\le\chien"
  
Line 29: Line 29:
  mkdir $dossier  mkdir $dossier
 } }
-</codedoc>+</code>
  
 ===== Télécharger un fichier ===== ===== Télécharger un fichier =====
-<codedoc code:powershell>+<code powershell>
 $url = http://url_du_fichier $url = http://url_du_fichier
  
 Invoke-WebRequest -Uri $url -OutFile C:\Ou\va\le\fichier\fichier.prout Invoke-WebRequest -Uri $url -OutFile C:\Ou\va\le\fichier\fichier.prout
-</codedoc>+</code>
  
 ===== Créer un raccourci ===== ===== Créer un raccourci =====
-<codedoc code:powershell>+<code powershell>
 $WshShell = New-Object -ComObject WScript.Shell $WshShell = New-Object -ComObject WScript.Shell
 $Shortcut = $WshShell.CreateShortcut("$env:PUBLIC\Desktop\Machin.lnk") $Shortcut = $WshShell.CreateShortcut("$env:PUBLIC\Desktop\Machin.lnk")
 $Shortcut.TargetPath = "C:\ou\est\le\fichier\Machin.exe" $Shortcut.TargetPath = "C:\ou\est\le\fichier\Machin.exe"
 $Shortcut.Save() $Shortcut.Save()
-</codedoc>+</code>
  
 ===== Créer plusieurs comptes / activer ===== ===== Créer plusieurs comptes / activer =====
-<codedoc code:powershell>+<code powershell>
 # On met les comptes dans un tableau # On met les comptes dans un tableau
 $comptes = @("utilisateur","toto","Administrateur") $comptes = @("utilisateur","toto","Administrateur")
Line 70: Line 70:
 } }
 Set-LocalUser -Name 'Toto' -FullName "Jean-Michel Toto" Set-LocalUser -Name 'Toto' -FullName "Jean-Michel Toto"
-</codedoc>+</code>
  
 ===== Désactiver et activer des trucs ===== ===== Désactiver et activer des trucs =====
-<codedoc code:powershell>+<code powershell>
 # Désactiver UAC # Désactiver UAC
 New-ItemProperty -Path HKLM:Software\Microsoft\Windows\CurrentVersion\policies\system -Name EnableLUA -PropertyType DWord -Value 0 -Force New-ItemProperty -Path HKLM:Software\Microsoft\Windows\CurrentVersion\policies\system -Name EnableLUA -PropertyType DWord -Value 0 -Force
Line 94: Line 94:
 # Installation de .NET3.5 # Installation de .NET3.5
 Enable-WindowsOptionalFeature -Online -FeatureName "NetFx3" Enable-WindowsOptionalFeature -Online -FeatureName "NetFx3"
-</codedoc>+</code>
  
 ===== Intégrer un poste à un domaine ===== ===== Intégrer un poste à un domaine =====
-<codedoc code:powershell>+<code powershell>
 Add-Computer -DomainName DOMAINE.LOCAL -Credential DOMAINE\administrateur -Restart -Force Add-Computer -DomainName DOMAINE.LOCAL -Credential DOMAINE\administrateur -Restart -Force
-</codedoc>+</code>
  
 +===== Récupérer le GUID des volumes =====
 +<code powershell>
 +GWMI -namespace root\cimv2 -class win32_volume | FL -property DriveLetter, DeviceID
 +</code>
 +
 +===== Exporter les utilisateurs d'un AD =====
 +<code powershell>
 +Get-ADUser -Filter * -Proerties * -SearchBase "OU=NOMDELOU,DC=DOMAINE,DC=TLD" | select displayname,UserPrincipalName | export-csv -path C:\informatique\users.csv
 +</code>
 +
 +===== Changer la casse d'une variable =====
 +
 +<code powershell>
 +# En majuscule
 +CHAINE.ToUpper()
 +
 +# En minuscule
 +CHAINE.ToLower()
 +</code>
 +
 +===== Remplacer un caractère ou un espace =====
 +
 +C'est pas beau.
 +
 +<code powershell>
 +# Un espace
 +$string = $string -replace " ",""
 +
 +# Un apostrophe
 +$string = $string -replace "'",""
 +</code>
 +
 +===== Lister les membres d'un groupe AD =====
 +<code powershell>
 +Get-ADGroupMember -Identity "Communication" | Format-Table Name, DistinguishedName
 +</code>
  
informatique/windows/powershell.1646404482.txt.gz · Last modified: 2022/03/04 14:34 by yahiko