Question
Modifier le commentaire serveur dans AD [Résolu]
- matthias
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
Réduire
Plus d'informations
- Messages : 4
- Remerciements reçus 0
il y a 17 ans 1 semaine #4282
par matthias
Modifier le commentaire serveur dans AD [Résolu] a été créé par matthias
Bonjour,
Je cherche à créer un script dans le but de modifier le commentaire du serveur dans active directory :
[code:1]param(
$computer = \"mon ordinateur\",
$comment = \"c'est un serveur virtuel\"
)
###########
###AD######
###########
#---Conenxion
Write-host AD $computer -backgroundcolor \"white\" -Foregroundcolor \"green\"
$requete = \"LDAP://MONDC/dc=mondomaine,dc=fr\"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry($requete)
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 10000
$strFilter = \"(&(objectCategory=computer)(objectClass=computer))\"
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = \"Subtree\"
$colProplist = \"name\",\"description\"
foreach ($i in $colPropList)
{
$objSearcher.PropertiesToLoad.Add($i)|out-null
}
$colResults = $objSearcher.FindAll()
#---Recherche
foreach($srv in $colResults)
{
if ($srv.Properties.name -eq $computer)
{
Write-Host \"Ancien commentaire: \" $srv.Properties.description -Foregroundcolor \"green\"
#---Mise à jour
#$srv.Properties.put(\"description\",$comment)
#---Vérification
Write-Host \"Nouveau commentaire: \" $srv.Properties.description -Foregroundcolor \"green\"
}
}[/code:1]
Le problème est que je n'arrive pas à envoyer l'information à jour dans AD :
[code:1]$srv.Properties.put(\"description\",$comment)[/code:1]
Si quelqu'un à une solution
Merci.<br><br>Message édité par: matthias, à: 10/03/09 13:54
Je cherche à créer un script dans le but de modifier le commentaire du serveur dans active directory :
[code:1]param(
$computer = \"mon ordinateur\",
$comment = \"c'est un serveur virtuel\"
)
###########
###AD######
###########
#---Conenxion
Write-host AD $computer -backgroundcolor \"white\" -Foregroundcolor \"green\"
$requete = \"LDAP://MONDC/dc=mondomaine,dc=fr\"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry($requete)
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 10000
$strFilter = \"(&(objectCategory=computer)(objectClass=computer))\"
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = \"Subtree\"
$colProplist = \"name\",\"description\"
foreach ($i in $colPropList)
{
$objSearcher.PropertiesToLoad.Add($i)|out-null
}
$colResults = $objSearcher.FindAll()
#---Recherche
foreach($srv in $colResults)
{
if ($srv.Properties.name -eq $computer)
{
Write-Host \"Ancien commentaire: \" $srv.Properties.description -Foregroundcolor \"green\"
#---Mise à jour
#$srv.Properties.put(\"description\",$comment)
#---Vérification
Write-Host \"Nouveau commentaire: \" $srv.Properties.description -Foregroundcolor \"green\"
}
}[/code:1]
Le problème est que je n'arrive pas à envoyer l'information à jour dans AD :
[code:1]$srv.Properties.put(\"description\",$comment)[/code:1]
Si quelqu'un à une solution
Merci.<br><br>Message édité par: matthias, à: 10/03/09 13:54
Connexion ou Créer un compte pour participer à la conversation.
- Laurent Dardenne
- Hors Ligne
- Modérateur
-
Réduire
Plus d'informations
- Messages : 6311
- Remerciements reçus 68
il y a 17 ans 1 semaine #4285
par Laurent Dardenne
Tutoriels PowerShell
Réponse de Laurent Dardenne sur le sujet Re:Modifier le commentaire serveur dans AD
Salut,
matthias écrit:
matthias écrit:
Il faut appeler la méthode Setinfo() , après la mise en cache des infos par le méthode Put.Le problème est que je n'arrive pas à envoyer l'information à jour dans AD :
Tutoriels PowerShell
Connexion ou Créer un compte pour participer à la conversation.
- matthias
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
Réduire
Plus d'informations
- Messages : 4
- Remerciements reçus 0
il y a 17 ans 1 semaine #4286
par matthias
Réponse de matthias sur le sujet Modifier le commentaire serveur dans AD [Résolu]
Merci pour ton aide, j'ai trouvé !
[code:1]
param(
$computer = \"mon ordinateur\",
$comment = \"c'est un serveur virtuel\"
)
###########
###AD######
###########
#---Conenxion
Write-host AD $computer -backgroundcolor \"white\" -Foregroundcolor \"green\"
$requete = \"LDAP://MONDC/dc=mondomaine,dc=fr\"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry($requete)
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 10000
$strFilter = \"(&(objectCategory=computer)(objectClass=computer))\"
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = \"Subtree\"
$colProplist = \"name\",\"description\"
foreach ($i in $colPropList)
{
$objSearcher.PropertiesToLoad.Add($i)|out-null
}
$colResults = $objSearcher.FindAll()
#---Recherche
foreach($srv in $colResults)
{
$resultcomputer = $srv.path
$objcomp = [ADSI]$resultcomputer
Write-Host \"Ancien commentaire: \" $srv.Properties.description -Foregroundcolor \"green\"
#---Mise à jour
$objcomp.put(\"Description\",$comment)
$objcomp.setinfo()
#---Vérification
Write-Host \"Nouveau commentaire: \" $srv.Properties.description -Foregroundcolor \"green\"
}[/code:1]
<br><br>Message édité par: matthias, à: 10/03/09 13:52
[code:1]
param(
$computer = \"mon ordinateur\",
$comment = \"c'est un serveur virtuel\"
)
###########
###AD######
###########
#---Conenxion
Write-host AD $computer -backgroundcolor \"white\" -Foregroundcolor \"green\"
$requete = \"LDAP://MONDC/dc=mondomaine,dc=fr\"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry($requete)
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 10000
$strFilter = \"(&(objectCategory=computer)(objectClass=computer))\"
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = \"Subtree\"
$colProplist = \"name\",\"description\"
foreach ($i in $colPropList)
{
$objSearcher.PropertiesToLoad.Add($i)|out-null
}
$colResults = $objSearcher.FindAll()
#---Recherche
foreach($srv in $colResults)
{
$resultcomputer = $srv.path
$objcomp = [ADSI]$resultcomputer
Write-Host \"Ancien commentaire: \" $srv.Properties.description -Foregroundcolor \"green\"
#---Mise à jour
$objcomp.put(\"Description\",$comment)
$objcomp.setinfo()
#---Vérification
Write-Host \"Nouveau commentaire: \" $srv.Properties.description -Foregroundcolor \"green\"
}[/code:1]
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.083 secondes
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Entraide pour les débutants
- Modifier le commentaire serveur dans AD [Résolu]