Comment faire un split d’un Distinguished Name pour en extraire le nom des OU.
$dn = "CN=Groupe_Compta,OU=Groups,OU=Paris,OU=France,DC=domain,DC=local" |
Extraire la ville:
$dn.split(",")[2].split("=")[1] |
Extraire le pays:
$dn.split(",")[3].split("=")[1] |
J’ai ajouté PowerShell Community Extensions (PSCX) sur mon poste.
Disponible ici.
Il ajoute des commandes sympathique.
Il faut l’activer avec la commande:
Add-PSSnapin "pscx" |
Il est possible d’afficher la liste des cmdlets avec la commande:
Get-Command -CommandType Cmdlet | Where-Object { $_.HelpFile -eq "Pscx.dll-Help.xml" } |
Permet de supprimer rapidement une liste d’utilisateurs d’un groupe AD.
Import-Csv -Path .\remove-usersfromgroup.txt | Foreach {Remove-QADGroupMember -Identity "Le_Groupe" -Member $_.alias } |
Je me suis demandé à la création de http://aidexchange.fr si il ne valais pas mieux le créer en Anglais.
Bien que mon environnement de travail soit en anglais deux choses mon fait renoncer à cette idée.
- Mon anglais, car même si mon Français n’est pas terrible, mon anglais est encore pire.
- Le fait qu’il y ai trop peu de site à traiter les sujets qui nous concernent en Français.
En voici un nouveau que je ne soupçonnais pas.
- Apprendre le Français aux anglais.
Exchange French Community
Je suis très content de cette nouvelle utilité trouvée par Anderson Patricio.
Vérifie la présence d’un objet AD en faisant une recherche du DN et répond par « True » ou « False ».
[ADSI]::Exists("LDAP://CN=BLUTEAU Christophe,OU=Informatique,DC=domain,DC=local") |
Permet de traiter des chaines de cratères.
| Function | Description | Example |
| CompareTo() | Compares one string to another | (« Hello »).CompareTo(« Hello ») |
| Contains() | Returns « True » if a specified comparison string is in a string or if the comparison string is empty | (« Hello »).Contains(« ll ») |
| CopyTo() | Copies part of a string to another string | $a = (« Hello World »).toCharArray() (« User! »).CopyTo(0, $a, 6, 5) $a |
| EndsWith() | Tests whether the string ends with a specified string | (« Hello »).EndsWith(« lo ») |
| Equals() | Tests whether one string is identical to another string | (« Hello »).Equals($a) |
| IndexOf() | Returns the index of the first occurrence of a comparison string | (« Hello »).IndexOf(« l ») |
| IndexOfAny() | Returns the index of the first occurrence of any character in a comparison string | (« Hello »).IndexOfAny(« loe ») |
| Insert() | Inserts new string at a specified index in an existing string | (« Hello World »).Insert(6, « brave « ) |
| GetEnumerator() | Retrieves a new object that can enumerate all characters of a string | (« Hello »).GetEnumerator() |
| LastIndexOf() | Finds the index of the last occurrence of a specified character | (« Hello »).LastIndexOf(« l ») |
| LastIndexOfAny() | Finds the index of the last occurrence of any character of a specified string | (« Hello »).LastIndexOfAny(« loe ») |
| PadLeft() | Pads a string to a specified length and adds blank characters to the left (right-aligned string) | (« Hello »).PadLeft(10) |
| PadRight() | Pads string to a specified length and adds blank characters to the right (left-aligned string) | (« Hello »).PadRight(10) + « World! » |
| Remove() | Removes any requested number of characters starting from a specified position | (« Hello World »).Remove(5,6) |
| Replace() | Replaces a character with another character | (« Hello World »).Replace(« l », « x ») |
| Split() | Converts a string with specified splitting points into an array | (« Hello World »).Split(« l ») |
| StartsWith() | Tests whether a string begins with a specified character | (« Hello World »).StartsWith(« He ») |
| Substring() | Extracts characters from a string | (« Hello World »).Substring(4, 3) |
| ToCharArray() | Converts a string into a character array | (« Hello World »).toCharArray() |
| ToLower() | Converts a string to lowercase | (« Hello World »).toLower() |
| ToLowerInvariant() | Converts a string to lowercase using casing rules of the invariant language | (« Hello World »).toLowerInvariant() |
| ToUpper() | Converts a string to uppercase | (« Hello World »).toUpper() |
| ToUpperInvariant() | Converts a string to uppercase using casing rules of the invariant language | (« Hello World »).ToUpperInvariant() |
| Trim() | Removes blank characters to the right and left | ( » Hello « ).Trim() + « World » |
| TrimEnd() | Removes blank characters to the right | ( » Hello « ).TrimEnd() + « World » |
| TrimStart() | Removes blank characters to the left | ( » Hello « ).TrimStart() + « World » |
| Chars() | Provides a character at the specified position | (« Hello »).Chars(0) |
Un p’tit plaisir.
Au bon souvenir de la XFrX Team.
Export des MailContacts.
$resfile = New-Item -ItemType file -Path liste_external_contacts.csv -Force Add-Content -Path $resfile -Value "MailContactDisplayName,MailcontactAlias,MailcontactOrganizationalUnit,MailcontactExternalEmailAddress" Get-MailContact -ResultSize unlimited | ForEach-Object { Add-Content -Path $resfile -Value "$($_.DisplayName),$($_.alias),$($_.OrganizationalUnit),$($_.ExternalEmailAddress)" } |
