PowerShell Import-CSV cmdlet Help

"as I am assuming I need the field to be EmailAddress"That is absolutely correct, to pipe the object from a csv straight to new-aduser the column headers in the csv must match the parameters of new-aduser. So mail won't work, but EmailAddress will.You can do the following to get the parameters that are available.Powershellget-help new-aduserIf changing the csv column headers isn't going to work then you can build the script like this:PowershellForEach($user in (Import-CSV .\data.csv) ) \{ New-ADUser -EmailAddress $user.mail ......}

PowershellForEach($user in (import-csv .\FreshmanADImport2.csv) ){ $userobj = $user | New-ADUser -PassThru -Path "OU=Freshman,OU=Students,DC=domain,DC=com" "Students","Student_iPads" | Add-ADGroupMember -Members $userobj}I haven't looked at your csv yet, but here is the gist of what you are after.Notes:1. Loop thru them with a ForEach() will give you the control you need to do the groups.2. -PassThru lets you capture the new user3. -Path lets you specify where the user is created.

Similar Messages

  • Import-CSV and PSObject

    Hello,
    I have a problem to get below approach.
    Imagine that I have csv file with content as below:
    Head1;Head2;Head3;
    xyz;---;---;
    ---;zyx;---;
    ---;---;xzy;
    123;---;---;
    ---;213;---;
    ---;---;321;
    I'd like to import this file to powershell (import-csv) and put whole content to PSObject that:
    1. First line contains only headers - that if I put $PSObj[1] I'll get all headers
    2. All three "letters lines" are joined to one PSObject item - that if I put "$PSObj[1]" I'll get all these 3 lines
    3. All three "numbers lines" are joined to one PSObject item - that if I put "$PSObj[2]" I'll get all these 3 lines
    I need points 2 and 3 because I need to compare imported information on subject level (Test1 or Test2) and not to compare information on each line level.
    One facilitation (I hope) is that each PSObject item begines when in a row in first column is not "---" value. And end of this item is one row before a row where in first colum is different value than "---" (it is shown on above example)
    Has anyone an idea how to do it?

    Hi D'Thompson,
    Yes you are right, I think that to accomplish my idea I need to divide csv lines/items into separate objects as below:
    Object 1 (5 items)
    Head1 : TestName1
    Head2 : ---
    Head3 : ---
    Head4 : ---
    Head5 : Generic
    Head6 : 1/8/2015 2:48:06 PM
    Head7 :
    Head1 : ---
    Head2 : ---
    Head3 : CommonDeploymentUtility
    Head4 : 6.4.0.4025
    Head5 : ---
    Head6 : ---
    Head7 :
    Head1 : ---
    Head2 : ---
    Head3 : CommonUtility
    Head4 : 6.4.0.4025
    Head5 : ---
    Head6 : ---
    Head7 :
    Head1 : ---
    Head2 : ---
    Head3 : Ionic
    Head4 : 1.9.1.5
    Head5 : ---
    Head6 : ---
    Head7 :
    Head1 : llllllllll
    Head2 : llllllllll
    Head3 : llllllllll
    Head4 : llllllllll
    Head5 : llllllllll
    Head6 : llllllllll
    Head7 : llllllllll
    Object 2 (9 items)
    Head1 : TestName2
    Head2 : ---
    Head3 : ---
    Head4 : ---
    Head5 : Generic
    Head6 : 6/17/2013 9:04:22 AM
    Head7 :
    Head1 : ---
    Head2 : Experiences.PublishingExperiences
    Head3 : ---
    Head4 : ---
    Head5 : ---
    Head6 : ---
    Head7 :
    Head1 : ---
    Head2 : ---
    Head3 : Experiences.ListDefinitions.ExperienceLists
    Head4 : 1.0.0.0
    Head5 : ---
    Head6 : ---
    Head7 :
    Head1 : ---
    Head2 : Material.News
    Head3 : ---
    Head4 : ---
    Head5 : ---
    Head6 : ---
    Head7 :
    Head1 : ---
    Head2 : ---
    Head3 : Material.News
    Head4 : 1.0.0.0
    Head5 : ---
    Head6 : ---
    Head7 :
    Head1 : ---
    Head2 : Material.PublishingMaterials
    Head3 : ---
    Head4 : ---
    Head5 : ---
    Head6 : ---
    Head7 :
    Head1 : ---
    Head2 : ---
    Head3 : Material
    Head4 : 1.0.0.0
    Head5 : ---
    Head6 : ---
    Head7 :
    Head1 : ---
    Head2 : Material.Search
    Head3 : ---
    Head4 : ---
    Head5 : ---
    Head6 : ---
    Head7 :
    Head1 : llllllllll
    Head2 : llllllllll
    Head3 : llllllllll
    Head4 : llllllllll
    Head5 : llllllllll
    Head6 : llllllllll
    Head7 : llllllllll
    So all I need is code that import csv file and divide content to many objects according to below rules
    Beginning (first item) of an object is csv item where first column/position (Head1) value is not like "---" and not like "llllllllll".
    Last item of such object would be csv item where first column/position (Head1) value is "llllllllll"
    The code should also be able to create many PSObjects (as variables) with unique names (e.g. $PSObj1, $PSObj2, PSObj3,...).

  • 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

  • Import CSV file to SP List via Powershell

    Hi there,
    I have a trouble writing a correct function for the script to achieve what I want.
    I export and import a CSV file on a regular
    basis and that way I keep 2 sharepoint lists (external and native) in sync.
    When I import the values, I want Powershell to:
    See if the item exists, if not – add a new item - THAT CURRENTLY WORKS
    If item exists, compare its columns and if there is a new value in CSV, update SP List with updated values just for the items that have changed – DO NOT KNOW HOW TO DO IT
    Editing just the items that have changed would help me keeping version history under control.
    See my script so far. How can I modify it accomplish point 2 above?
    $csvVariable= Import-CSV -path "\\fileshare\folder\export.csv"
    # Destination site collection
    $WebURL = "https://intranet.contoso.com"
    # Destination list name
    $listName = "SP Native List"
    #Get the SPWeb object and save it to a variable
    $webDestination = Get-SPWeb -identity $WebURL
    #Get the SPList object to retrieve the list
    $list = $webDestination.Lists[$listName]
    #Get all items in this list and save them to a variable
    $items = $list.items
    #loop through csv file
    foreach($row in $csvVariable)
    $updated = 0
    #loop through SharePoint list
    foreach($item in $items)
    if($item["EquipmentID"] -eq $row."EquipmentID")
    $updated++
    #add new item if an update wasn't made
    if($updated -eq 0)
    $newItem = $list.items.Add()
    $newItem["UniqueRef"] = $row."UniqueRef"
    $newItem["Safety"] = $row."Safety"
    $newItem["Comment"] = $row."Comment"
    $newItem["Serial"] = $row."Serial"
    $newItem["Vendor"] = $row."Vendor"
    $newItem["Active"] = $row."Active"
    $newItem["Model"] = $row."Model"
    $newItem["Description"] = $row."Description"
    $newItem["EquipmentID"] = $row."EquipmentID"
    $newItem["Code"] = $row."Code"
    $newItem.Update()
    $webDestination.Dispose()

    The problem with word is that it needs the same version of Outlook - 2010 - or you'll get that or similar errors. Import should work because it doesn't need to find outlook - it should know where it is. That points to a problem with the import function.
    See if this helps -
    Open the CSV file in Notepad and use File, Save as then select ANSI from the Encoding dropdown and Save using the existing file name. Also, if you haven't repaired outlook 2013's install, do that in control panel, programs and features. 
    Diane Poremsky [MVP - Outlook]
    Outlook & Exchange Solutions Center
    Outlook Tips
    Subscribe to Exchange Messaging Outlook weekly newsletter

  • Help importing csv for birthday email campaign

    Hello,
    I've used the downloaded data template and uploaded a list of customers. My list shows 153 customers. After I upload it, the name of the list has (84) after it, and when I hover over the name and hit "View Subscribers," it shows 94 items in the list, (at the bottom right of the list, as such: Displaying page 1 of 5, items 1 to 20 of 94).
    When I import the csv, through the E-Mail Campaigns > Recipients window, I get a window with the following:
    Have you downloaded and reviewed the import template file (above right) to ensure your import file is setup correctly? More than one column in your customer database is updated during this import.
    I don't understand what the second sentence means. I've used the template and copied my records into it.
    Comparing lists, it is skipping names, and I can't find anything triggering it. The records are complete.
    Thanks in advance for any advice.
    Teresa

    Hi Vkid12,
    You can refer to the script below, which can check if the ad user exists, if not, it will create a new user and its phone:
    The input file c:\input.csv listed like:
    name, manager, email, location, phone
    nana, haha, [email protected], 123
    import-csv c:\input.csv|foreach{
    try{
    get-ADUser $_.name -ErrorAction Stop}
    catch{
    New-ADuser $_.name -OfficePhone $_.phone}
    To create user with the cmdlet New-ADUser, please refer to this article:
    http://technet.microsoft.com/en-us/library/ee617253.aspx
    If there is anything else regarding this issue, please feel free to post back.
    Best Regards,
    Anna Wang

  • Import-csv how to make powershell ignore a line in a csv file if a column contains a certain value

    Basically I got a very basic script that uses a csv file to input values needed to remove people from a distro list. That part is working fine. I'd like to add to it's functionality so it can look at values in a certain column, and if any of those certain
    values are present, I want powershell to skip that line and not process it. For instance I have a column in the csv called Group. If I have a listing under Group that says ABC I want the script to skip that line and not try to process it. What could I insert
    into the script to acheive this?

    You're welcome. You can add to the if test with -and:
    Import-Csv .\groups.csv | ForEach {
    If ($_.Group -ne 'ABC' -and $_.Group -ne 'DEF') {
    Write-Output "Group is $($_.Group)"
    Write-Output "Name is $($_.Name)"
    Output:
    Group is GHI
    Name is Show Me
    groups.csv:
    Group,Name
    ABC,Skip Me
    DEF,Skip Me Too
    GHI, Show Me
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

  • Powershell: How to change the header name in a imported CSV file

    HI All,
    I have a csv file in which I want to change the headers names in powershell.
    oldnames are name,id
    newnames I want to give are: company and transit respectively.
    Following is what I wrote in script:
               $a = import-csv .\finalexam\employees.csv -header name,id'
                       foreach ($a in $as[1-$as.count-1])  // I used 1 here because I want it to ignore the  exiting headers.
                      { $_.name -eq company, $_.id -eq transit}
    I think this not entirely correct way to do this. Can someone show me how to fix this.
    Regards
    SQL 75

    If you're not an experienced PowerShell programmer, I recommend editing the file in a text editor and changing the name that way.
    -- Bill Stewart [Bill_Stewart]

  • Get-Mailbox PS command import/export csv - need help

    Greetings,
    I know this should be simple but I'm having trouble.  I have about 500 users that have left the company and I want to verify their Exchange 2010 mailbox have been disabled.  If I just run the basic command "Get-Mailbox -identity alias"
    I see all I need to see.  The Name, Alias, and ServerName (that their mailbox is on).  If I check someone whose mailbox has been disabled I get "object could not be found."  Perfect, then I know their mailbox no longer exists. 
    In trying to import a csv file of the 500 users - and export it I'm having trouble. There are a few posts on these forums for similar issues but none are working or the conditions are different.  I'm not too good and PS scripting so I am hoping someone
    can assist.  I pieced this together.
    import-csv C:\temp\DisabledMBs.csv | get-mailbox >c:\temp\DisabledMBsOutput.csv
    The csv output file is blank.  The PS screen outputs this error for each user.
    The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
        + CategoryInfo          : InvalidArgument: (@{Name=Heaton; ...er Logon Name=}:PSObject) [Get-Mailbox], ParameterBindingException
        + FullyQualifiedErrorId : InputObjectNotBound,Get-Mailbox
    I guess I'm missing something here but stuck.  Any help is greatly appreciated!
    thank you!

    If you use a CSV for input, you need to tell the Get-Mailbox command what field is the identifier.  So if you have an alias field in your CSV, you would run your command as follows:
    import-csv C:\temp\DisabledMBs.csv | % { get-mailbox $_.Alias } | Export-Csv c:\temp\DisabledMBsOutput.csv -NoTypeInformation
    BTW, you'll notice that I've also piped your output to the Export-Csv command.  If you just pipe the output of Get-Mailbox to a file with a CSV suffix, you don't get a CSV - you get a text file with only one field named "Name                     
    Alias                ServerName       ProhibitSendQuota" (note, not "Name", "Alias", "ServerName", and "ProhibitSendQuota"
    separately).

  • Import Documents via Powershell from CSV

    Hey guys,
    I have a CSV, managing metadata of documents, with following columns:
    WEB, DocLib, DocPath
    DocPath is the file location of the corresponding documents. Web+DocLib the target destination on Sharepoint. 
    How can I import these documents to the correct destination, using powershell.

    Hi,    
    According to your description, there is a .csv file which stores the destination path and the source path of files, you want to use PowerShell to read the values of this .csv file, then upload files from their source path to the
    destination path which points to a SharePoint Document Library.
    Here is a solution like this: Retrieve the values of columns in this .csv file, then upload files to the specific location according the values we got.
    Here are two links about how to read csv file using PowerShell:
    http://itrob.be/sharepoint-powershell-script-to-import-csv-data-into-a-list/
    http://malcolm1215.wordpress.com/2013/03/11/powershell-how-to-read-csv-files/
    A blog from TechNet about SharePoint 2010: Upload File in Document Library Using PowerShell:
    http://social.technet.microsoft.com/wiki/contents/articles/19529.sharepoint-2010-upload-file-in-document-library-using-powershell.aspx
    Best regards
    Patrick Liang
    TechNet Community Support

  • Import-CSV | New-ADGroup not working as expected with Powershell

    I've looked all over and I can't seem to find an explanation for why this command works perfectly with New-ADUser but not with New-ADGroup.
    These are commands I'm using:
    For Users:
    Import-CSV C:\Imports\adusers.csv | New-ADUser
    This works great. All 500+ users imported with all fields.
    For Groups:
    Import-CSV C:\Imports\adgroups.csv | New-ADGroup
    Only the first line is run correctly. Then I get this error: The specified group already exists
    Here is a snip of my CSV for Groups:
    Name,DisplayName,Description,GroupCategory,GroupScope,Path
    DB Users,DB Users,Group for DB users,Global,"OU=Security Groups,OU=ABC Users,DC=domain,DC=local"
    Accounting,Accounting,Access to the Accounting folder,Security,Global,"OU=Security Groups,OU=ABC Users,DC=domain,DC=local"
    Am I missing something here or is this not possible?
    THanks.

    I knew I would figure this out as soon as I posted it...
    This is the behavior you see if the SamAccountName field is not included.

  • Import-csv Help

    I can't get the below code to work.  If I remove the second condition on the import-csv it will work, but not with both.
    $UserList = "C:\User.csv"
    $exclude = @("Admin", "EBT User", "Guest")
    Get-WmiObject -Class win32_useraccount | Select-Object Name | Export-Csv $UserList -NoTypeInformation
    Import-csv $UserList | Where-Object {($_.Name -notlike "cs*") -or ($_.Name -notin $exclude)}

    One possibility is that you have trailing whitespace in the Name values in your csv.
    Try this:
    $UserList = "C:\User.csv"
    $exclude = @("Admin", "EBT User", "Guest")
    Get-WmiObject -Class win32_useraccount | Select-Object Name | Export-Csv $UserList -NoTypeInformation
    Import-csv $UserList | Where-Object {($_.Name -notlike "cs*") -or ($_.Name.trim() -notin $exclude)}
    If that works as expected, you have trailing white space.
    The trailing whitespace will not matter for the first test because it's only looking at the first two characters.  It will cause it to fail the second test because it will require an exact match, and will look at the entire string.
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • How to find out what was imported from Import-CSV

    If I have an input file that could contain any CSV field names in the headers and after I run Import-CSV I want to find the names of the fields that were imported. How can I do this?

    Hi Patrick,
    generally speaking, you can figure out a lot about what you are working with by using the PowerShell commandline, not a script. You can inspect an object's 'attributes' - as shown by Adam - using the Get-Member cmdlet (You can do this to the content of any
    variable, not just Csv imports):
    # Get content of Csv file
    $Data = Import-Csv "C:\temp\Input.csv"
    # List properties:
    $Data | Get-Member
    The resulting information is a table with 3 columns:
    - Name: The Name of the attribute
    - MemberType: This tells you what it is. The two Types usually of interest are "Method" and anything containing the word "Property". Method does something (Save a file, disable a Mailbox, etc.). Property is a piece of Information (eg. UserName,
    Email, Address, ...).
    - Definition: The definition-column is in my opinion the most interesting aspect of the output of Get-Member. This tells you how to interact with the objects' 'attribute' in question. In case of methods, it shows how to call it and what it returns (Let's say
    you want to save a file: The Method Save() might then require you to specify a path where to save the file).
    In case of Properties however it tells you what kind of information is stored in the Property. If you import a csv, that's always a string for each column, since all you can store in a csv file is text. In some cases, when the console behaves differently to
    what you'd expect, check this out - it may well be that the property is of a type you didn't expect. All Types can be looked up on MSDN (just copy paste the full type-name to google and it'll send you there).
    Learn to use the Get-Member cmdlet and you can figure out how to work with what the console gives you all on your own (Seriously, it's one of the three most important cmdlets in all of PowerShell). Try reading:
    Get-Help Get-Member -Examples
    Those examples explain the use of Get-Member better than I ever could :)
    Cheers,
    Fred
    There's no place like 127.0.0.1

  • Import-csv file for robocopy

    I am using a powershell script which imports a csv file to copy directories.
    Since the folders which I need to copy contain spaces I use double quotes in the csv file.
    Although I don't get the right syntax when I use import-csv
    Either there are too many quotes in the source and/or destination folder or too few quotes.
    the robocopy command should work fine if there are quotes at the beginning and the end of each folder.
    So I started with the following syntax in my csv file:
    source;destination
    "source folder";"destination folder"
    If I run the import-csv command with the content listed above it only shows double quotes at the destination folder.
    so I started adding additonal double quotes around the source folder, it seems toe be an easy thing, but I didn't find the correct amount of double quotes to get the source and destination folder both starting and ending with double quotes.
    any suggestion how to fix this ?

    I agree with jrv, do some reading to get a basic understanding of the concepts
    The script I posted was just an example of how to enclose the data in quotes, since the quotes are removed when importing a csv, they are only there for the purpose of the data containing a comma (,). So now we need to put them back since, your paths contains
    spaces and breaks your robocopy.
    Import-Csv F:\Testing\test.csv -Delimiter ";" | Foreach {
    """$($_.Source)""" + " " + """$($_.destination)"""
    After I import the csv file, I send it over to the Foreach-Object cmdlet, this takes pipeline data and processes it. the $_ is the current object on the pipe line, hence me doing $_.Source
    With your script, you are doing
    $CsvFile = ".\test.csv"
    $srchome = "c:\source location"
    $dsthome = "c:\destination location"
    $Logfile = ".\copy.log"
    $csv = Import-CSV $CsvFile -Delimiter ';'
    foreach ($folder in $csv)
    $srcdoc = $srchome +$folder.source
    $dstdoc = $dsthome +$folder.destination
    robocopy $srcdoc $dstdoc /z /e /np /MIR /COPY:DAT /r:10 /w:30 /log+:$LogFile
    You are saving the results from Import-Csv to a variable $csv, then looping through the variable. So if you possible did the following it would work as my script showed
    $srcdoc = """$($srchome$folder.source)"""
    $dstdoc = """$($dsthome$folder.destination)"""
    Now by looking at your script I am assuming that all the source and destination paths in your csv are \somepath\somepath\.... since the srchome and dsthome do not have a ending \??
    You can clean up the script to be
    $csvFile = ".\test.csv"
    $srchome = "c:\source location"
    $dsthome = "c:\destination location"
    $logfile = ".\copy.log"
    Import-Csv $csvFile -Delimiter ";" | ForEach-Object {
    $srcDoc = """$($srcHome$_.Source)"""
    $dstDoc = """$($dstHome$_.Destination)"""
    RoboCopy $srcDoc $dstDoc /z /e /np /MIR /COPY:DAT /r:10 /w:40 /log+:$logFile
    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.
    Don't Retire Technet

  • How do I import csv file into a SharePoint list?

    I am trying to use a PowerShell script to load data into a SharePoint list from a csv file. When I run my code, it seems to go through the process of loading the data into the list. However when I go to my list, all I see is "System.Object[]" displayed
    in the first column of all my rows with no other data displayed. When I check my csv file, I see a ton of data (several rows and columns) but that is not being moved to my SharePoint list. This is what my script looks like
    if((Get-PSSnapin | Where {$_.Name -eq “Microsoft.SharePoint.PowerShell”}) -eq $null) {
    Add-PSSnapin Microsoft.SharePoint.PowerShell
    $web = Get-SPWeb http://link to web
    $list = $web.lists["List Name"]
    $recordsNumber = 0
    foreach($i in Import-CSV myCSVFile.csv)
    $new = $list.Items.Add()
    $new["Title"] = $i.Title,
    $new["FirstName"] = $i.FirstName,
    $new["LastName"] = $i.LastName
    $new.Update()
    $recordsNumber++
    "Added " + $recordsNumber.ToString() + " records."
    "Done. Press any key to continue..."
    $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
    Any ideas on how to fix this, and get my list populated with data?

    if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
    Add-PsSnapin Microsoft.SharePoint.PowerShell
    $host.Runspace.ThreadOptions = "ReuseThread"
    #Open SharePoint List
    $SPServer=http://SOMESERVER
    $SPAppList="/Lists/List Name/"
    $spWeb = Get-SPWeb $SPServer
    $spData = $spWeb.GetList($SPAppList)
    $InvFile="myCSVFile.csv"
    # Get Data from Inventory CSV File
    $FileExists = (Test-Path $InvFile -PathType Leaf)
    if ($FileExists) {
    "Loading $InvFile for processing..."
    $tblData = Import-CSV $InvFile
    } else {
    "$InvFile not found - stopping import!"
    exit
    # Loop through Applications add each one to SharePoint
    "Uploading data to SharePoint...."
    foreach ($row in $tblData)
    "Adding entry for "+$row."Application Name".ToString()
    $spItem = $spData.AddItem()
    $spItem["Title"] = $row."Title".ToString()
    $spItem["FirstName"] = $row."FirstName".ToString()
    $spItem["LastName"] = $row."LastName".ToString()
    $spItem.Update()
    "Upload Complete"
    $spWeb.Dispose()
    Link
    Please 'propose as answer' if it helped you, also 'vote helpful' if you like this reply.

  • Importing CSV file and parsing it

    First of all I am very new to writing powershell code.  Therefore, my question could be very rudimentary, but I cannot find an answer, so please help.
    I'm trying to read a CSV file and parse it.  I cannot figure out how to access nth element without hardcoding its name.
    $data = Import-Csv $file   #import CSV file
    # read column headers (manually read the first row of the data file, or import it from other source, or ...)
    $file_dump = Get-Content $file  #OK, I'm sure there is another way to get just the first line, but that's not relevant
    $name_list = $file_dump[0].split(",")
    # access element
    $temp = $data[$i].Name  # works - but that's HARDCODING the column name into the script - what if someone changes it?
    #but what I want to do is
    $temp = $data[$i].$name_list[0]
    How do I do this in PowerShell?

    So you're asking how to get the first data point from the first column, no matter what the header is?
    Why won't you know what your input file looks like?
    You can always drop the first line of the file to remove the existing headers and then use the -Header parameter of Import-Csv to give yourself known headers to reference (this will only work if you know how many columns to expect, etc etc etc).
    http://ss64.com/ps/import-csv.html
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

Maybe you are looking for

  • HT1689 How can I get my  itunes gift card balance to me?

    I recently received a ITunes Gift card and I "redeemed" it. My credit balance states the same amount but I cannot find where to look to see if I have already used the $15.00 up on it and I have purchased a couple more songs. On my Purchase page it is

  • Error 1418 / Itunes detected an Ipod that may be corrupt / "Autoplay"

    I've now spent many hours researching these 3 subjects in the discussion groups and I'm still one of many without a resolution to them. I think I've tried everything to get my 5th generation, 13 month old Ipod loaded with music again but without succ

  • Error in my javac?

    my problem: (1) i downloaded a java-applet. when i open the included html-file at any place on my drive, the applet starts and works. the same in the javaviewer. (2) i compile the included "<filename>.java" with "javac" to "<filename>.class" and the

  • Recovery media for qosmio x775

    Hi!! I have a toshiba qosmio X775, mistakenly deleted the recovery of the HHD, and try to buy the recovery media to DVD or USB but I can not buy on the website of Toshiba ...  need help getting the recovery media on DVD, but any help me and will offe

  • PSE 8 synch issues

    My PSE 8 stopped being able to synch/backup to my photoshop.com account.  Adobe support is unwilling to help without a bogus service charge.  Any ideas on how I can fix this problem?  Thanks, Dan