I’m leaning towards it being an issue with the $user.Path part; basically it can’t find the location you’re trying to create the user in.
Is that path the container that the user should be created in?
|
Damien
Solodow
|
--
You received this message because you are subscribed to the Google Groups "ntpowershell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
ntpowershell...@googlegroups.com.
To view this discussion visit
https://groups.google.com/d/msgid/ntpowershell/CAHBr%2B%2BiSK7yWe0sCd%2BpHxwgd%3DMxw4T4KnxYH0SGoJ9Hg6ify3A%40mail.gmail.com.
I tend to agree.
The basic code looks ok, but without sample data, it’s impossible to be sure.
I don’t usually create users this way, but I was checking the help file on New-ADUser and noticed this:
The following example shows how to set this parameter to an OU.
-Path "ou=mfg,dc=noam,dc=corp,dc=contoso,dc=com"
There’s no username in that. But your error looks like it includes it. Does the path property terminate at the destination OU or with the username?
ObjectNotFound: (CN=John Doe,OU=...DC=phila,DC=Gov:String) [New-ADUser], ADIdentityNotFoundException
--
John Wright
IT Support Specialist
1800 Old Bluegrass Avenue, Louisville, KY 40215
Please submit IT requests to Hazelwoo...@bluegrass.org
24 Hour Helpline 1.800.928.8000
CONFIDENTIALITY NOTICE: This message contains confidential information and is intended only for the individual(s) addressed in the message. If you are not the named addressee, you should not disseminate, distribute, or copy this e-mail. If you are not the intended recipient, you are notified that disclosing, distributing, or copying this e-mail is strictly prohibited.
From: ntpowe...@googlegroups.com <ntpowe...@googlegroups.com>
On Behalf Of Mike Leone
Sent: Wednesday, April 16, 2025 3:56 PM
To: NTPowershell Mailing List <ntpowe...@googlegroups.com>
Subject: [ntpowershell] Creating AD users using a CSV file and a splat
EXTERNAL EMAIL - This email was sent by a person from outside your organization. Exercise caution when clicking links, opening attachments or taking further action, before validating its authenticity. |
--
Should contain just the OU.
From: ntpowe...@googlegroups.com <ntpowe...@googlegroups.com> On Behalf Of Wright, John M
Sent: Wednesday, April 16, 2025 4:17 PM
To: ntpowe...@googlegroups.com
A slightly simpler example that I know works. It has some details left out, but I’m sure you can figure it out. 😊
Notice that I cheat – if your CSV file headers are exactly the same as the parameters to New-ADUser, you don’t have to create a separate hashtable. So $u is a line from the CSV.
(One hint: wv stands for ‘write-verbose’)
$sam = $u.SamAccountName
$disp = $u.DisplayName
$email = $u.EmailAddress
$user = Get-ADUser -LDAPFilter "(samaccountname=$sam)" -EA 0
if( $null -ne $user )
{
wv "User already exists in AD: sam='$sam' displayname='$disp' email='$email'"
}
else
{
wv "User does NOT exist in AD, will create: sam='$sam' displayname='$disp' email='$email'"
$path = 'OU=NoGP,OU=RegularUsers,DC=contoso,DC=Com'
New-ADUser @u -AccountPassword $secure -Path $path -ChangePasswordAtLogon $false
if( $? )
{
wv "User successfully created"
}
else
{
wv "User creation FAILED. User index $( $count - 1 ), UPN '$( $u.UserPrincipalName )', SAM '$( $u.SamAccountName )', Display '$( $u.DisplayName )', error '$( $error[ 0 ] )'"
To view this discussion visit https://groups.google.com/d/msgid/ntpowershell/97df81ba493f40d0a2860d1dcb07926b%40smithcons.com.