powershell - How can I clone a GroupOfNames Active Directory Object? -
i'm writing script take 1 groupofnames
object , create second group first groups members. seems simple piece of code:
$obj = get-adobject -server "$server" -searchbase $searchbase -filter "name -eq '$groupname'" -properties member new-adobject -server "$server" -path $searchbase -type 'groupofnames' -name "$newgroupname" -otherattributes @{'member'= ($($obj.member))}
when run $obj gets created , can display both groupofnames
information, list of members. when calls new-adobject
cmdlet, following error:
new-adobject : unable contact server. may because server not exist, down, or not have active directory web services running.
i've tried multiple variations of code , fail similar errors.
interestingly, if loop through list of members , add them group 1 @ time, works, takes way long (an hour+ vs seconds).
try this, casts results of first query, adpropertyvaluecollection
, string array(untested!):
$obj = get-adobject -server "$server" -searchbase $searchbase -filter "name -eq '$groupname'" -properties member $m = [string[]]$obj.member new-adobject -server "$server" -path $searchbase -type 'groupofnames' -name "$newgroupname" -otherattributes @{'member'= $m}
Comments
Post a Comment