Here is the current script I have which produces the results I want but since individuals have multiple devices (iphone, ipad, android, windows phone etc) the results have there name on multiple rows. I can save the csv to macro enabled workbook and run script that removes duplicates and put in format I want, but can anyone show me how to do this in powershell?
$mobilecollection = @()
$mobiledevice = Get-MobileDevice -ResultSize Unlimited
Foreach-Object {
$mobiledevice | %{
$objdevice = "" | Select-Object UserDisplayName,DeviceType,DeviceModel,DeviceUserAgent
$objdevice.UserDisplayName = $_.UserDisplayName.substring(37)
$objdevice.DeviceType = $_.DeviceType
$objdevice.DeviceModel = $_.DeviceModel
$objdevice.DeviceUserAgent = $_.DeviceUserAgent
$mobilecollection += $objdevice
}
}
$mobilecollection | Export-Csv -NoType "D:\Scripts\GAD\SAReports\ALL-MOBILE.csv"
Current Output looks like this:
UserDisplayName | DeviceType | DeviceModel | DeviceUserAgent | |
afrances | iPhone | iPhone6C1 | Apple-iPhone6C1/1102.511 | |
agoodair | iPad | iPad2C7 | Apple-iPad2C7/1101.501 | |
ajensen1 | iPhone | iPhone5C1 | Apple-iPhone5C1/1101.501 | |
ajoseph2 | Android | SAMSUNG-SGH-I337 | TouchDown(MSRPC)/8.1.00052/ENCRYPTDEVICE,ENCRYPTSD | |
amantill | iPhone | iPhone5C1 | Apple-iPhone5C1/1101.501 | |
amunoz | iPhone | iPhone5C2 | Apple-iPhone5C2/1101.501 | |
aparker2 | iPhone | iPhone5C2 | Apple-iPhone5C2/1101.465 | |
apeshevs | iPhone | iPhone | Apple-iPhone4C1/901.406 | |
apoon2 | iPhone | iPhone3C1 | Apple-iPhone3C1/1101.501 | |
apoon2 | iPhone | iPhone5C2 | Apple-iPhone5C2/1101.501 | |
arhodes | iPhone | iPhone5C1 | Apple-iPhone5C1/1101.501 | |
asemizia | Android | Galaxy Nexus | Android/MIAndroidEmail-4.2.1-1.1.0.1 | |
asorrent | iPhone | iPhone | Apple-iPhone4C1/902.206 | |
asutton | iPhone | iPhone4C1 | Apple-iPhone4C1/1102.511 | |
atan | iPhone | iPhone5C2 | Apple-iPhone5C2/1101.501 | |
ateixeir | Android | SCH-I535 | TouchDown(MSRPC)/8.3.00016/ENCRYPTDEVICE,ENCRYPTSD | |
avanvlie | iPhone | iPhone4C1 | Apple-iPhone4C1/1101.501 | |
ballred | iPhone | iPhone4C1 | Apple-iPhone4C1/1102.511 | |
bcouvril | BlackBerry | Q5 SQR100-2 | RIM-Q5-SQR100-2/10.1.0.2342 | |
bcouvril | Android | GT-I9100 | TouchDown(MSRPC)/8.1.00052/ENCRYPTDEVICE,ENCRYPTSD | |
bcouvril | BlackBerry | Q10 SQN100-3 | RIM-Q10-SQN100-3/10.1.0.2342 | |
bcouvril | BlackBerry | Z10 STL100-2 | RIM-Z10-STL100-2/10.1.0.4633 | |
bcouvril | WP8 | Windows Phone 8X by HTC | MSFT-WP/8.0.9903 | |
bgonzale | iPhone | iPhone5C1 | Apple-iPhone5C1/1102.511 | |
bgonzale | iPad | iPad3C1 | Apple-iPad3C1/1101.501 |
Desired Output: (done with macro now)
1) Removes duplicate userdisplayname
2) For any devicetype it puts in the column separating each device by comma
3) For any devicemodel it put in the column separating each model by comma
UserDisplayName | DeviceType | DeviceModel | DeviceUserAgent |
aarthus | Android | GT-S5839i | TouchDown(MSRPC)/8.1.00052/ENCRYPTDEVICE,ENCRYPTSD |
aferri | iPhone | iPhone5C1 | Apple-iPhone5C1/1101.501 |
afrances | iPhone,iPhone | iPhone4C1,iPhone6C1 | Apple-iPhone4C1/1101.501,Apple-iPhone6C1/1102.511 |
ajensen1 | iPhone | iPhone5C1 | Apple-iPhone5C1/1101.501 |
ajoseph2 | Android | SAMSUNG-SGH-I337 | TouchDown(MSRPC)/8.1.00052/ENCRYPTDEVICE,ENCRYPTSD |
amantill | iPhone | iPhone5C1 | Apple-iPhone5C1/1101.501 |
amunoz | iPhone | iPhone5C2 | Apple-iPhone5C2/1101.501 |
aparker2 | iPhone | iPhone5C2 | Apple-iPhone5C2/1101.465 |
apeshevs | iPhone | iPhone | Apple-iPhone4C1/901.406 |
apoon2 | iPhone,iPhone | iPhone3C1,iPhone5C2 | Apple-iPhone3C1/1101.501,Apple-iPhone5C2/1101.501 |
arhodes | iPhone | iPhone5C1 | Apple-iPhone5C1/1101.501 |
asorrent | iPhone | iPhone | Apple-iPhone4C1/902.206 |
asutton | iPhone | iPhone4C1 | Apple-iPhone4C1/1102.511 |