OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Powershell : Move-ADObject : The operation could not be performed because the object's parent is either uninstantiated or deleted

  • Thread starter Thread starter PetiteFlamme31
  • Start date Start date
P

PetiteFlamme31

Guest
i've a problem with a script in Powershell...

I want to transfer users from an OU (parent OU : "IT" for exemple) to a "child OU" => "Users". ("IT">"Users").

Problem :

Code:
$name = "CN=Michael Allen,OU=IT,DC=Adatum,DC=com" 
Move-ADObject "CN=Michael Allen,OU=IT,DC=Adatum,DC=com" -TargetPath "OU=IT,OU=Users,DC=Adatum,DC=com"
Move-ADObject : The operation could not be performed because the object's parent is either 
uninstantiated or deleted
At line:5 char:1
+ Move-ADObject "CN=Michael Allen,OU=IT,DC=Adatum,DC=com" -TargetPath "OU=IT,OU=Us ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (CN=Michael Allen,OU=IT,DC=Adatum,DC=com:ADObject) [Move-AD 
   Object], ADException
    + FullyQualifiedErrorId : ActiveDirectoryServer:8329,Microsoft.ActiveDirectory.Management.Commands. 
   MoveADObject

My code :

Code:
$root = [ADSI]"LDAP://RootDSE"
$DOMAIN = $root.Get("rootDomainNamingContext")

#Informations serveur & domaine (Ex. : SERVER='LON-DC' / DOMAIN='DC=Adatum,DC=com')"
$SERVER = (Get-WmiObject Win32_ComputerSystem).Name
$root = [ADSI]"LDAP://RootDSE"
$DOMAIN = $root.Get("rootDomainNamingContext")

#Sous OU des OU parentes
$CHILD_OU1 = "Users"
$CHILD_OU2 = "Computers"
$CHILD_OU3 = "Groups"

#Pour chaque sous-OUs "Users", on récupère les utilisateurs des OU parent du fichier texte défini et on les transferts
foreach ($PARENT_OU in $OU_FILE) {
    #Récupération de la liste des utilisateurs de l'OU parente
    $users = Get-ADUser -Filter * -SearchBase "OU=$PARENT_OU,$DOMAIN"
    #Write-Host "Liste d'utilisateurs pour : $PARENT_OU : [$users]"

    #Pour chaque utilisateurs de la liste dans l'OU parente, on le transfert dans l'OU enfante "Users"
    foreach ($user in $users) {
    Write-Host "Utilisateur pour le transfert : $user"
    Write-Host "OU parente : $PARENT_OU"
    Write-Host "OU enfante : $CHILD_OU1"
    Move-ADObject -Identity "$user" -Server $SERVER -TargetPath "OU=$PARENT_OU,OU=$CHILD_OU1,$DOMAIN"
    }

}

I'm french and I try lot of time to do this script but I can't understand... Can somone help could help me please ?

Thanks.
<p>i've a problem with a script in Powershell...</p>

<p>I want to transfer users from an OU (parent OU : "IT" for exemple) to a "child OU" => "Users". ("IT">"Users").</p>

<p><strong>Problem</strong> : </p>

<pre><code>$name = "CN=Michael Allen,OU=IT,DC=Adatum,DC=com"
Move-ADObject "CN=Michael Allen,OU=IT,DC=Adatum,DC=com" -TargetPath "OU=IT,OU=Users,DC=Adatum,DC=com"
Move-ADObject : The operation could not be performed because the object's parent is either
uninstantiated or deleted
At line:5 char:1
+ Move-ADObject "CN=Michael Allen,OU=IT,DC=Adatum,DC=com" -TargetPath "OU=IT,OU=Us ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CN=Michael Allen,OU=IT,DC=Adatum,DC=com:ADObject) [Move-AD
Object], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8329,Microsoft.ActiveDirectory.Management.Commands.
MoveADObject
</code></pre>

<p><strong>My code</strong> :</p>

<pre><code>$root = [ADSI]"LDAP://RootDSE"
$DOMAIN = $root.Get("rootDomainNamingContext")

#Informations serveur & domaine (Ex. : SERVER='LON-DC' / DOMAIN='DC=Adatum,DC=com')"
$SERVER = (Get-WmiObject Win32_ComputerSystem).Name
$root = [ADSI]"LDAP://RootDSE"
$DOMAIN = $root.Get("rootDomainNamingContext")

#Sous OU des OU parentes
$CHILD_OU1 = "Users"
$CHILD_OU2 = "Computers"
$CHILD_OU3 = "Groups"

#Pour chaque sous-OUs "Users", on récupère les utilisateurs des OU parent du fichier texte défini et on les transferts
foreach ($PARENT_OU in $OU_FILE) {
#Récupération de la liste des utilisateurs de l'OU parente
$users = Get-ADUser -Filter * -SearchBase "OU=$PARENT_OU,$DOMAIN"
#Write-Host "Liste d'utilisateurs pour : $PARENT_OU : [$users]"

#Pour chaque utilisateurs de la liste dans l'OU parente, on le transfert dans l'OU enfante "Users"
foreach ($user in $users) {
Write-Host "Utilisateur pour le transfert : $user"
Write-Host "OU parente : $PARENT_OU"
Write-Host "OU enfante : $CHILD_OU1"
Move-ADObject -Identity "$user" -Server $SERVER -TargetPath "OU=$PARENT_OU,OU=$CHILD_OU1,$DOMAIN"
}

}
</code></pre>

<p>I'm french and I try lot of time to do this script but I can't understand... Can somone help could help me please ?</p>

<p>Thanks.</p>
Continue reading...
 
Top