User Tools

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
Next revisionBoth sides next revision
informatique:windows:powershell [2020/02/28 09:42] – external edit 127.0.0.1informatique:windows:powershell [2022/06/10 12:41] yahiko
Line 1: Line 1:
 ====== Powershell ====== ====== Powershell ======
 [[informatique:windows:powershell:excel-separer-feuilles|Excel : séparer les feuilles dans des fichiers]] [[informatique:windows:powershell:excel-separer-feuilles|Excel : séparer les feuilles dans des fichiers]]
 +
 +===== Autoriser l'exécution des scripts : =====
 +<codedoc code:powershell>
 +set-executionpolicy remotesigned
 +</codedoc>
 +
 +===== Lancer un script Powershell à partir d'un Batch =====
 +<codedoc code:batch>
 +Powershell.exe -executionpolicy remotesigned -File NOMDUSCRIPT.ps1
 +</codedoc>
 +
 +===== Lancer un script Powershell à partir d'un chemin UNC =====
 +Attention, c'est très sale : 
 +<codedoc code:batch>
 +Powershell.exe -NoProfile -ExecutionPolicy bypass -File "\\IP_DU_SERVEUR\OU\EST\LE\script.ps1"
 +</codedoc>
 +Source : [[https://superuser.com/questions/106360/how-to-enable-execution-of-powershell-scripts]]
 +
 +===== Tester la présence d'un dossier =====
 +<codedoc code:powershell>
 +$dossier = "%userprofile%\path\le\chien"
 +
 +if (Test-Path -Path $dossier) {
 + "Le dossier $dossier !"
 +} else {
 +    "Création du dossier $dossier"
 + mkdir $dossier
 +}
 +</codedoc>
 +
 +===== Télécharger un fichier =====
 +<codedoc code:powershell>
 +$url = http://url_du_fichier
 +
 +Invoke-WebRequest -Uri $url -OutFile C:\Ou\va\le\fichier\fichier.prout
 +</codedoc>
 +
 +===== Créer un raccourci =====
 +<codedoc code:powershell>
 +$WshShell = New-Object -ComObject WScript.Shell
 +$Shortcut = $WshShell.CreateShortcut("$env:PUBLIC\Desktop\Machin.lnk")
 +$Shortcut.TargetPath = "C:\ou\est\le\fichier\Machin.exe"
 +$Shortcut.Save()
 +</codedoc>
 +
 +===== Créer plusieurs comptes / activer =====
 +<codedoc code:powershell>
 +# On met les comptes dans un tableau
 +$comptes = @("utilisateur","toto","Administrateur")
 +ForEach ($compte in $comptes)
 +{
 +    $op = Get-LocalUser | Where-Object {$_.Name -eq $compte}
 +    if ( -not $op) {
 +        "Création du compte $compte..."
 +        $password = Read-Host "Saisir le mot de passe du compte $compte (rien si pas de mot de passe)" -AsSecureString
 +        New-LocalUser -Name $compte -Password $password -AccountNeverExpires -UserMayNotChangePassword
 +        Add-LocalGroupMember -Group "Administrateurs" -Member $compte
 +    } else {
 +        "Le compte $compte existe déjà"
 +        if ((Get-LocalUser $compte).Enabled) {
 +            "Le compte $compte est déjà activé"
 +        } else {
 +            "Activation du compte $compte..."
 +            Enable-LocalUser -Name $compte
 +            "Le compte $compte est activé"
 +        }
 +    }
 +}
 +Set-LocalUser -Name 'Toto' -FullName "Jean-Michel Toto"
 +</codedoc>
 +
 +===== Désactiver et activer des trucs =====
 +<codedoc code:powershell>
 +# Désactiver UAC
 +New-ItemProperty -Path HKLM:Software\Microsoft\Windows\CurrentVersion\policies\system -Name EnableLUA -PropertyType DWord -Value 0 -Force
 +
 +# Désactiver pare-feu sur tous les profils
 +Set-NetFirewallProfile -Profile * -Enabled False
 +
 +# Désactivation smart-screen
 +Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer" -Name "SmartScreenEnabled" -Type String -Value "Off"
 +Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\AppHost" -Name "EnableWebContentEvaluation" -Type DWord -Value
 +
 +# Désactivation OOBE
 +Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\OOBE" -Name "DisablePrivacyExperience" -Type DWORD -Value 1 -Force
 +Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\OOBE" -Name "PrivacyConstentStatus" -Type DWORD -Value 1 -Force
 +Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\OOBE" -Name "SkipMachineOOBE" -Type DWORD -Value 1 -Force
 +
 +# Activation client SMBv1
 +Enable-WindowsOptionalFeature -Online -FeatureName "SMB1Protocol-Client" -All
 +
 +# Installation de .NET3.5
 +Enable-WindowsOptionalFeature -Online -FeatureName "NetFx3"
 +</codedoc>
 +
 +===== Intégrer un poste à un domaine =====
 +<codedoc code:powershell>
 +Add-Computer -DomainName DOMAINE.LOCAL -Credential DOMAINE\administrateur -Restart -Force
 +</codedoc>
 +
 +===== Récupérer le GUID des volumes =====
 +<codedoc code:powershell>
 +GWMI -namespace root\cimv2 -class win32_volume | FL -property DriveLetter, DeviceID
 +</codedoc>
 +
  
informatique/windows/powershell.txt · Last modified: 2023/09/14 08:45 by yahiko

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki