Wait - I think  got it!
w00t!

On Tue, Apr 23, 2013 at 11:04 AM, Candee <can...@gmail.com> wrote:

> Okay, okay, I know this isn't my new PowerShell help list ;')
> But if you have a second... I'm having trouble with error trapping.
> This is what I want to do:
> import the users
> check if username (firstinitiallastname) is in use.
> If it is, try (firstinitialsecondletterlastname)
> This works the way I want it to (yay!).
>
> I'm having trouble with error trapping if the second username I try is in
> use.
> and display ***Create user manually** instead of the whole, qaduser is in
> use...
>
> any help, pointers, or fish appreciated!
>
> __________________________________________________________________
>
>
> #Start creating users
> Import-Csv $newusers |foreach  {
>         $preferredfirstname = $_.preferredfirstname
>         $lastnamepreferred = $_.lastnamepreferred
>         $SAM = $preferredfirstname.substring(0,1)+$lastnamepreferred
>         $SAM2 = $preferredfirstname.substring(0,2)+$lastnamepreferred+"2"
>         $UPN = $preferredfirstname +"."+$lastnamepreferred+$DNSROOT
>         $Displayname = $lastnamepreferred +" "+$preferredfirstname
>         $Email = $UPN
>         $testemail = get-recipient -identity $email -ErrorAction
> SilentlyContinue
>         $user = Get-qADUser -SamAccountName $SAM
> #Determine if the employee account name is already in use
>
>   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){
>
> "*******************************************************************************************
>      Creating a new user account for $($SAM2)"
>
>      $NewUser2 = New-qaduser -name $SAM2 `
>                -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}
> `
>
>
>       }
>
>      }
> catch{   ErrorAction "silentlycontinue"
>             write-host  "CANNOT CREATE USER $($SAM2)"
>
>
>              }
> finally {
>
>  } }
>
> ~ 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 listmana...@lyris.sunbeltsoftware.com
> 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 listmana...@lyris.sunbeltsoftware.com
with the body: unsubscribe ntsysadmin

Reply via email to