Skip to main content

Hi,

 

We have an ADExport.csv file which overnight imports users into Assyst via ETM.

 

Sometimes, a user fails to import so we manually have to import that user via ETM.

 

I’ve written a basic PowerShell script which prompts us to enter in the Email address of the user that has failed to import. Once the email address has been entered, the script then searches for that user in the ADExport.csv file. Once the user is found in the file, it copies the following file headers into a new .csv file:

 

"sAMAccountName","userPrincipalName","SID","GivenName","Description","sn","physicalDeliveryOfficeName","Department","mail","telephoneNumber","userAccountControl","MobilePhone","Manager","ManagerName","ManagersAMAccountName","extensionAttribute11","DistinguishedName"

 

The script then copies the users info found in the ADExport.csv file then pastes it into the new .csv file created above. I’ve confirmed each header has the correct info assigned.

When I import the new .csv into ETM, it shows the following error message:

 

 

If I do the exact same thing manually, the .csv file imports without any issues.

Manual Process:

  • Copy the headers from the ADExport.csv file into a new .csv file
  • Copy the users info from the ADExport.csv file into a new .csv file
  • Successfully imports into ETM

I’ve done a hexadecimal file comparison and the two files are identical but for some reason, the .csv created via the PowerShell script fails to import.

PowerShell script:

Do {

#Prompt user for input
$EmailAddressOfUser = Read-Host -Prompt "Please enter the user's email address"
""
} Until ($EmailAddressOfUser)

Do {


#This is the ADExport.csv file the script will search for the user in.

$filename = "\\Location\ADExport.csv"
} Until ($filename)

#Save file with the email address in the file name.
$saveOutputFileAs = "ADExport_$EmailAddressOfUser.csv"

#Search for sAMAccountName header in ADExport.csv
$ValueToSearchFor = "sAMAccountName"

 

$Output = select-string -path "$filename" -Pattern "$ValueToSearchFor"
$Output.line | out-file \\Location\$saveOutputFileAs -append


$Output = select-string -path "$filename" -Pattern "$EmailAddressOfUser"
$Output.line | out-file \\Location\$saveOutputFileAs -append

 

#End of script

 

The script creates the file with the data I need but I can’t figure out why It’s failing to import into ETM.

 

Would appreciate any help on this! :-)

 

Kind regards,

 

Danyal

If you open the Powershell created CSV and then try to import does that import successfully? That error seems to imply that the data is being output as a single column rather than being split into the 17 that you would expect. 

 


Hi Kevin,

 

Thanks for your response :-)

 

I tested that but unfortunately I’m still getting the same message for columns.

 

However, your suggestion helped! I separated the columns via the PowerShell script - ETM successfully imported the file.

 

I used the following in my script:

 

#Export file as a tab separated CSV file
$CSVFileTabSeparated = "TabSeparated_$EmailAddressOfUser.csv"

Import-Csv \\Location\$saveOutputFileAs -Delimiter "," | Export-Csv \\Location\$CSVFileTabSeparated -NoTypeInformation

 

This saves the original ADExport_$EmailAddressOfUser.csv file as a new tab separated CSV file - I couldn’t figure out how to save the original CSV file as a tab separated file so I’m saving it as a new file.

 

We now have a working PowerShell script which automatically imports files into ETM.

 

Thank you for your help :-)

 

Kind regards,

 

Danyal

 

 

 

 

 

 


Reply