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 [2024/11/04 15:46] – [Lancer un script Powershell à partir d'un Batch] yahikoinformatique:windows:powershell [2025/08/12 13:20] (current) yahiko
Line 111: Line 111:
 </code> </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>
 +
 +===== Groupes AD =====
 +==== Lister les groupes d'une OU ====
 +<code powershell>
 +Get-AdGroup -filter * -searchbase "OU=Groupes,OU=CLIENT,DC=DOMAINE,DC=LOCAL" | sort name | select name
 +</code>
 +
 +==== Lister les utilisateurs d'un groupe ====
 +<code powershell>
 +Get-ADGroupMember -Identity "Communication" | Format-Table Name, DistinguishedName
 +</code>
 +
 +===== Vérifier les droits NTFS d'un dossier =====
 +
 +Non récursif.
 +
 +<code powershell>
 +Get-NTFSAccess 'D:\DATA\partages\dossier'
 +
 +    Path: D:\DATA\partages\dossier (Inheritance enabled)
 +
 +
 +Account                             Access Rights  Applies to                Type           IsInherited   InheritedFrom
 +-------                             -------------  ----------                ----           -----------   -------------
 +BUILTIN\Administrateurs             FullControl    ThisFolderOnly            Allow          False
 +BUILTIN\Administrateurs             FullControl    ThisFolderSubfoldersAn... Allow          True          D:
 +AUTORITE NT\Système                 FullControl    ThisFolderSubfoldersAn... Allow          True          D:
 +CREATEUR PROPRIETAIRE               GenericAll     SubfoldersAndFilesOnly    Allow          True          D:
 +BUILTIN\Utilisateurs                ReadAndExec... ThisFolderSubfoldersAn... Allow          True          D:
 +BUILTIN\Utilisateurs                CreateDirec... ThisFolderAndSubfolders   Allow          True          D:
 +BUILTIN\Utilisateurs                CreateFiles    ThisFolderAndSubfolders   Allow          True          D:
 +</code>
 +
 +===== Lister les utilisateurs connectés en RDP =====
 +
 +<code powershell>
 +Get-CimInstance -ClassName Win32_UserProfile | where {-not $_.Special} | select LocalPath, LastUseTime, @{ Name = 'DaysSinceLastUse'; Expression = { if ($_.LastUseTime) { ((Get-Date) - $_.LastUseTime).Days } } }
 +</code>
 +
 +Source : https://www.reddit.com/r/sysadmin/comments/150qoo6/whats_the_best_way_to_verify_the_last_logged_in/
 +
 +
 +===== Uptime =====
 +
 +<code powershell>
 +(get-date) – (gcim Win32_OperatingSystem).LastBootUpTime
 +</code>
informatique/windows/powershell.1730735182.txt.gz · Last modified: 2024/11/04 15:46 by yahiko