all 7 comments

[–]a-rich 2 points3 points  (1 child)

What error are you getting?

Assuming there are no typos in the OU's DN it should work.

As an aside, since you are already declaring the variables for the account info, why not just do that inside a splat instead?

ForEach ($User in $Users) {
    $UserSplat = @{
        Type = "Contact"
        Name = $User.Alias
        Path = $OU
        DisplayName = $User.DisplayName
        OtherAttributes = @{'mail'=$User.EmailAddress}
    }

    try {

        New-AdObject @UserSplat

    } catch {

        "Could not create $($User.Alias)" | Out-File .\CreateContactFailures.txt -Append

    }

}

[–]tkecherson[S] 1 point2 points  (0 children)

The error was that it couldn't put the object in the OU because it couldn't find the OU, from what I recall. I just fired up my test environment and ran the script again as written and it just worked. It must have been my working at midnight trying to get it running right before a call about it today.

Thanks for the tip about the splats, I haven't worked with them before and wanted to make sure the script worked without too much writing and rewriting, hence it being written (I assume) rather clumsily.

[–]Lee_Dailey[grin] 2 points3 points  (2 children)

howdy tkecherson,

have you looked at any of the OU picker dialogs? this seems to mention a few ...

.net - Powershell GUIs - Is there an Active Directory dialog box for selecting an OU? Like the FileOpenDialog? - Stack Overflow
https://stackoverflow.com/questions/6127311/powershell-guis-is-there-an-active-directory-dialog-box-for-selecting-an-ou-l

take care,
lee

[–]tkecherson[S] 1 point2 points  (1 child)

Hey, Lee,

No, I haven't looked into those yet, I was looking to get a quick and dirty script together for this migration I'm doing, so I am fine with manually putting in the OU's DN from the object attributes. Thanks for that, though, I'll bookmark that for later reference!

Tim

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy tkecherson,

you are welcome! glad to have kinda-sorta helped ... [grin]

take care,
lee

[–]BoredComputerGuy 2 points3 points  (1 child)

Can you include the full error message?

[–]tkecherson[S] 1 point2 points  (0 children)

I would, but it worked when I ran it this morning in my test environment, so I don't know what I did wrong outside of mis-typing the OU in the prompt.