I used try/catch; and so far it's good! Here it is:

try{

if($user -eq $Null)  {
"*********************************************************************************

Creating a new user account for $($SAM)"
#If the user name and email are available, start creating the account
            $NewUser = New-qaduser -name $SAM `
               -parentcontainer $OU  `
               -userprincipalname $UPN `
                -samaccountname $SAM `
             -displayname $displayname `
                -mail $email `
          -givenname $_.preferredfirstname`
          -sn $_.lastnamepreferred `
          -userPassword $pass  `
                -company $_.Company `
            -department $_.department -title $_.businesscardtitle
-telephonenumber $_.telephone `
            -city $_.city -postalcode $_.zip -state $_.state `
            -streetaddress $_.street  -manager $_.manager `
            -oa
@{ipphone=$_.ipphone;mobile=$_.mobile;employeeid=$_.employeeid;employeenumber=$_.employeegui}
`
            }

if($user -ne $Null){

     $NewUser2 = New-qaduser -name $SAM2 `
                -erroraction stop `
               -parentcontainer $OU  `
               -userprincipalname $UPN `
                -samaccountname $SAM2 `
             -displayname $displayname `
                -mail $email `
          -givenname $_.preferredfirstname`
          -sn $_.lastnamepreferred `
          -userPassword $pass  `
                -company $_.Company `
            -department $_.department -title $_.businesscardtitle
-telephonenumber $_.telephone `
            -city $_.city -postalcode $_.zip -state $_.state `
            -streetaddress $_.street  -manager $_.manager `
            -oa
@{ipphone=$_.ipphone;mobile=$_.mobile;employeeid=$_.employeeid;employeenumber=$_.employeegui}
`


"*********************************************************************************

Creating a new user account for $($SAM2)"

}}
catch{
            write-host  "CANNOT CREATE USER $($SAM2)"
}
}
#stop the logging


On Tue, Apr 23, 2013 at 11:40 AM, Ben Scott <[email protected]> wrote:

> On Tue, Apr 23, 2013 at 11:28 AM, Candee <[email protected]> wrote:
> > Wait - I think  got it!
> > w00t!
>
>   Well, don't keep us in suspense.  What was the solution?  :)
>
> -- Ben
>
> ~ Finally, powerful endpoint security that ISN'T a resource hog! ~
> ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~
>
> ---
> To manage subscriptions click here:
> http://lyris.sunbelt-software.com/read/my_forums/
> or send an email to [email protected]
> with the body: unsubscribe ntsysadmin
>

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to [email protected]
with the body: unsubscribe ntsysadmin

Reply via email to