Uplouad excel file to MDM cat. - External table isnt in the expected format
Hi expert,
We try to uploud an excel file to the SRM-MDM catalog 3.0 but when I connect to source and pick my excel file I get error message
"External table is not in the expected format".
I tried to uploud a very simple file, such as hierarchy file or supllier file.
Does anyone can help?
Thanks for your help!
Lori
1st check if you choose the File type as Excel in the Import manager !
then make sure the excel is saved as .xls extension ONLY
also check whats the version of the excel ? I mean excel 2003 , 2007 (i know these work)
thanks
-Adrivit
Similar Messages
-
How to drop external table together with the linked file
Hi,
I am running 10g and using the external table feature to move data between two databases. Now the procedure I am using has to make sure, that on the target db the external tables created on the previous run are not existing.
As far I know the statement
DROP TABLE <EXTERNAL TABLE NAME>; does not remove the file.
How to achieve the goal?
Thanks!Can you use the UTL_FILE.FRemove function to delete the underlying file? That seems like the simplest solution. Assuming, of course, that you have the appropriate privileges to do so.
Justin
Of course, I'd generally question why you're using external tables and flat files to move data between databases rather than database links, but I assume you have valid reasons for that...
Message was edited by:
Justin Cave -
Read Excel file and populate in a Table
Hi,
I have a requirement in which i have to read a Excel file and populate it thoroughly in a Table. The rows and column numbers are uncertain.
Help me on this...
Regards,
KrishHi,
I can give solution to Upload Excel file.
1)Add jxl jar folder in the lib folder of ur project.
2)Go to properties of ur project and add jar to ur project.
3)Using the File upload ui ,browse and upload the file.
4)Write the read file in to ur server location using fileoutput stream.
5)then using code u can read the excelfile from the server location itself.
Here is the code:
IWDAttributeInfo attInfo =wdContext.getNodeInfo().getAttribute("upload");
binaryType=IWDModifiableBinaryTypeattInfo.getModifiableSimpleType();
fileuploaded = binaryType.getFileName();
byte b[] = wdContext.currentContextElement().getUpload();
File filename =new File("
<Server name>\<folde name>\" + fileuploaded);
try {
FileOutputStream out = new FileOutputStream(filename);
out.write(b);
out.close();
catch (FileNotFoundException e)
e.printStackTrace();
catch (IOException e)
e.printStackTrace();
int iRows = 0;
try {
Workbook wb = null;
Sheet sheet = null;
wb = Workbook.getWorkbook(filename);
sheet = wb.getSheet(0);
int iColumns = sheet.getColumns();
iRows = sheet.getRows();
int i = 0;
for (int r = 0; r < iRows; r++)
for (int c = 0; c < iColumns; c++)
Cell cell = sheet.getCell(c, r);
characterarray<i> = cell.getContents();
i++;
wb.close();
Declare Globally
//@@begin others
String fileuploaded;
IWDModifiableBinaryType binaryType;
String characterarray[] = new String [10];
//@@end
Thanks,
Durga Rao -
Error
[Load data from excel file [1]] Error: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER. The AcquireConnection method call to the connection manager "Excel Connection Manager" failed with error code 0xC0202009. There
may be error message
I am using BIDS Microsoft Visual Studio 2008 and running the package to load the data from excel .
My machine has 32 bit excel hence have set property to RUN64BITRUNTIME AS FALSE.
But the error still occurs .
I checked on Google and many have used Delay validation property at Data flow task level to true but even using it at both excel connection manager and DFT level it doesnt work
MudassarThats my connection string
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\SrcData\Feeds\Utilization.xlsx;Extended Properties="Excel 12.0;HDR=NO";
Excel 2010 installed and its 32 bit edition
Are you referring to install this component -AccessDatabaseEngine_x64.exe?
http://www.microsoft.com/en-us/download/details.aspx?id=13255
Mudassar
You can try an OLEDB provider in that case
see
http://dataintegrity.wordpress.com/2009/10/16/xlsx/
you might need to download and install ms access redistributable
http://www.microsoft.com/en-in/download/details.aspx?id=13255
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
I have a mac os 10.5.8, i want to upgrade to mac os snow leopard, can i keep all my files (documents, music on itunes) without backing up all the files first on a external device prior to the upgrade?
I strongly advise against upgrading the OS without first making a backup. Were something to go wrong you would lose all your files without the backup. See:
How to Install OS X Updates Successfully
A. Repair the Hard Drive and Permissions:
Boot from your current OS X Installer disc. After the installer loads select your language and click on the Continue button. Then select Disk Utility from the Utilities menu. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list. In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive. If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the installer. Now restart normally.
If DU reports errors it cannot fix, then you will need Disk Warrior (4.0 for Tiger) and/or TechTool Pro (4.5.2 for Tiger) to repair the drive. If you don't have either of them or if neither of them can fix the drive, then you will need to reformat the drive and reinstall OS X.
B. Make a Bootable Backup Using Restore Option of Disk Utility:
Open Disk Utility from the Utilities folder.
Select the destination volume from the left side list.
Click on the Restore tab in the DU main window.
Check the box labeled Erase destination.
Select the destination volume from the left side list and drag it to the Destination entry field.
Select the source volume from the left side list and drag it to the Source entry field.
Double-check you got it right, then click on the Restore button.
Destination means the external backup drive. Source means the internal startup drive.
C. Important: Please read before installing:
If you have a FireWire hard drive connected, disconnect it before installing the update unless you will boot from this drive and install the update on it. Reconnect it and turn it back on after installation is complete and you've restarted.
You may experience unexpected results if you have installed third-party system software modifications, or if you have modified the operating system through other means. (This does not apply to normal application software installation.)
The installation process should not be interrupted. If a power outage or other interruption occurs during installation, use the standalone installer (see below) from Apple Downloads to update. While the installation is in progress do not use the computer.
D. To upgrade:
Purchase the Snow Leopard Retail DVD.
Boot From The OS X Installer Disc:
Insert OS X Installer Disc into the optical drive.
Restart the computer.
Immediately after the chime press and hold down the "C" key.
Release the key when the spinning gear below the dark gray Apple logo appears.
Wait for installer to finish loading.
E. If updating:
Download and install update(s)
Use Software Update, or
Download standalone updater(s). -
I am working in text edit and cannot open my file. Error message says it is in the wrong format, truncated or corrupted. what to do?
Try opening Disk Utility in your Applications-Utilities folder and repair permissions.
-
I am working on SharePoint 2010 Infopath form, i have created one secondary connection to SharePoint List view using XML Connection it works fine.
For the deployment from DEV to PROD i converted this connection to universal data connection (UDC) and tested this before deploying to PROD but i m getting below error.
An error occurred querying a data source.
i checked ULS logs and found below details
Data adapter failed during OnLoad: The UDC file contains errors: '=' is an unexpected token. The expected token is ';'. Line 17, position 108.
UDC file is below
<?xml version="1.0" encoding="UTF-8"?>
<?MicrosoftWindowsSharePointServices ContentTypeID="0x010100B4CBD48E029A4ad8B62CB0E41868F2B0"?>
<udc:DataSource MajorVersion="2" MinorVersion="0" xmlns:udc="http://schemas.microsoft.com/office/infopath/2006/udc">
<udc:Name>LastItemID</udc:Name>
<udc:Description>Format: UDC V2; Connection Type: XmlQuery; Purpose: ReadOnly; Generated by Microsoft InfoPath 2010 on 2014-04-25 at 16:49:31 by DOMAIN\username.</udc:Description>
<udc:Type MajorVersion="2" MinorVersion="0" Type="XmlQuery">
<udc:SubType MajorVersion="0" MinorVersion="0" Type=""/>
</udc:Type>
<udc:ConnectionInfo Purpose="ReadOnly" AltDataSource="">
<udc:WsdlUrl/>
<udc:SelectCommand>
<udc:ListId/>
<udc:WebUrl/>
<udc:ConnectionString/>
<udc:ServiceUrl UseFormsServiceProxy="false"/>
<udc:SoapAction/>
<udc:Query>https://contoso/_vti_bin/owssvr.dll?Cmd=Display&List={32364DED-7FE3-4276-837C-F2AC62C04B81}&View={804CC528-34B2-4473-89DB-C4E766CACC95}&XMLDATA=TRUE&NOREDIRECT=TRUE</udc:Query>
</udc:SelectCommand>
<udc:UpdateCommand>
<udc:ServiceUrl UseFormsServiceProxy="false"/>
<udc:SoapAction/>
<udc:Submit/>
<udc:FileName>Specify a filename or formula</udc:FileName>
<udc:FolderName AllowOverwrite=""/>
</udc:UpdateCommand>
<!--udc:Authentication><udc:SSO AppId='' CredentialType='' /></udc:Authentication-->
</udc:ConnectionInfo>
</udc:DataSource>
w: sandippatilblog.blogspot.com/Hi Sandip ,
How about escape “&” to “&” as below:
<udc:Query>https://contoso/_vti_bin/owssvr.dll?Cmd=Display&List={32364DED-7FE3-4276-837C-F2AC62C04B81}&View={804CC528-34B2-4473-89DB-C4E766CACC95}&XMLDATA=TRUE&NOREDIRECT=TRUE</udc:Query>
Reference:
http://social.technet.microsoft.com/Forums/en-US/534fae6b-2cef-4947-86e2-4869cb291cfe/the-form-cannot-be-opened-because-it-requires-the-domain-permission-level-log-id-5566-error?forum=sharepointcustomizationlegacy
http://stackoverflow.com/questions/3493405/do-i-really-need-to-encode-as-amp
Best Regards,
Eric
Eric Tao
TechNet Community Support -
DATE fields and LOG files in context with external tables
I am facing two problems when dealing with the external tables feature in Oracle 9i.
I created an External Table with some fileds with the DATE data type . There were no issues during the creation part. But when i query the table, the DATE fields are not properly selected though the data is there in the files. Is there any ideas to deal with this ?
My next question is regarding the log files. The contents in the log file seems to be growing when querying the external tables. Is there a way to control this behaviour?
Suggestions / Advices on the above two issues are welcome.
Thanks
LakshminarayananHi
If you have date datatypes than:
select
greatest(TABCASER1.CASERRECIEVEDDATE, EVCASERS.FINALEVDATES, EVCASERS.PUBLICATIONDATE, EVCASERS.PUBLICATIONDATE, TABCASER.COMPAREACCEPDATE)
from TABCASER, TABCASER1, EVCASERS
where ...-- join and other conditions
1. greatest is good enough
2. to_date creates date dataype from string with the format of format string ('mm/dd/yyyy')
3. decode(a, b, c, d) is a function: if a = b than return c else d. NULL means that there is no data in the cell of the table.
6. to format the date for display use to_char function with format modell as in the to_date function.
Ott Karesz
http://www.trendo-kft.hu -
Attach an Excel File with Email for External Email Address
Hi,
I want to send an excel file to an external email address as an attachement.
I am using the function module SO_NEW_DOCUMENT_ATT_SEND_API1 for sending the email.
But as far as I know we can only create and send the excel file in this FM. e.g. we can put the text manually and name the file as excel and add it as packing list and send the document.
Now, my client has a template in excel/word which he wants to send as an attachment always when he sends the mail. I have below Queries:
1. Where and how do i store the template which is in Excel or word? He doesnt want to upload the template each time he runs the report. Can I save the file on AL11? how do i insert the file in this?
2. I have tried standard texts, but his template contains a logo. So, I am not sure if that would work. Can I send the template in Binary and just aapend the file extension? xls or doc? would that do?Hi,
See if you can matintain the required templates in document management and use them in your reports.
Try the link below for reference.
[Document Management|http://wiki.sdn.sap.com/wiki/display/PLM/Templates-Document+Management]]
Regards,
Booma -
Import Excel File Data into oracle database table.
HI,
i want to insert data into a specific table from a excel file. please help me..
for example
emp.xls file's data need to be import in emp database table.
thanks in advance...Hi,
to all knowledgable person, this would be gald for u all that i have solved the problem.
through this procedure..
PROCEDURE IMPORT_FROM_EXCEL_PROC (as_FileName VARCHAR2, exe_name varchar2) IS
appid PLS_INTEGER;
convid PLS_INTEGER;
docid PLS_INTEGER;
conv_established BOOLEAN := FALSE;
buffer VARCHAR2(100);
Emp_code VARCHAR2(100);
Emp_name VARCHAR2(100);
Emp_desig VARCHAR2(100);
Emp_Salary VARCHAR2(100);
ls_error VARCHAR2(1000);
li_row integer;
li_col integer;
li_error_count integer;
li_load_count integer;
BEGIN
--Start Excel
--This line assumes that Excel is in the specified directory
-- APPID := DDE.APP_BEGIN('D:\OFFICE11\EXCEL.EXE',DDE.APP_MODE_MINIMIZED);
APPID := DDE.APP_BEGIN(exe_name,DDE.APP_MODE_MINIMIZED);
--Establish a conversation with Excel
--The following loop will not end until a conversation with Excel
--has been established. Therefore, it can result in a endless loop,
--so use with caution.
WHILE NOT conv_established LOOP
BEGIN
convid := DDE.INITIATE('excel', 'system');
conv_established := TRUE;
EXCEPTION
WHEN DDE.DMLERR_NO_CONV_ESTABLISHED THEN
conv_established := FALSE;
END;
END LOOP;
--Open Excel document
--This assumes that you have an Excel spreadsheet named ddetest.xls in the root of c:
DDE.EXECUTE(convid, '[Open("'||as_FileName||'")]', 10000);
--Initiate conversation with Excel document
docid := DDE.INITIATE('excel',as_FileName);
--Begin transfer from Excel to Forms
li_load_count := 0;
li_error_count := 0;
li_col := 1;
li_row := 2;
GO_BLOCK('IMPORT_XLS');
DDE.REQUEST (docid, 'R' || TO_CHAR(li_row) || 'C' || TO_CHAR(li_col), buffer, DDE.CF_TEXT, 1000);
WHILE length(buffer) > 2 LOOP
WHILE li_col < 5 LOOP
buffer := substr(buffer, 1, instr(buffer, chr(10)) - 2);
IF li_col = 1 THEN --Emp_code
Emp_code := buffer;
ELSIF li_col = 2 THEN --Emp_name
Emp_name := buffer;
ELSIF li_col = 3 THEN --Emp_desig
Emp_desig := buffer;
ELSE --Emp_salary
Emp_salary := buffer;
END IF;
IF nvl(ls_error,'N') = 'N' THEN
li_col := li_col + 1;
DDE.REQUEST (docid, 'R' || TO_CHAR(li_row) || 'C' || TO_CHAR(li_col), buffer, DDE.CF_TEXT, 1000);
ELSE
li_col := 5;
END IF;
END LOOP;
IF nvl(ls_error, 'N') = 'N' THEN
li_load_count := li_load_count + 1;
IF li_load_count = 1 THEN
FIRST_RECORD;
ELSE
NEXT_RECORD;
END IF;
:IMPORT_XLS.Emp_code := Emp_code;
:IMPORT_XLS.Emp_name := Emp_name;
:IMPORT_XLS.Emp_desig := Emp_desig;
:IMPORT_XLS.Emp_salary := Emp_salary;
ELSE
li_error_count := li_error_count + 1;
DDE.POKE(docid, 'R' || TO_CHAR(li_row) || 'C5', ls_error, DDE.CF_TEXT, 10000);
END IF;
ls_error := '';
Emp_code := '';
Emp_name := '';
Emp_desig := '';
Emp_salary := '';
li_col := 1;
li_row := li_row + 1;
DDE.REQUEST (docid, 'R' || TO_CHAR(li_row) || 'C' || TO_CHAR(li_col), buffer, DDE.CF_TEXT, 1000);
END LOOP;
IF li_error_count > 0 THEN
DDE.EXECUTE(convid, '[[save]]', 10000);
Message(TO_CHAR(li_load_count) || ' Record(s) Loaded. ' ||
TO_CHAR(li_error_count) || ' Invalid Record(s). See error in excel file.');
ELSE
Message(TO_CHAR(li_load_count) || ' Record(s) Successfully Loaded.');
END IF;
--End transfer to Excel
DDE.TERMINATE(docid);
DDE.TERMINATE(convid);
DDE.APP_END(appid);
--Handle exceptions
EXCEPTION
WHEN DDE.DDE_APP_FAILURE THEN
MESSAGE('WINDOWS APPLICATION CANNOT START.');
WHEN DDE.DDE_PARAM_ERR THEN
MESSAGE('A NULL VALUE WAS PASSED TO DDE');
WHEN DDE.DMLERR_NO_CONV_ESTABLISHED THEN
MESSAGE('DDE CANNOT ESTABLISH A CONVERSATION');
WHEN DDE.DMLERR_NOTPROCESSED THEN
MESSAGE('A TRANSACTION FAILED');
END; -
Regarding Copying of Data From Excel file to Web Dynpro Java Table
Hi
Can any body give Suggestions that is how to copy or import Row and Column Values in the Excel file to the Java Web Dynpro Table
Regards
Chandran SHi,
First u should include jxl.jar API in ur classpath.
ind a Resource variable to FileUpload UI. Then from the Fileupload UI, u can get the Sheet variable as
InputStream fis=wdContext.currentFileUploadElement().getResource().read(true);
Workbook wb=Workbook.getWorkbook(fis);
Sheet sh=wb.getSheet(0);
This can be easily read to a table by
for(int i=14;i<34;i++)
String bId=sh.getCell(2,i).getContents();
String cId=sh.getCell(3,i).getContents();
String subj=sh.getCell(4,i).getContents();
IPrivate<View>.I<Table>Element el=wdContext.node<Table>().create<Table>Element();
wdContext.node<Table>().addElement(el);
el.setBID(bid);
el.setCID(cid);
el.setSUB(subj);
This example reads the excel from row 13 to 32 and column 3 to 5 and uploaded to a table
Regards
Fahad Hamsa -
Accesing windows files using oracle unix external tables.
Hi, I'm trying to access files on windows2k using oracle external tables on unix:
Oracle server on unix: oracle ver. is 9.2.0.6 and OS is 5.8 Generic_117000-03 sun4u sparc SUNW,Sun-Fire
1. Created dir object on oracle unix pointing to windows path
2. created user
3. Assigned read and write privs on dir to user
4. created external table using dir step 1
5. select on external table
When I FTP the files into unix and recreate dir object, it works, but if I point dir object into windows path, it fails.
Is possible to do this?
Tks
GAPHi
The directory object must be accesible to your Database server, so if the Database is in unix you must create the directory in unix.
I don´t know software that allow unix systems to see a windows file system. Maybe windows can see unix from a samba server or NFS. -
Upload file to read as external table from client to DB server using webutil
Hi I was wondering if this is possible
The requirement is I need to up load a comaseprate file to db server from client, so to read this fie as an external table
When we have doing is to create a samba share on the DB server and just do a copy to the network share and consequentially read the file in to the database
My environment - Forms 11R2 and 11g2
Can this be done using webutil ( from client to db server
Thanks nad regardsHi thanks for the reply!
Currently the application runs with a samba share, we need to get read of this share and directly load the file to DB server (on unix file system, then there wont be much changes to the existing code), is this possible?
Ells I was thinking the same as you say just load the file in to the database and do some other PL/Sql or shell scripts to do the rest of the operation. it would be better to use a PL/Sql via a trigger I believe unfortunately I am not an Pl/Sql programmer ((, guess one of our developers need to find the coding part ))
Appreciate if you can give me some example like
Thanks and best regards -
Move Excel files (400GB) from an external VPS service to Azure file storage
We are currently using an external VPS service to store 400GB Excel data in multiple files (approx 5000 files stored under 400 directories). Each directory refers to a region and user data within region.
Would like to copy all files from VPS to Azure storage account. Any thoughts on the best and most efficient way to accomplish this.
Thanks
MikeHi Manu
Thanks. Once the files are moved to Azure, how do I work on the excel files online? The idea here is to discontinue the third party VPS once all files are moved to Azure successfully.
If you read this old thread published in 2010, it looks like excel files cannot be read in Azure unless one uses OpenXML or OpenExcel.
https://social.msdn.microsoft.com/Forums/azure/en-US/95127eea-2e76-4d69-8050-65410598860c/reading-excel-file-from-azure-blob-storage-in-worker-role?forum=windowsazuredata
Thanks
Mike -
Please help me to get this done!....Thanks in Advance
This is current script I use to update AD record but its taking user id to pick the user in AD, which is some time give error not update properly..
# UpdateUsers.ps1
# PowerShell program to update Active Directory users from the information in a
# Microsoft Excel spreadsheet. Only single-valued string attributes supported.
# Author: Richard Mueller
# PowerShell Version 1.0
# September 12, 2011
Trap
If ("$_".StartsWith("Cannot load COM type Excel.Application"))
"Excel application not found, program aborted"
Add-Content -Path $LogFile -Value "## Excel application not found"
Add-Content -Path $LogFile -Value " $_"
Add-Content -Path $LogFile -Value $("Program aborted: " + (Get-Date).ToString())
Break
If (("$_".StartsWith("Exception has been thrown")) -and ($Step -eq "4"))
"Excel spreadsheet not found, program aborted"
Add-Content -Path $LogFile -Value "## Excel spreadsheet not found: $ExcelPath"
Add-Content -Path $LogFile -Value " $_"
Add-Content -Path $LogFile -Value $("Program aborted: " + (Get-Date).ToString())
Break
If ("$_".StartsWith("The server is not operational"))
"Domain Controller not found, program aborted"
Add-Content -Path $LogFile -Value "## Domain Controller not found"
Add-Content -Path $LogFile -Value " $_"
Add-Content -Path $LogFile -Value $("Program aborted: " + (Get-Date).ToString())
Break
If ("$_".StartsWith("The directory service is unavailable"))
"Active Directory not found, program aborted"
Add-Content -Path $LogFile -Value "## Active Directory not found"
Add-Content -Path $LogFile -Value " $_"
Add-Content -Path $LogFile -Value $("Program aborted: " + (Get-Date).ToString())
Break
If ("$_".StartsWith("The specified domain"))
"Domain not found, program aborted"
Add-Content -Path $LogFile -Value "## Domain not found"
Add-Content -Path $LogFile -Value " $_"
Add-Content -Path $LogFile -Value $("Program aborted: " + (Get-Date).ToString())
Break
"Unexpected error: $_"
Add-Content -Path $LogFile -Value "## Unexpected error: $_"
Add-Content -Path $LogFile -Value " Step: $Step"
Break
Function CleanUp
Trap
"Error during cleanup: $_"
Add-Content -Path $LogFile -Value "## Error during cleanup: $_"
$Script:Errors = $Script:Errors + 1
Continue
# Function to release Excel objects from memory.
Do {$x = [System.Runtime.InteropServices.Marshal]::ReleaseComObject($Columns)} While ($x -gt -1)
Do {$x = [System.Runtime.InteropServices.Marshal]::ReleaseComObject($Rows)} While ($x -gt -1)
Do {$x = [System.Runtime.InteropServices.Marshal]::ReleaseComObject($Range)} While ($x -gt -1)
Do {$x = [System.Runtime.InteropServices.Marshal]::ReleaseComObject($Sheet)} While ($x -gt -1)
Do {$x = [System.Runtime.InteropServices.Marshal]::ReleaseComObject($Worksheets)} While ($x -gt -1)
$Workbook.Close($False)
Do {$x = [System.Runtime.InteropServices.Marshal]::ReleaseComObject($Workbook)} While ($x -gt -1)
Do {$x = [System.Runtime.InteropServices.Marshal]::ReleaseComObject($Workbooks)} While ($x -gt -1)
$Excel.Quit()
Do {$x = [System.Runtime.InteropServices.Marshal]::ReleaseComObject($Excel)} While ($x -gt -1)
# Specify paths to spreadsheet and log file.
$Script:Errors = 0
$Step = "1"
$ExcelPath = "c:\scripts\UpdateUsers.xls"
$LogFile = "c:\scripts\UpdateUsers.log"
Write-Host "Please Standby..."
# Add to the log file.
$Step = "2"
Add-Content -Path $LogFile -Value "------------------------------------------------" -ErrorAction Stop
Add-Content -Path $LogFile -Value "UpdateUsers.ps1 Version 1.0 (September 12, 2011)"
Add-Content -Path $LogFile -Value $("Started: " + (Get-Date).ToString())
Add-Content -Path $LogFile -Value "Spreadsheet: $ExcelPath"
Add-Content -Path $LogFile -Value "Log file: $LogFile"
$Step = "3"
# Open specified Excel spreadsheet.
$Excel = New-Object -ComObject "Excel.Application"
$Workbooks = $Excel.Workbooks
$Step = "4"
$Workbook = $Workbooks.Open($ExcelPath)
$Worksheets = $Workbook.Worksheets
$Sheet = $Worksheets.Item(1)
$Range = $Sheet.UsedRange
$Rows = $Range.Rows
$Columns = $Range.Columns
$Step = "5"
# Hash table of attribute syntaxes.
# The LDAP display names will be read from the spreadsheet.
# The corresponding syntaxes will be read from the Schema container.
$Attributes = @{}
# Array of spreadsheet column headings.
$Cols = @()
$Step = "6"
# Read attribute LDAP Display Names from the first row of the spreadsheet.
$ID = 0
For ($k = 1; $k -le $Columns.Count; $k = $k + 1)
# Retrieve column heading, the lDAPDisplayName of an attribute.
$Value = $Sheet.Cells.Item(1, $k).Text
# Keep track of all column headings.
$Cols += $Value
# Skip duplicates in hash table.
If ($Attributes.ContainsKey($Value) -eq $False)
# Default is "NotFound", until found in the AD Schema.
$Attributes.Add($Value, "NotFound")
# Keep track of which column uniquely identifies users.
If ($Value.ToLower() -eq "distinguishedname") {$ID = $k}
If (($Value.ToLower() -eq "samaccountname") -and ($ID -eq 0)) {$ID = $k}
# This script cannot be used to rename users.
If ($value.ToLower() -eq "cn")
Add-Content -Path $LogFile -Value "## This script cannot be used to rename users"
Add-Content -Path $LogFile -Value " Do not specify the cn attribute in the spreadsheet"
Add-Content -Path $LogFile -Value $("Program aborted: " + (Get-Date).ToString())
CleanUp
Return "Program aborted: cn attribute found in spreadsheet" `
+ "`nSee log file: $LogFile"
$Step = "7"
If ($ID -eq 0)
Add-Content -Path $LogFile -Value "## No column found to identify users"
Add-Content -Path $LogFile -Value " One column must be distinguishedName or sAMAccountName"
Add-Content -Path $LogFile -Value $("Program aborted: " + (Get-Date).ToString())
CleanUp
Return "Program aborted: No column found in spreadsheet to identify users" `
+ "`nSee log file: $LogFile"
# Create filter to query for attributes in the schema.
$Attrs = $Attributes.Keys
$Filter = "(&(objectCategory=AttributeSchema)(|"
ForEach ($Attr In $Attrs)
$Filter = $Filter + "(lDAPDisplayName=$Attr)"
$Filter = $Filter + "))"
$Step = "8"
$RootDSE = [System.DirectoryServices.DirectoryEntry]([ADSI]"LDAP://RootDSE")
$Domain = $RootDSE.Get("defaultNamingContext")
$Schema = $RootDSE.Get("schemaNamingContext")
$Step = "9"
# Use the NameTranslate object.
$objTrans = New-Object -comObject "NameTranslate"
$objNT = $objTrans.GetType()
# Initialize NameTranslate by locating the Global Catalog.
$objNT.InvokeMember("Init", "InvokeMethod", $Null, $objTrans, (3, $Null))
$Step = "10"
# Retrieve NetBIOS name of the current domain.
$objNT.InvokeMember("Set", "InvokeMethod", $Null, $objTrans, (1, "$Domain"))
$NetBIOSDomain = $objNT.InvokeMember("Get", "InvokeMethod", $Null, $objTrans, 3)
Add-Content -Path $LogFile -Value "NetBIOS name of domain: $NetBIOSDomain"
$Step = "11"
$Searcher = New-Object System.DirectoryServices.DirectorySearcher
$Searcher.SearchRoot = [ADSI]"LDAP://$Schema"
$Searcher.PageSize = 200
$Searcher.SearchScope = "subtree"
$Searcher.PropertiesToLoad.Add("lDAPDisplayName") > $Null
$Searcher.PropertiesToLoad.Add("attributeSyntax") > $Null
$Searcher.PropertiesToLoad.Add("isSingleValued") > $Null
$Searcher.PropertiesToLoad.Add("systemFlags") > $Null
# Filter on specified attributes.
$Searcher.Filter = $Filter
$Step = "12"
# Query Active Directory.
$Results = $Searcher.FindAll()
# Enumerate recordset.
ForEach ($Result In $Results)
# Retrieve properties of attributes.
$Name = $Result.Properties.Item("lDAPDisplayName")[0]
$SysFlags = $Result.Properties.Item("systemFlags")[0]
$SyntaxNum = $Result.Properties.Item("attributeSyntax")[0]
$SingleValued = $Result.Properties.Item("isSingleValued")[0]
# Only single-valued string attributes supported by this version of the program.
Switch ($SyntaxNum)
"2.5.5.12" {$Syntax = "String"}
Default {$Syntax = "NotSupported"}
If ($Name.ToLower() -eq "distinguishedname") {$Syntax = "DN"}
If (($SysFlags -band 4) -ne 0)
$Attributes[$Name] = "Constructed"
Else
If ($SingleValued -eq $True)
$Attributes[$Name] = $Syntax
Else
$Attributes[$Name] = "NotSupported"
$Step = "13"
# Check if any attributes not found or have unsupported syntax.
$Found = $True
ForEach ($Attr In $Attrs)
$Syntax = $Attributes[$Attr]
If ($Syntax -eq "NotFound")
Add-Content -Path $LogFile -Value "## Attribute $Attr not found in schema"
"Attribute $Attr not found in schema"
$Found = $False
If ($Syntax -eq "NotSupported")
Add-Content -Path $LogFile -Value "## Attribute $Attr has a syntax that is not supported"
"Attribute $Attr has a syntax that is not supported"
$Found = $False
If ($Syntax -eq "Constructed")
Add-Content -Path $LogFile -Value "## Attribute $Attr is operational, so is not supported"
"Attribute $Attr is operational, so is not supported"
$Found = $False
$Step = "14"
If ($Found -eq $False)
Add-Content -Path $LogFile -Value $("Program aborted: " + (Get-Date).ToString())
CleanUp
Return "Program aborted" `
+ "`nSee log file: $LogFile"
# Read remaining rows of the spreadsheet, until the first blank value is found
# in the column that identifies users.
$Step = "15"
$Script:Updated = 0
$Script:Unchanged = 0
$j = 2
Do {
# Retieve ID value for the user first.
$Value = $Sheet.Cells.Item($J, $ID).Text
$Found = $False
$Step = "16"
If ($Cols[$ID - 1] -eq "distinguishedname")
# Any forward slash characters must be escaped.
$DN = $Value.Replace("/", "\/")
# Bind to the user object.
# If user not found, $User.Name will be $Null.
$User = [ADSI]"LDAP://$DN"
If ($User.Name -ne $Null)
$Found = $True
$Step = "17"
If ($Cols[$ID - 1] -eq "samaccountname")
Trap
Write-Host ""
"Error translating name: $_"
Add-Content -Path $LogFile -Value "## Error translating name $Value"
Add-Content -Path $LogFile -Value " Description: $_"
$Script:Errors = $Script:Errors + 1
Continue
# Convert sAMAccountName to distinguishedName.
$DN = ""
$Step = "18"
$objNT.InvokeMember("Set", "InvokeMethod", $Null, $objTrans, (3, "$NetBIOSDomain$Value"))
$DN = $objNT.InvokeMember("Get", "InvokeMethod", $Null, $objTrans, 1)
$Step = "19"
If ($DN -ne "")
$Step = "20"
# Any forward slash characters must be escaped.
$DN = $DN.Replace("/", "\/")
# Bind to the user object.
$User = [ADSI]"LDAP://$DN"
$Found = $True
If ($Found -eq $True)
$Step = "21"
# Read remaining values for this user.
$Changed = $False
For ($k = 1; $k -le $Columns.Count; $k = $k + 1)
# Skip the identifying column.
If ($k -ne $ID)
$Step = "22"
# Retrieve attribute name for this column from array.
$AttrName = $Cols[$k - 1]
# Retrieve attribute syntax from hash table.
$Syntax = $Attributes[$AttrName]
$Step = "23"
# Retrieve attribute value for this user.
$Value = $Sheet.Cells.Item($j, $k).Text
# Skip blank values.
If ($Value -ne "")
If ($Syntax -eq "String")
Trap
If ("$_".StartsWith("The directory property cannot be found"))
Continue
Else
Write-Host ""
"Error retrieving value from Active Directory: $_"
Add-Content -Path $LogFile -Value "## Error retrieving $AttrName for user $DN"
Add-Content -Path $LogFile -Value " Description: $_"
$Script:Errors = $Script:Errors + 1
Continue
$Step = "24"
# Single-valued string attribute.
# Retrieve existing value.
$OldValue = ""
$OldValue = $User.Get($AttrName)
# Check if existing value to be deleted.
If ($Value.ToLower() -eq ".delete")
If ($OldValue -ne "")
If ($AttrName.ToLower -eq "samaccountname")
Add-Content -Path $LogFile -Value `
"## Mandatory attribute sAMAccountName cannot be cleared for user: $DN"
$Script:Errors = $Script:Errors + 1
Else
Trap
Write-Host ""
"Error deleting value from Active Directory: $_"
Add-Content -Path $LogFile -Value "## Error deleting $AttrName for user $DN"
Add-Content -Path $LogFile -Value " Description: $_"
$Script:Errors = $Script:Errors + 1
Continue
$Step = "25"
# Make the attribute value "not set".
$User.PutEx(1, $AttrName, 0)
$Changed = $True
Else
$Step = "26"
# Check if new value from spreadsheet different.
If ($Value -ne $OldValue)
Trap
Write-Host ""
"Error assigning value from Active Directory: $_"
Add-Content -Path $LogFile -Value "## Error assigning $AttrName for user $DN"
Add-Content -Path $LogFile -Value " Description: $_"
$Script:Errors = $Script:Errors + 1
Continue
# Assign the new value to the attribute.
$User.Put($AttrName, $Value)
$Changed = $True
Else
# Unexpected error.
Add-Content -Path $LogFile -Value `
"## Unexpected syntax: $Syntax for attribute $AttrName for user $DN"
$Script:Errors = $Script:Errors + 1
If ($Changed -eq $True)
Trap
Write-Host ""
"Error saving to Active Directory: $_"
Add-Content -Path $LogFile -Value "## Error saving to AD for user $DN"
Add-Content -Path $LogFile -Value " Description: $_"
$Script:Errors = $Script:Errors + 1
$Script:Updated = $Script:Updated - 1
Continue
$User.SetInfo()
Add-Content -Path $LogFile -Value "Update user: $DN"
Write-Host "." -NoNewLine
$Script:Updated = $Script:Updated + 1
Else
Add-Content -Path $LogFile -Value "User unchanged: $DN"
Write-Host "." -NoNewLine
$Script:Unchanged = $Script:Unchanged + 1
Else
Add-Content -Path $LogFile -Value "## User not found: $Value"
Write-Host "." -NoNewLine
$Script:Errors = $Script:Errors + 1
$j = $J + 1
} Until ($Sheet.Cells.Item($j, $ID).Text -eq "")
$Step = "27"
CleanUp
Add-Content -Path $LogFile -Value $("Finished: " + (Get-Date).ToString())
Add-Content -Path $LogFile -Value "Number of users updated: $Script:Updated"
Add-Content -Path $LogFile -Value "Number of users unchanged: $Script:Unchanged"
Add-Content -Path $LogFile -Value "Number of errors: $Script:Errors"
Write-Host ""
"Done"
"Number of errors: $Script:Errors"
"See log file: $LogFile"Actually scripts run fine with excel file, currently we are using user-id to pick to update AD. Now we want to update AD use employee id. You can say to identify the record in AD through employee ID instead of user-id.
I do not think you will get anyone here to fix that for you. You need to find someone who knows PowerShell to help you or learn PowerShell your self.
I would fix it for you but not for free. It is too oddly designed and has too many dependencies. Any small change is likely to break it.
¯\_(ツ)_/¯
Maybe you are looking for
-
Error while rman recovery of database
We are using rman recovery for database clone. I am getting the following error, restoring datafile 00442 to /d05/u10/oracle/ndevdata/applsysd06.dbf channel dup1: reading from backup piece /db05/PROD_BACKUPS/inc0_dPROD_u1bku1pnr_t702605051_s15403_p1
-
Hello I have a lot of experience with iDVD and have used it to create many slide show/music DVDs but have never worked with iMovie. My son recently created a DVD from a VHS tape which had been created from old 8mm movies. I now want to edit that DVD
-
Incompatibility between iTunes 11.1.3 and Apple TV?
Up until a few days ago, our 3rd generation Apple TV, purchased in August 2013, permitted home sharing with our iTunes music library without any problem. After having gone through every troubleshooting suggestion, we can no longer access the iTunes l
-
How to display the special character ' ' ?
I have defined a button with the name '|<<', but in the runtime, it's displayed as '|< ;< ;', then how can i display '<' in runtime? Message was edited by: bo wang
-
IPhone 3G randomly plays song list, can't stop it
My iPhone 3G has recently stopped playing albums or playlists sequentially. It goes into a random shuffle mode, though there isn't any apparent icon that states it's in random mode. How do I stop this so I can listen an album straight through?