Import csv rename user account is exists in AD

ok, got an interesting one here. Might be easy i have no idea where to even begin with this one.
If have a web site that generates csv file to import into AD. No problem, works great.
I need to put in a check to see if the user/email account already exists in AD and if they do, append a 1 to the account.
then i want to check that appended account with the 1 to see if that exists, if it does add a 2 and so on until the account doesnt exist, then bam create it.
Has anyone done anything like this before ? Or can someone possibly point me in the right direction as far as coding would go.
I'm kind of a novice but diving in head first here.
Any help is appreciated
Thanks All 

here's what i got thus far. i haven't tested as of yet. looking for feedback first.
Import-Module ActiveDirectory
$files = Get-ChildItem -Path c:\new_users\*.csv
Foreach ($file in $files) {
Foreach ($user in(import-csv $file)) {
$username=$user.SamAccountName
$UserPrincipalName = $username + '@my-domain.COM'
$password='xxxxxxxxxx'
Foreach ($user in $files)
 ##Check if exist##
  $User = Get-ADUser -Filter {SamAccountName -eq $Entry}
  If ($User -eq $null) {
     New-ADUser -SamAccountName $user.SamAccountName -UserPrincipalName $UserPrincipalName -name $user.DisplayName -GivenName $user.GivenName -Initials $user.Initials -SurName $user.SurName -DisplayName $user.DisplayName -OfficePhone $user.OfficePhone
-EmailAddress $user.EmailAddress -Title $user.Title -Department $user.Department -Company $user.Company -profilePath $user.ScriptPath
  Else
  $Count = "0"
  While ($User -ne $null)                                                                          
    $Count ++                                                                                          
    [String]$Entry = $Entry.Substring(0,$string.Lenghth-1) + $Count                                                                                                                                                                                      
    $User = Get-ADUser -Filter {SamAccountName -eq $Entry}                                                                                                                                                                                    
  If ($User -eq $null)                                                                                                         
    New-ADUser -SamAccountName $user.SamAccountName -UserPrincipalName $UserPrincipalName -name $user.DisplayName -GivenName $user.GivenName -Initials $user.Initials -SurName $user.SurName -DisplayName $user.DisplayName -OfficePhone $user.OfficePhone
-EmailAddress $user.EmailAddress -Title $user.Title -Department $user.Department -Company $user.Company -profilePath $user.ScriptPath

Similar Messages

  • Setting Up Mobile Accounts to For Users Who Already Exist

    Hi there,
    I work for a company with about 10 Macs, all laptops, all are on 10.5.
    They have never had a server and have asked me to set one up for them. I am in the process of setting up a server here with a new copy of OS X Server 10.5. Here's my question.
    The people here are half-wits and any kind of backup which involves them, you know, actually doing anything is never going to happen.
    My thought was to set up Mobile accounts for all of them s this provides seamless syncing and no issues if they leave their office, The problem seems to be to set up a mobile account seems to require a new user where all the people here already have home folders/stuff on their personal laptops (we don't share computers). The user I create on Open Directory seem, even if i give them the same details of the current user on their laptops, to be different. Is there a way to make this work or should I just make them all Time Machine backups to the server instead?
    Thanks,
    Ben

    So create a csv file with the following headers and data
    UserID, Alias
    UserID should be the user SamAccountName, and the Alias is the Mailbox Alias that you want to set. Supposing that the csv file is named users.csv and located under C:\ , open the Exchange Management Console and run:
    $users = Import-Csv c:\users.csv
    Foreach ($user in $users) {
    Enable-Mailbox -Identity $user.UserID -alias $user.alias -database 'DB1'
    Set-Mailbox -Identity $user.UserID -IssueWarningQuota 1.5gb -ProhibitSendQuota 2gb 
    Please Mark As Answer if this helps
    ammarhasayen

  • Creating multiple mailboxes using Powershell for users who already exist in AD

    Hi there,
    Wondering if anyone can help, I am wanting to use Powershell to run a command which references a CSV file to create a mailbox for a user who already exists in AD.
    It needs to reference the username, to ensure the correct user has a mailbox created (as mentioned they exist already in the domain), place them on a specific database (e.g DB1) and assign them an email address as well as possibly an alias email address
    too.
    Can anyone provide me the headings of the CSV file which would be needed as well as the powershell command to run. It would be great too if I could also set the quota sizes for the user at the same time of creating the mailbox, but if not possible or complicated
    I can run a script afterwards to do this. I would only want to warn them when their mailbox is 1.5GB in size and stop them sending when it reaches 2GB. 
    Thanks

    So create a csv file with the following headers and data
    UserID, Alias
    UserID should be the user SamAccountName, and the Alias is the Mailbox Alias that you want to set. Supposing that the csv file is named users.csv and located under C:\ , open the Exchange Management Console and run:
    $users = Import-Csv c:\users.csv
    Foreach ($user in $users) {
    Enable-Mailbox -Identity $user.UserID -alias $user.alias -database 'DB1'
    Set-Mailbox -Identity $user.UserID -IssueWarningQuota 1.5gb -ProhibitSendQuota 2gb 
    Please Mark As Answer if this helps
    ammarhasayen

  • New-ADUser with Import-Csv...

    trying to run this cmd from an elevated PS prompt.
    Import-CSV "C:\Users\administrator\Documents\Students.csv" | foreach {New-ADUser -SamAccountName $_.PermID -Name ($_.FirstName + " " + $_.LastName) -DisplayName ($_.FirstName + " " + $_.LastName) -Surname $_.LastName -GivenName $_.FirstName -Path $_.OU -AccountPassword
    (ConvertTo-SecureString -AsPlainText $_.Password -Force) -Enabled $true }
    and it fails with
    New-ADUser : The server is unwilling to process the request
    At line:1 char:81
    + Import-CSV "C:\Users\administrator\Documents\Students.csv" | foreach {New-ADUser <<<<  -SamAccountName $_.PermID -Nam
    e ($_.LastName + ", " + $_.FirstName) -DisplayName ($_.LastName + ", " + $_.FirstName) -Surname $_.LastName -GivenName
    $_.FirstName -Path $_.OU -AccountPassword (ConvertTo-SecureString -AsPlainText $_.Password -Force) -Enabled $true }
        + CategoryInfo          : NotSpecified: (CN=Marsh\, Stan...dents,dc=testad:String) [New-ADUser], ADException
        + FullyQualifiedErrorId : The server is unwilling to process the request,Microsoft.ActiveDirectory.Management.Comm
       ands.NewADUser
    No really sure what it means by the server is unwilling. Could it be the Account/Password Policies?
    Thanks for the help

    There are several possibilities. Among them:
    1. A -Name value is not unique in the OU.
    2. A -sAMAccountName value is not unique in the domain.
    3. Password does not meet domain requirements.
    4. -Path is not the Distinguished Name of a valid OU or container.
    5. -Name includes a character that must be escaped (with the backslash escape character "\"), such as one of the following:
    , \ # + < > ; " =
    The most common character that should be escaped is the comma.
    Richard Mueller - MVP Directory Services

  • System Preference/User Accounts Crashes

    System preferences crashes when opening "Accounts" or when using parental controls for one user, but not other.  Would it help to include the bug report generated upon crashing?
    Have...
    Sent bug report to apple, but not sure it went out.
    repaired permissions, but got this message "
              Warning: SUID file "System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/MacOS/ARDAg ent" has been modified and will not be repaired."
    removed   com.apple.systempreferences.plist from preferences folder and restarted
    Problem began after son said his password had mysteriously changed, so I reset it and then the problem began.
    Started up from Install disc and reset passwords, restarted computer, still crashes program

    Back up all data to at least two different storage devices, if you haven't already done so. The backups can be made with Time Machine or with a cloning tool such as Disk Utility. Preferably both. You must be certain that you can restore everything to the state it's in now.
    Boot into Recovery, launch Disk Utility, and erase the startup volume. This operation will destroy all data on the volume, so you had be better be sure of your backups. Install OS X. If your Mac was upgraded from an older version of OS X, you’ll need the Apple ID and password you used to upgrade, so make a note of those before you begin.
    When you reboot, you'll be prompted to go through the initial setup process. That’s when you import the data from one of your backups. For a walkthrough, see here:
    Using Setup Assistant
    Import only the original administrator account. Also import Applications and other files. Test the system when it's up and running. If it seems normal, use Migration Assistant to import the other user accounts, one at a time.
    How to use Migration Assistant to transfer files from a Time Machine backup
    After each one, back up and test.
    Note: You need an always-on Ethernet or Wi-Fi connection to the Internet to use Recovery. It won’t work with USB or PPPoE modems, or with networks that require any kind of authentication other than a WPA or WPA2 Personal password.

  • Import-CSV script to add mobile phone numbers to existing Active Directory accounts

    Hi guys, I'm a powershell beginner and trying to make a simple script to populate the mobile phone number field for a specified number of AD accounts that are currently blank.
    I have a csv file mobilenumbers2.csv with two headers, "samaccountname,mobilenumber".     Underneath the headers I would have "jdoe,3333333333" and so on.
    Here is the script I tried:
    import-csv .\mobilenumbers2.csv -header samaccountname,mobilenumber | ForEach-Object { set-aduser -Identity $_.samaccountname -MobilePhone $_.mobilenumb
    And I'm getting this error when I tried to run it:
    set-aduser : Cannot find an object with identity: 'samaccountname' under:
    'DC=xxxxxxxx,DC=local'.
    At C:\myscripts\addmobilephone3.ps1:1 char:88
    + ... rEach-Object { set-aduser -Identity $_.samaccountname -MobilePhone
    $_.mobilenumb ...
    +                   
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (samaccountname:ADUser) [Set-ADU
       ser], ADIdentityNotFoundException
        + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.
       Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Managemen 
      t.Commands.SetADUser
    I can't seem to populate the "identity" switch from the csv file correctly, but if I run the command manually without importing from the csv and type "jdoe" after the identity switch it works....
    Any help would be greatly appreciated,
    Tom
     

    Hi Tom,
    If you already have the header as the first line in your csv file, plrase drop the parameter -Header, please try the script below and feedback:
    import-csv .\mobilenumbers2.csv | ForEach-Object {
    set-aduser -Identity $_.samaccountname -MobilePhone $_.mobilenumber}
    And the input .csv file should list like:
    samaccountname  mobilenumber
    jdoe                     3333333333
    Best Regards,
    Anna

  • Using PowerShell to import CSV data from Vendor database to manipulate Active Directory Users

    Hello,
    I have a big project I am trying to automate.  I am working in a K-12 public education IT Dept. and have been tasked with importing data that has been exported from a vendor database via .csv file into Active Directory to manage student accounts. 
    My client wants to use this data to make bulk changes  to student user accounts in AD such as moving accounts from one OU to another, modifying account attributes based on State ID, lunchroom ID, School, Grade, etc. and adding new accounts / disabling
    accounts for students no longer enrolled.
    The .csv that is exported doesn't have headers that match up with what is needed for importing in AD, so those have to be modified in this process, or set as variables to get the correct info into the correct attributes in AD or else this whole project is
    a bust.  He is tired of manually manipulating the .csv data and trying to get it onto AD with few or no errors, hence the reason it has been passed off to me.
    Since this information changes practically daily, I need a way to automate user management by accomplishing the following on a scheduled basis.
    Process must:
    Check to see if Student Number already exists
    If yes, then modify account
    Update {School Name}, {Site Code}, {School Number}, {Grade Level} (Variables)
    Add correct group memberships (School / Grade Specific)
    Move account to correct OU (OU={Grade},OU=Students,OU=Users,OU={SiteCode},DC=Domain,DC=net)
    Remove incorrect group memberships (School / Grade Specific)
    Set account status (enabled / disabled)
    If no, create account
    Import Student #
    Import CNP #
    Import Student name
    Extract First and Middle initial
    If duplicate name exists
    Create log entry for review
    Import School, School Number, Grade Level
    Add to correct Group memberships (School / Grade Specific)
    Set correct OU (OU={Grade},OU=Students,OU=Users,OU={SiteCode},DC=Domain,DC=net)
    Set account Status
    I am not familiar with Powershell, but have researched enough to know that it will be the best option for this project.  I have seen some partial solutions in VB, but I am more of an infrastructure person instead of scripting / software development. 
    I have just started creating a script and already have hit a snag.  Maybe one of you could help.
    #Connect to Active Directory
    Import-Module ActiveDirectory
    # Import iNOW user information
    $Users = import-csv C:\ADUpdate\INOW_export.csv
    #Check to see if the account already exists in AD
    ForEach ( $user in $users )
    #Assign the content to variables
    $Attr_employeeID = $users."Student Number"
    $Attr_givenName = $users."First Name"
    $Attr_middleName = $users."Middle Name"
    $Attr_sn = $users."Last Name"
    $Attr_postaldeliveryOfficeName = $users.School
    $Attr_company = $users."School Number"
    $Attr_department = $users."Grade Level"
    $Attr_cn = $Attr_givenName.Substring(0,1) + $Attr_middleName.Substring(0,1) + $Attr_sn
    IF (Get-ADUser $Attr_cn)
    {Write-Host $Attr_cn already exists in Active Directory

    Thank you for helping me with that before it became an issue later on, however, even when modified to be $Attr_sAMAaccountName i still get errors.
    #Connect to Active Directory
    Import-Module ActiveDirectory
    # Import iNOW user information
    $Users = import-csv D:\ADUpdate\Data\INOW_export.csv
    #Check to see if the account already exists in AD
    ForEach ( $user in $users )
    #Assign the content to variables
    $Attr_employeeID = $users."Student Number"
    $Attr_givenName = $users."First Name"
    $Attr_middleName = $users."Middle Name"
    $Attr_sn = $users."Last Name"
    $Attr_postaldeliveryOfficeName = $users.School
    $Attr_company = $users."School Number"
    $Attr_department = $users."Grade Level"
    $Attr_sAMAccountName = $Attr_givenName.Substring(0,1) + $Attr_middleName.Substring(0,1) + $Attr_sn
    IF (Get-ADUser $Attr_sAMAccountName)
    {Write-Host $Attr_sAMAccountName already exists in Active Directory
    PS C:\Windows\system32> D:\ADUpdate\Scripts\INOW-AD.ps1
    Get-ADUser : Cannot convert 'System.Object[]' to the type 'Microsoft.ActiveDirectory.Management.ADUser'
    required by parameter 'Identity'. Specified method is not supported.
    At D:\ADUpdate\Scripts\INOW-AD.ps1:28 char:28
    + IF (Get-ADUser $Attr_sAMAccountName)
    + ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Get-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.ActiveDirectory.Management.Commands.GetAD
    User

  • User account missing files and preferences??  Not from renaming home folder

    Hi all,
    After some strange behaviour in Apple Color, upon rebooting, my user account has returned to default. I had many items on the desktop and various subfolders in the documents folder. All pictures. Music. All are now gone. Desktop and dock have been reset to default.
    The user folder still exists but everything I had in there is gone.
    Another user may have been created called "root" containing only
    /Library
    /Documents/Color Documents...etc
    I am aware of the problem with changing the short name or renaming the home folder (after sifting through this forum) and it is definitely not this problem.
    Maybe its somehow related but I definitely did not rename any of these things myself. And there is no duplicated user account with all my files in it.
    Any help or ideas would be greatly appreciated.
    Cheers
    Nate
    ps. Is it possible to restore the system to an earlier time like in Windows?
    I've read somewhere that a Previous System folder exists and it might be possible with Disk Utility but I can't find this folder anywhere.
    Message was edited by: stoney23

    Hi there,
    Thanks for the reply. I've managed to restore most of my important stuff using a file recovery software so I'm at peace with the loss of only a few files now. I'll just have to start rebuilding my dock and preferences again now which is not the end of the world.
    After a bit of thinking about it I'm 95% sure this is what happened.
    Color tried to save an image file with the same name as the folder I had made storing all my Color project saves. The folder was called Post. I'm not quite sure how its possible but it managed to overwrite the folder with the new image file. Now there is a Color image file (with no extension) there called Post and no folder.
    Then I tried to save the Color project and of course it told me the project directory was missing and it will create a new one. I'm guessing this is when Color bulldozed through my user account to create the folder Color Documents where it DIDN'T save the file anyway
    Leaving me with a default user account deleting everything that was 'added' to the account previously.
    It also created another user account called 'root' in which there is also only a Color Library/preferences and documents folder
    Is that normal that things like that can just happen?
    I guess from here I will just try and finish my project and afterwards do a re-install of the OS just to be sure - checking the Archive and Install option this time
    Unless you have any other ideas from what I've told you.
    Thanks again for replying
    Nate

  • Full import error : "user does not exists"

    Hi all,
    I had 5 separated windows based servers (32bit) with oracle database 9i. I decided to centralize them into one server. So, I configured a new Linux (64bit) and install an Oracle 10gR2. Then I configured a starter database with dbca. I prepared a full dump file from one of old servers and successfully full imported it into starter database on new Linux (10g) server. After that I configured another database using dbca. But when I wanted to full import the previous dump file into new database I have got the error "user does not exists" regarding some demo schema and import terminated unsuccessfully.
    I decided to create users regarding the errors and restart the import. After each user creation I was getting a new error for a new user account.
    My main question is why first time import terminated successfully without any error but second one in new database raised error?
    Thank
    Iman
    Edited by: Iman.Jam on Aug 25, 2009 9:38 AM

    Hi yingkuan,
    imp full=y file=.... log=..... userid=system/manager@orcl
    ALTER SESSION SET CURRENT_USER = "HR"
    ORA-.... : user does not exists
    And I know that import will create users that are not exists. Actually, all my specified schema are created but not some of accounts
    Regards,
    Iman
    Edited by: Iman.Jam on Aug 25, 2009 9:59 AM

  • HT4872 I have not been able to import contacts from google or my android to my new I-phone 5. This article helps to a point until error message "cannot create account" already exist is received. Please help.

    I have not been able to import contacts from google or my android to my new I-phone 5. This article helps to a point until error message "cannot create account ... already exist" is received. Please help.

    -Reece,
    We only have 1 single domain, 1 domain forest, no subdomains, only alias. I had replied to the other post as well. But I am happy to paste it here in case anyone want to read it.
    So, after a few months of testing, capture and sending logs back and forth to Apple Engineers, we found out there is a setting in AD, under User Account that prevent us to log into AD from Mountain Lion. If you would go to your AD server, open up a user account properties, then go to Account tab, the "Do not require Kerberos preauthentication" option is checked. As soon as I uncheck that option, immediately I was able to log into AD on the Mac client. Apple engineers copied all my AD settings and setup a test environment on their end and match exact mine AD environment. They was able to reproduce this issue.
    The bad part about this is... our environment required the "Do not require Kerberos preauthentication" is checked in AD, in order for our users to login into some of our Unix and Linux services. Which mean that it is impossible for us to remove that check mark because most, if not all of them some way or another require to login into applications that run on Unix and Linux. Apple is working to see if they can come up with a fix. Apparently, no one has report this issue except us. I believe most of you out there don't have that check mark checked in your environment... Anyone out there have any suggestion to by pass or have a work around for this?

  • Change (rename) short names on existing Users

    Working on the Workgroup Manager with the Apple XServer 10.4.10, and I wonder if there was a code or script to change the “short name” of the users accounts as well as having the new (rename)“short name” stay the default short name. I don’t want the “old” short name to exist on the user account. Is there a process through the terminal program I can make this change?
    Thank you,

    The simple answer is 'no.' But if you're really bent on it, Apple documents the process of creating a new user and integrating the old user's files. http://docs.info.apple.com/article.html?artnum=106824 (updated 2005 so i assume the process has not changed)
    I believe this is targeted at OS X client, as a standalone. The process for an OpenDirectory account may differ.
    Also, there is a utility called ChangeShortName that supposedly automates this process at www.danfrakes.com. I haven't run it and I believe it's intended for standalone OS X clients -- I have no idea what it'd do on a server. I think it's one of those "run at your own risk" things.

  • Renaming Acive Directory User Account

    Hi,
    I am undergoing streamlining of usernames in Local AD. Instead of renaming the existing users, I am planning to create new users and copy old user profile to the new user account. scenario is as under:-
    1. Currently user "abc" has domain account [email protected]
    2. I created new user with abcxyz with the domain account [email protected]
    3. I need to copy user "abc" profile to the newly created user account "abcxyz"
    ** User Profiles are local not Roaming.
    Is it a workable solution? if so, then how can I do this? if not, then what could be the alternate?
    Thanks.

    Why do you want to create new accounts? The issue with that approach is that all group memberships will be gone and all file/share permissions throughout AD will be missing as well.  So you will need to give them permission to everything again. Why
    not just perform a rename?
    Mark B. Cooper, President and Founder of PKI Solutions Inc., former Microsoft Senior Engineer and subject matter expert for Microsoft Active Directory Certificate Services (ADCS). Known as “The PKI Guy” at Microsoft for 10 years.

  • Is it possible to use my music files in both my girlfriend's and my separate Itunes libraries through our seperate user accounts?? I want to import my music into her library with out copying the files onto my hard drive a second time....

    Is it possible to use my music files in both my girlfriend's and my Itunes library's through our seperate user account?  I want to import my music into her library without copying to my hard drive a second time.....

    Would any of these help you?:
    http://www.apple.com/itunes/inside-itunes/2011/05/two-ways-to-share-media-librar ies-through-itunes.html
    http://www.apple.com/itunes/inside-itunes/2011/01/keeping-multiple-itunes-librar ies-on-a-single-computerif-you-share-your-computer-with-others-and-you.html

  • My question is in regard to pc to mac migration. How do I migrate information from my pc with specific user account to an existing user account on my mac? I do not want to use multiple mac user accounts.

    My question is in regard to pc to mac migration. How do I migrate information from my pc with specific user account to an existing user account on my mac? I do not want to use multiple mac user accounts.

    https://discussions.apple.com/message/16371308#16371308

  • Separate accounts for existing multiple users on multiple computers

    We have three users on four computers. We each have large libraries. i want to spin off and set up my own account with separate billing and let the other two go their own way (together or also separate). I'm afraid of losing the 4,000 songs I have purchased and copied from CDs or possibly freezing out the other two users if I just change the password. Also, will the changes sync with my iPod and iPhone?

    Setting up new account in the iTunes Store, if that's what you mean, will have no effect on existing tracks nor iPods as long as you don't try to authorize the computer to more than five iTunes Store accounts. If you're using a single Mac OS X user account and iTunes library, you'll each have to log into your own iTunes Store account to purchase and then remember to log out when you're done. It will probably be easier if you have your own user account in Mac OS X so you have a completely separate iTunes library. Then you have have your iTunes logged into your own account. You'll need to copy the tracks you want from the existing iTunes library to your new Mac OS X user account.

Maybe you are looking for

  • Index Usage from SQL query in Oracle Forms

    Would using LIKE/OR in where clause (of an indexed column) will force the the query to NOT use INDEX. We have these where clause in Oracle Forms Records Group. Below are two examples... 1. If we have a where clause with LIKE would that NOT use the in

  • Implicit commit in ABAP Web Dynpro?

    I wonder if ABAP Web Dynpro is executing an implicit commit. I have two buttons on the same view. The first one inserts an entry into a table, the second one executes a "rollback work" (and to be sure calls function "DB_ROLLBACK"). However, after fir

  • Remote debugging of 4.6C from ecc 6.0

    Hello, we are developing Web applications in WD Abap on an ecc 6.0 system. The necessary data are provided from a 4.6c System. Question. I need to DEBUGG the functionality on the 4.6C system with input from the website (ecc6.0 application). Can anyon

  • Customizing the title bar of a title window

    hi, I want to resize the height of the titleBar of titleWindow, without using skin  How can I do this?

  • 8500 All-in-One Printing envelopes

    Do I have to remove all of the paper from the feeder to print one envelope?  or several envelopes?  I tried to print one envelope by placing it on a stack of paper in the feeder - it jammed.  Had a 6500 AIO and sometimes it worked with 1 envelope on