I have a need for a very strict CSV export for a COTS package I am trying to create an automated user load for.
The import utility by the vendor can only have double quotes around values that contain special characters, and nothing else.
So basically, every pscustomobject I’ve created then is a stopper, since the output is enclosed in " " whether the object is empty (I could use $null here), or adding a Get-ADuser property.
Unfortuantely, Export-CSV outputs double quotes around EVERYTHING. Is there a way around this, say, to only have the DISPLAYNAME object contain double quotes?
[pre]
$destinationCSV = “C:\Temp\export.csv”
‘OU=Users, OU=redacted1, OU=blue, OU=tree, OU=oranges, OU=Agencies, DC=business, DC=net’, ‘OU=Users,OU=redacted2,OU=brown,OU=stick,OU=oranges,OU=Agencies,DC=business,DC=net’, ‘OU=Users,OU=redacted3,OU=5030,OU=leaf,OU=grapes,OU=Agencies,DC=business,DC=net’ | ForEach-Object { Get-ADUser -SearchBase $_ -filter { Enabled -eq $true } -properties samaccountname, givenname, surname, displayname, usdaeauthID, mail, telephonenumber, title, manager, streetAddress, physicalDeliveryOfficeName, state, postalCode, c, l, description |
Select-Object samaccountname, givenname, surname, displayname, authID, mail, telephonenumber, title, @{ Name = ‘manager’; Expression = { (Get-ADUser $.Manager).Name } }, @{ n = ‘StreetAddress’; e = { $.streetaddress -replace "n", ", " } }, physicalDeliveryOfficeName, state, postalCode, c, l, description } |
foreach {
[pscustomobject]@{
MAXPERUSER_STATUS = “ACTIVE”
STATUSDATE = “”
USERID = $.samaccountname
PASSWORDCHECK = “Redacted!”
PASSWORDINPUT = “Redacted!”
GROUPNAME = “”
FIRSTNAME = $.givenname
LASTNAME = $.surname
DISPLAYNAME = $.displayname
DEFSITE = “ENG”
EMAILPSWD = “0”
INACTIVESITES = “0”
LOGINID = $.authID
LOCATIONORG = “TEST”
PERSONID = $.samaccountname
POSTALCODE = $.postalcode
PRIMARYEMAIL = $.mail
PRIMARYPHONE = $.telephonenumber
ADDRESSLINE1 = $.streetAddress -join “;”
ADDRESSLINE2 = $.physicalDeliveryOfficeName
ADDRESSLINE3 = “”
BILLTOADDRESS = “”
BIRTHDATE = “”
CALTYPE = “”
CITY = $.l
COUNTRY = $.c
COUNTY = “”
DEPARTMENT = $.description
EMPLOYEETYPE = “”
EXTERNALREFID = “”
HIREDATE = “”
LASTEVALDATE = “”
LOCATION = “”
REGIONDISTRICT = “”
STATEPROVINCE = $.state
SUPERVISOR = “”
TERMINATIONDATE = “”
TITLE = $.title
MEMO = “”
PASSWORD = “”
PWEXPIRATION = “”
PWHINTANSWER = “”
PWHINTQUESTION = “”
} | Export-Csv -Delimiter “,” $destinationCSV -Append -NoTypeInformation
}
#Add mandatory “header” for MIF to import correctly
$oldCSV = Get-Content $destinationCSV
Set-Content -Path $destinationCSV -Value “EXTSYS1,MXPERUSERInterface,EN”
Add-Content -Path $destinationCSV -Value $oldCSV
[/pre]