Import computers from csv Powershell

Hi,
I'm trying to import some computers within sccm via Powershell but get the following error:
PS STC:\> $Computers = Import-Csv "C:\computers.csv"
$CollectionName = "STC - W7 - Deploy"
ForEach ($Workstation in $Computers)
   Import-CMComputerInformation -ComputerName $Workstation.Name -MacAddress $Workstation.Mac -CollectionName $CollectionName
Import-CMComputerInformation : Cannot validate argument on parameter 'MacAddress'. System.Management.Automation.ValidationMetadataException
At line:5 char:77
+ ...  -ComputerName $Workstation.Name -MacAddress $Workstation.Mac -Collec ...
Csv contains:
Name,Mac
Computer1,0C:51:8F:7E:3D:04
Please advise.
J.
Jan Hoedt

That does work but it only imports 1 computer (the last in my list).
Import-CMComputerInformation -CollectionName "All Systems" -FileName "c:\computers2.csv" -EnableColumnHeadings $True -verbose
csv
Name,Mac Address
test123,00:11:22:33:44:55
test3456,00:11:22:33:44:55
test75689,00:11:22:33:44:55
test899,00:11:22:33:44:55
test756689,00:11:22:33:44:55
Only test756689 is imported.
This is the verbose output:
VERBOSE: Start: Execution of WQL query: SELECT * FROM SMS_Collection WHERE CollectionType = 2 AND Name='All Systems' ORDER by Name
VERBOSE: Query options: None
VERBOSE: Performing the operation "Import" on target "ComputerInformation: c:\computers2.csv".
VERBOSE: Executing method 'ImportMachineEntry' against class 'SMS_Site'
VERBOSE: Input properties:
VERBOSE: -- :: NetBiosName == test123
VERBOSE: -- :: SMBIOSGUID ==
VERBOSE: -- :: MACAddress == 00:11:22:33:44:55
VERBOSE: -- :: OverwriteExistingRecord == True
VERBOSE: Output properties:
VERBOSE: -- :: MachineExists == True
VERBOSE: -- :: ResourceID == 16791724
VERBOSE: -- :: ReturnValue == 0
VERBOSE: -- :: SMSUniqueIdentifier == GUID:D86BB77F-4F29-4DFA-B8A1-874783E55FC0
VERBOSE: Executing method 'ImportMachineEntry' against class 'SMS_Site'
VERBOSE: Input properties:
VERBOSE: -- :: NetBiosName == test3456
VERBOSE: -- :: SMBIOSGUID ==
VERBOSE: -- :: MACAddress == 00:11:22:33:44:55
VERBOSE: -- :: OverwriteExistingRecord == True
VERBOSE: Output properties:
VERBOSE: -- :: MachineExists == True
VERBOSE: -- :: ResourceID == 16791724
VERBOSE: -- :: ReturnValue == 0
VERBOSE: -- :: SMSUniqueIdentifier == GUID:D86BB77F-4F29-4DFA-B8A1-874783E55FC0
VERBOSE: Executing method 'ImportMachineEntry' against class 'SMS_Site'
VERBOSE: Input properties:
VERBOSE: -- :: NetBiosName == test75689
VERBOSE: -- :: SMBIOSGUID ==
VERBOSE: -- :: MACAddress == 00:11:22:33:44:55
VERBOSE: -- :: OverwriteExistingRecord == True
VERBOSE: Output properties:
VERBOSE: -- :: MachineExists == True
VERBOSE: -- :: ResourceID == 16791724
VERBOSE: -- :: ReturnValue == 0
VERBOSE: -- :: SMSUniqueIdentifier == GUID:D86BB77F-4F29-4DFA-B8A1-874783E55FC0
VERBOSE: Executing method 'ImportMachineEntry' against class 'SMS_Site'
VERBOSE: Input properties:
VERBOSE: -- :: NetBiosName == test899
VERBOSE: -- :: SMBIOSGUID ==
VERBOSE: -- :: MACAddress == 00:11:22:33:44:55
VERBOSE: -- :: OverwriteExistingRecord == True
VERBOSE: Output properties:
VERBOSE: -- :: MachineExists == True
VERBOSE: -- :: ResourceID == 16791724
VERBOSE: -- :: ReturnValue == 0
VERBOSE: -- :: SMSUniqueIdentifier == GUID:D86BB77F-4F29-4DFA-B8A1-874783E55FC0
VERBOSE: Executing method 'ImportMachineEntry' against class 'SMS_Site'
VERBOSE: Input properties:
VERBOSE: -- :: NetBiosName == test756689
VERBOSE: -- :: SMBIOSGUID ==
VERBOSE: -- :: MACAddress == 00:11:22:33:44:55
VERBOSE: -- :: OverwriteExistingRecord == True
VERBOSE: Output properties:
VERBOSE: -- :: MachineExists == True
VERBOSE: -- :: ResourceID == 16791724
VERBOSE: -- :: ReturnValue == 0
VERBOSE: -- :: SMSUniqueIdentifier == GUID:D86BB77F-4F29-4DFA-B8A1-874783E55FC0
Jan Hoedt

Similar Messages

  • Import data from csv to SQL database

    How to  Import data from csv to SQL database through BLS-xMII?

    Hi,
    if you using Oracle, you may also use the bulk insert with MII. You can use the String List to XML parser to convert your CSV to XML, and then use a query that calls a stored procedure which does the bulk insert.
    Also have a look at thread [read XML file into stored procedure|http://forums.sdn.sap.com/click.jspa?searchID=63850236&messageID=7455643].
    Michael

  • How to import contacts from csv to Iphone 4S?

    How to import contacts from csv to Iphone 4S?

    Hi,
    you can use this app to import your contacts from CSV file to your iPhone:
    https://itunes.apple.com/us/app/contacts-in-import-csv-contacts/id549639443?mt=8
    You can send CSV file to app via email attachment ot iTunes. More details:
    http://csvcontacts.wordpress.com/user-instructions/
    You can handle phone number types correctly ("mobile","work","home"), import birdthays from any date format and many more.

  • How to import data from CSV to TCode COR6N

    Hi friends,
    Please help me. I don't know how to import data from CSV file to TCode COR6N. (time ticket for production order)
    I used function: BAPI_PRODORDCONF_CREATE_TT to fill information into TCode COR6n, but it thrown error: "Orders of the order type ZP01 cannot be confirmed". ZP01 is my Order Type.
    Thanks in advance.
    Nguyen Phuoc Toan.

    You can use the LSMW tool to do this.
    The details of LSMW BAPI method is as follows :-
    Business Object:- BUS2116
    Method:-CREATEPREDEFTIMETICKETMULTIPLE
    Message Type:- PPCC2PRETTICKET
    Basic Type:- PPCC2PRETTICKET01
    Regards
    Dhirendra

  • How to import data from CSV to TCode COR1?

    Hi SAP PP guru,
    How to import data from CSV file to TCode COR1?
    Thanks in advance,
    Nguyen Phuoc Toan.

    Nguyen,
    You have not yet confirmed what your requirement is?
    You can take the help of ABAP person to understand what BDC or LSMW is about, basically this is a tool provided by SAP that would enable you to record a transaction process and you can use the code to perform the transaction in mass. [Help on LSMW|http://help.sap.com/erp2005_ehp_04/helpdata/EN/ad/2d54a41d7011d2b42e006094b944c8/content.htm]
    Regards,
    Prasobh

  • How to import data from CSV file with columns separated by semicolon?

    I migrate database from MS SQL 2008 to ORACLE 11g
    I export data to CSV file from MS SQL
    then I try to import it to Oracle
    several tables goes fine using Import data option in the SQL Developer
    Standard CSV files with data separated by comma were imported.
    chars, date (with format string), and integer data are imported via import wizard without problems
    the problems were when I try to import table with noninteger numbers with modal part separated by comma not by dot
    comma is the standard separator for columns in CSV file
    so I must change the standard separator to semicolon
    then the import wizard have problem to correct recognize the columns data because it use only standard CSV comma separator :-/
    In SQL Developer 1.5.3 Tools -> Preferences -> Migration -> Data Move Options
    I change "End of Column Delimiter" to ; but it doens't work
    Is this possible to change the standard column separator for import data wizzard in SQL Developer 1.5.3?
    Or maybe someone know how to import data in SQL Developer 1.5.3 from CSV when CSV colunn separator is set to semicolon?

    A new preference has been added to customize the import delimiter in main code line. This should be available as part of future release.

  • Script to import contacts from CSV file into Address Book

    Hi,
    I am wondering if it would be possible to import contacts from a CSV file into a group in Address Book using applescript, and if so, if anyone is aware of a script that does this or something similar.
    I have a CSV file with three columns 'First Name', 'Last Name' and 'Email Address'.  I would like these to correspond with  'First', 'Last' and (Work) 'Email' in Address Book.
    Ideally the script would also check to see if entries already exist for the people being imported, but this is less crucial.
    Thanks in advance for any assistance,
    Nick

    Hi,
    Test this on a very small csv file (four or five contacts) to see if it works for you. It will not de-duplicate. You don't give the name of the group, so you'll need to replace Name of group in the second line with your group name, enclosed in double quotes.
    --begin script
    set the_people to read (choose file with prompt "Choose your CSV file")
    set the_group to "Name of group"
    set old_tids to AppleScript's text item delimiters
    set AppleScript's text item delimiters to ","
    set par_count to (count paragraphs in the_people)
    repeat with x from 1 to par_count
              set next_par to paragraph x of the_people
              set first_name to text item 1 of next_par
              set last_name to text item 2 of next_par
              set e_mail to text item 3 of next_par
              tell application "Address Book"
                        set nu_person to make new person with properties {first name:first_name, last name:last_name}
      make new email at end of emails of nu_person with properties {label:"Work", value:e_mail}
                        add nu_person to group the_group
      save
              end tell
    end repeat
    set AppleScript's text item delimiters to old_tids
    --end script
    Watch out for bad line breaks in the lines beginning "set nu_person..." and "make new email..."

  • BUG 3.0/3.1 Import data from CSV in non english local

    Hello,
    I have 3.0 on a German XP (NLS Decimal "," and Group ".") but with
    AddVMOption -Duser.language=en
    because of bug 9231534
    I try to import data from a delimited file that contains the number "123,23"
    When I use the Import Data Wizard it generates an insert with "12323.0". This import works, but gives me the wrong values, 12323 instead of 123,23.
    I have 3.1 with german UI and try the same import.
    It generates a correct insert "123.23", but on executing it fails, because it expects the german decimal separator, this is wrong for two reasons:
    The generated script has a dot as decimal separator and it would not make sense to use a comma, because this is the value separator in an insert script.
    To execute the script it should use the same NLS-Setting as for generating.
    Regards
    Marcus

    Hello,
    has anybody found a solution?
    Testcase: SQL Developer 3.1 on a German XP with default NLS Settings
    CREATE TABLE "TEST_TABLE"
           "NUM" NUMBER
          ,"VCH"  VARCHAR2(10 BYTE)
        ) ;Test file test_insert.dsv
    num;vch
    1;KL
    1,5;tz
    12345,45;ooImporting using the wizard inserts the first row correctly, for the others I get
    SET DEFINE OFF
    --Einfügen für Zeilen  1  bis  3  nicht erfolgreich
    --ORA-01722: invalid number
    --Zeile 2
    INSERT INTO TEST_TABLE (NUM, VCH) VALUES (1.5,'tz');
    --Zeile 3
    INSERT INTO TEST_TABLE (NUM, VCH) VALUES (12345.45,'oo');Beside the wrong umlaut in the message the insert statement itself is correct, because you cannot use the german decimal separator "," in the script. The bug is, that it should use the same NLS settings for generating and running the script.
    Regards
    Marcus

  • How to import data from CSV file into a table by using oracle forms

    Hi,
    I have a CSV file and i want to insert in oracle database in a table by using a button in oracle forms.
    the user can select CSV file by using open dialog .
    can any one help me to find method to make import and select file from the client machine ?
    thx.

    1. create table blob
    CREATE TABLE IB_LOVE
      DOC          BLOB,
      CONTRACT_NO  VARCHAR2(20 BYTE)                NOT NULL
    )2. use the code below to insert:
           INSERT INTO ordmgmt.ib_love
                       (contract_no, doc
                VALUES (:control.contract_no_input, NULL
           lb$result :=
             webutil_file_transfer.client_to_db (:b2.file_name, v_file_blob_name, v_col_blob_name,
                                                 'CONTRACT_NO = ' || :control.contract_no_input);
           :SYSTEM.message_level := 25;
           COMMIT;
           :SYSTEM.message_level := 0;3. use the code below to download
         if :control.CONTRACT_NO_INPUT is not null then
              vboolean :=   webutil_file_transfer.DB_To_Client_With_Progress(
                               vfilename,  --filename                       
                              'IB_LOVE', ---table of Blob item                       
                              'DOC',  --Blob column name                       
                              'CONTRACT_NO = ' || :CONTROL.CONTRACT_NO_INPUT, ---where clause to retrieve the record                       
                              'Downloading from Database', --Progress Bar title                       
                              'Wait to Complete'); --Progress bar subtitle  client_host('cmd /c start '||vfilename);
              client_host('cmd /c start '||vfilename);                 
         else
              errmsg('Please choose contract no');
         end if;4. use the code below to open file dialog
    x:= WEBUTIL_FILE.FILE_OPEN_DIALOG ( 'c:\', '*.gif', '|*.gif|*.gif|', 'My Open Window' ) ;
    :b2.FILE_NAME:=X;

  • Problem Importing Contacts from CSV to Outlook 365 Home Premium

    I have exported contacts from gmail to Outlook CSV format, unable to import to Outlook 365.  Error suggests:
    There was a problem importing your contacts.    
    Phone numbers and websites can only contain English characters (a-z or A-Z), numbers (0-9), and specific symbols (such as @). Please try again.
    I exported from Outlook 365 a CSV file and column by column copy/value pasted the data from the gmail generated file to the Outlook 365 (People) CSV and saved.  I also searched for any such vaguely referenced trouble spot character and removed anything
    that feel out of description (I didn't find anything obvious)
    characters left in place on emails were (underscore _), characters left in several phone numbers were (comma's , (pause prompts)).  I may have a phone number or 2 that also contain the English character "x".
    Please help

    Hi,
    Make sure you exported the Gmail contacts as Outlook CSV format.
    In addition, you can also try exporting the contacts as the vCard format, test if it can be imported into Outlook properly.
    If you deleted the column of phone, import the contacts into Outlook, will the same error show up?
    If you have an Outlook.com account, you can try import the contacts to Outlook.com, create the Outlook.com account in Outlook, after the contacts sync completes, move the contacts to the target account.
    Regards,
    Melon Chen
    TechNet Community Support

  • Importing Contacts from CSV without MS Outlook/Lot...

    I have PC Suite 7.0.8.2 running on WinXP Sp3 and have contacts in a spreadsheet that I need to import to my N95 software version 20.0.015. PC Suite Contacts (PCSC) is version 1.0
    If I save the spreadsheet data as a CSV, Unicode (or any other translation come to that) and attempt to import it via PCSC then Contacts "GPF"s and closes.
    If I export current phone contacts to a CSV file then I can re-import this file without problem. This exported file is reported by other applications such as Notepad and Open Office as being in Unicode format - hence my use of that format.
    Looking at my generated CSV and the one from PCSC the difference would seem to be quote marks. So I have tried making every element have a set of quote marks as the PCSC file has. Also setting the last element to each line to be a set of quote marks ("") as in the PCSC file. Or removing all "empty" elements at the end of a line as in the PCSC file. But still when attempting to import the file PCSC closes with an unexpected error.
    I don't have access to MS Outlook or Lotus Notes so using one of them as an intermediary is not an option. I do only need to do this once as I want my phone contacts to be the "Master" set once I've consolidated to the phone. That consolidation needs PCSC to manage to import from a CSV file though!
    Any one know how to make a "personally generated" csv file acceptable to PCSC?
    Solved!
    Go to Solution.

    So having spent a load more time attempting to do this I have, at last, managed to get the thing to work!
    So for any others having issues it seems that the data checking, when it finds an error just GPFs the application rather than report what it does not like! (Nokia people can you fix that?)
    All fields in the CSV should have " at the start and finish, even if nul/blank
    Every line should end in "" (as the heading line does when exporting from contacts)
    Phone numbers should not contain ( or ) but can contain +
    File should be saved in Unicode bigendian format (Notepad in XP can do that)
    Dates of Birth should be given as "YYYY-MM-DD"
    Any thing that notepad shows as a square should be removed
    I found that when doing the import the progress bar moved quickly to 49% then sat there until the operation was finished. It struck that the contacts were put onto the PC in the first 49% and then copied to the phone but I may be wrong about that.

  • How to import data from CSV files to OIM?

    Hello,
    We have to import some of the files which are in csv format and are placed in a specific folder hierarchy. Please help as i am not able to proceed further.
    Thanks a lot!

    To write custom scheduler tasks you need to write a class which extends SchedulerBaseTask class.
    See this link. Re: Custom reconcilation
    Also GTC flat file retrieves data from file and creates identity/account in OIM. You can use either ways to meet your requirements.

  • Import List Items with Managed Metadata Field from CSV File

    Hello,
    I try to import list items from a CSV File. Most of the fields are populating correctly except the Managed Metadata Field. I found multiple examples on how to set Managed Metadata Fields with Powersehll, but unfortunately I couldnt get it running.
    The CSV File holds values for the Metadata Column, this value should be checked against the Metadata in the Termstore. If this Term is existent, then it should set the fields value, if it is not existant then it should add the term from the CSV File to the
    Term Set in the Term Store. Can anybody give me a tip on how to do this? This is what I have, where Line 4 holds the Metadata:
    $Siteurl = "http://siteUrl"
    $Rootweb = New-Object Microsoft.Sharepoint.Spsite($Siteurl);
    $Webapp = $Rootweb.Webapplication
    $listName = "Catalogue"
    $listWeb = Get-SPWeb $Siteurl
    $list = $listWeb.Lists[$listName]
    $pfad1 = "c:\temp\Servers.csv"
    $content = import-csv -Delimiter ";" -Path $pfad1 
    foreach ($line in $content) {
    $newItem = $list.Items.Add()
    $newItem["Field 1"] = $line.1
    $newItem["Field 2"] = $line.2
    $newItem["Field 3"] = $line.3
    $newItem["Field 4"] = $line.4
    $newItem.Update()
    write-host $line.Title imported
    Thanks!!

    Hi Jimmie,
    From your description, when importing list from csv to SharePoint site, you would like to compare if Managed Metadata column exists in term store, and return yes value, if not, add it to term store.
    That might need script to achieve. You need to import list at first, then get value from term store, and compare with the list. Change the list field per comparison result, then add new value to term store.
    However, there might some workaround to meet your requirement. Not surly understand, so I find some references for you:
    If you would like to export Term Set to CSV from SharePoint 2013, then you could compare it:
    http://gallery.technet.microsoft.com/office/PowerShell-for-SharePoint-a838b5d0#content
    If you would like to query SharePoint 2013 Managed metadata term store using JavaScript:
    http://sharepoint.stackexchange.com/questions/60045/query-sp2013-managed-metadata-term-store
    http://stackoverflow.com/questions/13858962/getting-all-the-term-stores-in-sharepoint-2010-web-services-or-client-side-obje
    If you would like to synchronize, import or copy term store & managed metadata in SharePoint between environments:
    http://www.matthewjbailey.com/synchronize-import-or-copy-term-stores-managed-metadata-in-sharepoint/
    Regards,
    Rebecca Tu
    TechNet Community Support

  • Trigger while importing from .csv file

    hey
    i am importing data from .csv file into a table called temp.
    .csv file is having column sales. the data in that also contains some empty filed or N/A or -
    sales coulmn in my table is NUMBER.
    so while importing some column are not able to import.
    how to write a trigger to eliminate '-' or 'N/A' or ' ' values from the sales column before inserting into the table

    It might be easier if the field on temp was a varchar2 field instead?
    The values entered should be loaded into this field and you can then use the trigger to test the values and convert these into numbers or nulls before inserting onto the proper data table.
    Check out the TO_NUMBER() function in SQL for info on how to convert strings to numbers.
    Regards
    Andy

  • SQL bulk copy from csv file - Encoding

    Hi Experts
    This is the first time I am creating a PowerShell script and it is almost working. I just have some problems with the actual bulk import to SQL encoding from the text file since it replaces
    special characters with a question mark. I have set the encoding when creating the csv file but that does not seem to reflect on the actual bulk import. I have tried difference scenarios with the encoding part but I cannot find the proper solution for that.
    To shortly outline what the script does:
    Connect to Active Directory fetching all user - but excluding users in specific OU's
    Export all users to a csv in unicode encoding
    Strip double quote text identifiers (if there is another way of handling that it will be much appreciated)
    Clear all records temporary SQL table
    Import records from csv file to temporary SQL table (this is where the encoding is wrong)
    Update existing records in another table based on the records in the temporary table and insert new record if not found.
    The script looks as the following (any suggestions for optimizing the script are very welcome):
    # CSV file variables
    $path = Split-Path -parent "C:\Temp\ExportADUsers\*.*"
    $filename = "AD_Users.csv"
    $csvfile = $path + "\" + $filename
    $csvdelimiter = ";"
    $firstRowColumns = $true
    # Active Directory variables
    $searchbase = "OU=Users,DC=fabrikam,DC=com"
    $ADServer = 'DC01'
    # Database variables
    $sqlserver = "DB02"
    $database = "My Database"
    $table = "tblADimport"
    $tableEmployee = "tblEmployees"
    # Initialize
    Write-Host "Script started..."
    $elapsed = [System.Diagnostics.Stopwatch]::StartNew()
    # GET DATA FROM ACTIVE DIRECTORY
    # Import the ActiveDirectory Module
    Import-Module ActiveDirectory
    # Get all AD users not in specified OU's
    Write-Host "Retrieving users from Active Directory..."
    $AllADUsers = Get-ADUser -server $ADServer `
    -searchbase $searchbase -Filter * -Properties * |
    ?{$_.DistinguishedName -notmatch 'OU=MeetingRooms,OU=Users,DC=fabrikam,DC=com' `
    -and $_.DistinguishedName -notmatch 'OU=FunctionalMailbox,OU=Users,DC=fabrikam,DC=com'}
    Write-Host "Users retrieved in $($elapsed.Elapsed.ToString())."
    # Define labels and get specific user fields
    Write-Host "Generating CSV file..."
    $AllADUsers |
    Select-Object @{Label = "UNID";Expression = {$_.objectGuid}},
    @{Label = "FirstName";Expression = {$_.GivenName}},
    @{Label = "LastName";Expression = {$_.sn}},
    @{Label = "EmployeeNo";Expression = {$_.EmployeeID}} |
    # Export CSV file and remove text qualifiers
    Export-Csv -NoTypeInformation $csvfile -Encoding Unicode -Delimiter $csvdelimiter
    Write-Host "Removing text qualifiers..."
    (Get-Content $csvfile) | foreach {$_ -replace '"'} | Set-Content $csvfile
    Write-Host "CSV file created in $($elapsed.Elapsed.ToString())."
    # DATABASE IMPORT
    [void][Reflection.Assembly]::LoadWithPartialName("System.Data")
    [void][Reflection.Assembly]::LoadWithPartialName("System.Data.SqlClient")
    $batchsize = 50000
    # Delete all records in AD import table
    Write-Host "Clearing records in AD import table..."
    Invoke-Sqlcmd -Query "DELETE FROM $table" -Database $database -ServerInstance $sqlserver
    # Build the sqlbulkcopy connection, and set the timeout to infinite
    $connectionstring = "Data Source=$sqlserver;Integrated Security=true;Initial Catalog=$database;"
    $bulkcopy = New-Object Data.SqlClient.SqlBulkCopy($connectionstring, [System.Data.SqlClient.SqlBulkCopyOptions]::TableLock)
    $bulkcopy.DestinationTableName = $table
    $bulkcopy.bulkcopyTimeout = 0
    $bulkcopy.batchsize = $batchsize
    # Create the datatable and autogenerate the columns
    $datatable = New-Object System.Data.DataTable
    # Open the text file from disk
    $reader = New-Object System.IO.StreamReader($csvfile)
    $columns = (Get-Content $csvfile -First 1).Split($csvdelimiter)
    if ($firstRowColumns -eq $true) { $null = $reader.readLine()}
    Write-Host "Importing to database..."
    foreach ($column in $columns) {
    $null = $datatable.Columns.Add()
    # Read in the data, line by line
    while (($line = $reader.ReadLine()) -ne $null) {
    $null = $datatable.Rows.Add($line.Split($csvdelimiter))
    $i++; if (($i % $batchsize) -eq 0) {
    $bulkcopy.WriteToServer($datatable)
    Write-Host "$i rows have been inserted in $($elapsed.Elapsed.ToString())."
    $datatable.Clear()
    # Add in all the remaining rows since the last clear
    if($datatable.Rows.Count -gt 0) {
    $bulkcopy.WriteToServer($datatable)
    $datatable.Clear()
    # Clean Up
    Write-Host "CSV file imported in $($elapsed.Elapsed.ToString())."
    $reader.Close(); $reader.Dispose()
    $bulkcopy.Close(); $bulkcopy.Dispose()
    $datatable.Dispose()
    # Sometimes the Garbage Collector takes too long to clear the huge datatable.
    [System.GC]::Collect()
    # Update tblEmployee with imported data
    Write-Host "Updating employee data..."
    $queryUpdateUsers = "UPDATE $($tableEmployee)
    SET $($tableEmployee).EmployeeNumber = $($table).EmployeeNo,
    $($tableEmployee).FirstName = $($table).FirstName,
    $($tableEmployee).LastName = $($table).LastName,
    FROM $($tableEmployee) INNER JOIN $($table) ON $($tableEmployee).UniqueNumber = $($table).UNID
    IF @@ROWCOUNT=0
    INSERT INTO $($tableEmployee) (EmployeeNumber, FirstName, LastName, UniqueNumber)
    SELECT EmployeeNo, FirstName, LastName, UNID
    FROM $($table)"
    try
    Invoke-Sqlcmd -ServerInstance $sqlserver -Database $database -Query $queryUpdateUsers
    Write-Host "Table $($tableEmployee) updated in $($elapsed.Elapsed.ToString())."
    catch
    Write-Host "An error occured when updating $($tableEmployee) $($elapsed.Elapsed.ToString())."
    Write-Host "Script completed in $($elapsed.Elapsed.ToString())."

    I can see that the Export-CSV exports into ANSI though the encoding has been set to UNICODE. Thanks for leading me in the right direction.
    No - it exports as Unicode if set to.
    Your export was wrong and is exporting nothing. Look closely at your code:
    THis line exports nothing in Unicode"
    Export-Csv -NoTypeInformation $csvfile -Encoding Unicode -Delimiter $csvdelimiter
    There is no input object.
    This line converts any file to ansi
    (Get-Content $csvfile) | foreach {$_ -replace '"'} | Set-Content $csvfile
    Set-Content defaults to ANSI so the output file is converted.
    Since you are just dumping into a table by manually building a recorset why not just go direct.  You do not need a CSV.  Just dump theresults of the query to a datatable.
    https://gallery.technet.microsoft.com/scriptcenter/4208a159-a52e-4b99-83d4-8048468d29dd
    This script dumps to a datatable object which can now be used directly in a bulkcopy.
    Here is an example of how easy this is using your script:
    $AllADUsers = Get-ADUser -server $ADServer -searchbase $searchbase -Filter * -Properties GivenName,SN,EmployeeID,objectGUID |
    Where{
    $_.DistinguishedName -notmatch 'OU=MeetingRooms,OU=Users,DC=fabrikam,DC=com'
    -and $_.DistinguishedName -notmatch 'OU=FunctionalMailbox,OU=Users,DC=fabrikam,DC=com'
    } |
    Select-Object @{N='UNID';E={$_.objectGuid}},
    @{N='FirstName';Expression = {$_.GivenName}},
    @{N='LastName';Expression = {$_.sn}},
    @{N=/EmployeeNo;Expression = {$_.EmployeeID}} |
    Out-DataTable
    $AllDUsers is now a datatable.  You can just upload it.
    ¯\_(ツ)_/¯

Maybe you are looking for

  • How to run report in background, save output to word or excel

    Hello all, I have a huge report that needs to be run in background and I need the report in word. When running in Dialog it takes too long and SAP times out. How do you get something to run in background and have the output in excel. I know you can g

  • Error while using autotype task

    Hi, We are using a custom exception class which is extended from java.lang.Exception. When using with autotype weblogic ant task it gives following error. I am using weblogic 8.1 SP4 weblogic.xml.schema.binding.BindingException: No default constructo

  • Error while executing Sample XML Procedures..

    Hi, I was trying to execute DOMSAMPLE procedure from Oracle XML Developers guide to parse a xml file. domsample('C:\xml','family.xml','family.err'); I am getting the following error message. ORA-29532: Java call terminated by uncaught Java exception:

  • URGENT:Eventing between two iviews in one page

    Hi all, I have developed a model in visual composer which contains two iviews in a single page .The first iview contains the input fields and the data service.The second iview contains the output form.I should get the output in the second iview when

  • I got a software license crtificate ,how to use it??? i   paied    for it.

    I got a software license crtificate ,how to use it??? i   paied    for it.