PI Services

Le blog des collaborateurs de PI Services

Active Directory : Restaurer des objets de la corbeille sous 2008

Quand on a l'habitude d'utiliser la console Active Directory Administrative Center pour restaurer des objets AD et que l'on désire restaurer des objets AD sur un Active Directory sous Windows server 2008, on peut se sentir décontenancer.

Eh oui pas de console ADAC sur Windows Server 2008, bon alors on fait quoi ? Powershell !!!

Pour lister tous les objets de la corbeille :

# List All Deleted objects
$AllDeletedObjects = Get-ADObject -ldapFilter:"(msDS-LastKnownRDN=*)" –IncludeDeletedObjects -Properties *

Ensuite libre à vous de filtrer sur les types d'objets, nom et autres propriétés.

# List All Deleted Groups
$DeletedGroups = $AllDeletedObjects | Where {$_.ObjectClass -eq "group"}

Et enfin restaurer ce qui vous intéresse dans l'OU de destination qui convient (ici le groupe "GS-Office-E3" restaurer dans l'OU "RestaurationPlace")

$ToRestore = $DeletedGroups | Where {$_.Name -like "GS-Office-E3"}
$DeletedGroups | Restore-ADObject -TargetPath "OU=RestorationPlace,DC=Demo,DC=corp"

 

Powershell : Générateur de mot de passe

Vous en avez marre de chercher un nouveau mot de passe, ou vous devez générer des mots de passe pour u grand nombre d'utilisateur ?

Voici quelques lignes Powershell que vous pouvez utiliser dans une fonction ou  dans une boucle pour générer un mot de passe.

$TinyCharacters = "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"
$CapitalCharacters = "A",",B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"
$NumeralCharacters = "0","1","2","3","4","5","6","7","8","9"
$SpecialCharacters = "!","$","%","&","/","(",")","=","?","}","]","[","{","@","#","*","+"
$Password = $null

1..3 | ForEach-Object {
    $Password += Get-Random -Minimum 1 $TinyCharacters
    $Password += Get-Random -Minimum 1 $CapitalCharacters
    $Password += Get-Random -Minimum 1 $NumeralCharacters
    $Password += Get-Random -Minimum 1 $SpecialCharacters
    }
$Password

Ces quelques ligne vous permettront de générer un mot de passe de 12 caractères, pour un mot de passe plus long changez la valeur de 1..3 à 1..4 ou 1..5