How do I change the way powershell exports info to a CSV file.

I have successfully created a batch file that runs a powershell script in Exchange Managment Shell to extract the users that have an exchange mobile device partnership to a CSV file. The first column of my CSV file is the "Identity" which looks like this. Accounts/fred flinstone/ExchangeActiveSyncDevices/AirWatchDroid?AirWatch1070560211

It is pulling this information from AD. Is there a way to change or filter out everything from "Identity" except the username?

Here is my script.
Add-PSSnapin Microsoft.Exchange.Management.Powershell.SnapIn -ea silentlyContinue

$UserList = Get-CASMailbox -Filter {hasactivesyncdevicepartnership -eq $true -and -not displayname -like "CAS_{*"} | Get-Mailbox

$UserList | foreach { Get-MobileDeviceStatistics -Mailbox $_} | Sort Identity,DeviceType,DeviceID,FirstSyncTime,LastSuccessSync | select Identity,DeviceType,DeviceID,FirstSyncTime,LastSuccessSync | Export-Csv -Path c:\MobileDeviceCSV\ExchMobileDevice.csv –NoTypeInformation
chiefsmanSystems AdministratorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subash SundharanIT Infrastructure Architect Commented:
Try to add a custom property..

$UserList | foreach { Get-MobileDeviceStatistics -Mailbox $_} | Sort Identity,DeviceType,DeviceID,FirstSyncTime,LastSuccessSync | select @{N="User";E={($_.Identity -split "/")[-3]}},DeviceType,DeviceID,FirstSyncTime,LastSuccessSync | Export-Csv -Path c:\MobileDeviceCSV\ExchMobileDevice.csv –NoTypeInformation 

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chiefsmanSystems AdministratorAuthor Commented:
Wow!!!! Dude you are good. What a genius you are! It works exactly how I wanted now. Can you please explain what is going on exactly to display just the user name? I would like to understand how it is working. I am a novice PowerShell nut.

 @{N="User";E={($_.Identity -split "/")[-3]}},

Subash SundharanIT Infrastructure Architect Commented:
@{N="User";E={($_.Identity -split "/")[-3]}},
Above creates a custom property..
$_.Identity -split "/"
above code splits the string (identity in our case) with "/"
($_.Identity -split "/")[-3]
[-3] selects the third index value from last from the array created by split..
chiefsmanSystems AdministratorAuthor Commented:
Great! Thank you for explaining it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.