Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

using -Instance option of New-ADUser with existing user object not working as expected

$
0
0

so the help documentation states that a CIM instance, I believe, of a user object passed to the "-Instance" option of theNew-ADUser cmdlet should effectively use the referenced user object as a template for creating the new user, however:

I have not been able to successfully produce a user object in PowerShell that reproduces the same results as using the DSA.MSC UI and the "copy..." option of the context menu for a user object.

I have tried storing the CIM instance of a user object to a variable and passing that to the -Instance option as well as trying to use a subshell call to get-aduser (same verbiage used as with the variable CIM instance) and passing the returned object.

In both cases, the user is created and placed in the built-in Users container.

e.g.

method 1:  $template=get-aduser -identity "_template_sales"

new-aduser -instance $template -givenname"Jenny"-surname"Sales" -accountpassword (convertto-securestring -asplaintext"P@$$word1" -force) -enabled:$true -name"Jenny Sales" -confirm:$false

method 2:

new-aduser -instance (get-aduser -identity "_template_sales") -givenname"Jenny"-surname"Sales" -accountpassword (convertto-securestring -asplaintext"P@$$word1" -force) -enabled:$true -name"Jenny Sales" -confirm:$false

Anybody experience this as well?  If so, what did you do differently to correct the result to produce a new user object that inherited the properties of the user object specified as a template?

I'm sure I'm just doing it wrong but searching the forums has yielded nothing but results related to mostly posts related to creating users with bulk-import methods and the import-csv process.  I have yet to come across any existing threads/documentation related to creating new user objects using existing user objects as a template in PowerShell.

Thanks, in advance and cheers, guys!



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>