I'm in need of a little help. I've got little to no PowerShell experience but I'm working with a Pocket Guide by my side and my GoogleFu.
Currently, my plan is to prompt for a username and store it, use Get-ADUser with the stored username to get and store the DistinguishedName, use Move-ADObject to move the user from the DistinguishedName to the target path.
The problem I'm encountering is storing and calling these things. I have this, which gives me the info on a user. How can I isolate just the distinguished name and store it?
$name = read-host "Enter user name"
Get-ADUser $name
After storing the DN, can Move-ADObject use the stored value? I've attempted to store individual values like:
Move-ADobject 'CN=$name,OU=department,OU=company,DC=Domain,DC=net' -TargetPath 'OU=NonActive,OU=company,DC=Domain,DC=net'
But this returns "Directory object not found" as it doesn't use the stored value.
Cmdlet. Move-Item cmdlet is used to move a directory by passing the path of the directory to be moved and destination path where the folder is to be moved.
Try this:
Get-ADUser $name| Move-ADObject -TargetPath 'OU=nonactive,OU=compny,DC=domain,Dc=net'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With