modifier un élément dans les comptes user d'une OU
Bonsoir je débute en powershell. Je voudrais l'utiliser pour m'aider à administrer l'AD. je recherche un script pour modifier un élément dans tous les comptes user d'une OU.
Je fais la même chose avec les comptes ordinateur mais je n'arrive à le faire que pour un seul
Code:
1 2 3 4 5
| $ordinateur = [ADSI]'LDAP://CN=UC123456789,CN=ordinateurs,DC=momo,DC=fr'
$ordinateur.PutEx(1, 'Description' ,$null)
$ordinateur.SetInfo() |
J'essaye en passant par un fichier text mais ca ne fonctionne pas:
1 script :
Code:
1 2 3 4
| $strCategory = “computer”
$objDomain = New-Object System.DirectoryServices.DirectoryEntry(“LDAP://OU=ordinateurs,dc=momo,dc=fr”)
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher($objDomain,”(objectCategory=$strCategory)”,@(‘name’))
$objSearcher.FindAll() | %{$_.properties.name} | out-file C:\computersList.txt |
2script de modification :
Code:
1 2 3 4 5 6 7 8 9
| $EmplacementFichier = "c:\computersList.txt"
$MonFichier = get-content $EmplacementFichier
foreach ($UneLigne in $MonFichier){
$ordinateur = [ADSI]'LDAP://cn=$UneLigne,OU=ordinateurs,DC=momo,DC=fr'
$ordinateur.PutEx(1, 'Description',$null)
$ordinateur.SetInfo()
} |
erreur :
L'exception suivante s'est produite lors de la récupération du membre «*SetInfo*»*: «*Cet objet ne se trouve pas sur le
serveur.
*»
Au niveau de C:\test2.ps1*: 14 Caractère*: 20
+ $ordinateur.SetInfo <<<< ()
+ CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemException
+ FullyQualifiedErrorId : CatchFromBaseGetMember
Merci par avance.