Quantcast
Channel: PowerShell General
Viewing all articles
Browse latest Browse all 10624

Get-MobileDevice and remove duplicates

$
0
0

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:

UserDisplayNameDeviceTypeDeviceModelDeviceUserAgent
afrancesiPhoneiPhone6C1Apple-iPhone6C1/1102.511
agoodairiPadiPad2C7Apple-iPad2C7/1101.501
ajensen1iPhoneiPhone5C1Apple-iPhone5C1/1101.501
ajoseph2AndroidSAMSUNG-SGH-I337TouchDown(MSRPC)/8.1.00052/ENCRYPTDEVICE,ENCRYPTSD
amantilliPhoneiPhone5C1Apple-iPhone5C1/1101.501
amunoziPhoneiPhone5C2Apple-iPhone5C2/1101.501
aparker2iPhoneiPhone5C2Apple-iPhone5C2/1101.465
apeshevsiPhoneiPhoneApple-iPhone4C1/901.406
apoon2iPhoneiPhone3C1Apple-iPhone3C1/1101.501
apoon2iPhoneiPhone5C2Apple-iPhone5C2/1101.501
arhodesiPhoneiPhone5C1Apple-iPhone5C1/1101.501
asemiziaAndroidGalaxy NexusAndroid/MIAndroidEmail-4.2.1-1.1.0.1
asorrentiPhoneiPhoneApple-iPhone4C1/902.206
asuttoniPhoneiPhone4C1Apple-iPhone4C1/1102.511
ataniPhoneiPhone5C2Apple-iPhone5C2/1101.501
ateixeirAndroidSCH-I535TouchDown(MSRPC)/8.3.00016/ENCRYPTDEVICE,ENCRYPTSD
avanvlieiPhoneiPhone4C1Apple-iPhone4C1/1101.501
ballrediPhoneiPhone4C1Apple-iPhone4C1/1102.511
bcouvrilBlackBerryQ5 SQR100-2RIM-Q5-SQR100-2/10.1.0.2342
bcouvrilAndroidGT-I9100TouchDown(MSRPC)/8.1.00052/ENCRYPTDEVICE,ENCRYPTSD
bcouvrilBlackBerryQ10 SQN100-3RIM-Q10-SQN100-3/10.1.0.2342
bcouvrilBlackBerryZ10 STL100-2RIM-Z10-STL100-2/10.1.0.4633
bcouvrilWP8Windows Phone 8X by HTCMSFT-WP/8.0.9903
bgonzaleiPhoneiPhone5C1Apple-iPhone5C1/1102.511
bgonzaleiPadiPad3C1Apple-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

UserDisplayNameDeviceTypeDeviceModelDeviceUserAgent
aarthusAndroidGT-S5839iTouchDown(MSRPC)/8.1.00052/ENCRYPTDEVICE,ENCRYPTSD
aferriiPhoneiPhone5C1Apple-iPhone5C1/1101.501
afrancesiPhone,iPhoneiPhone4C1,iPhone6C1Apple-iPhone4C1/1101.501,Apple-iPhone6C1/1102.511
ajensen1iPhoneiPhone5C1Apple-iPhone5C1/1101.501
ajoseph2AndroidSAMSUNG-SGH-I337TouchDown(MSRPC)/8.1.00052/ENCRYPTDEVICE,ENCRYPTSD
amantilliPhoneiPhone5C1Apple-iPhone5C1/1101.501
amunoziPhoneiPhone5C2Apple-iPhone5C2/1101.501
aparker2iPhoneiPhone5C2Apple-iPhone5C2/1101.465
apeshevsiPhoneiPhoneApple-iPhone4C1/901.406
apoon2iPhone,iPhoneiPhone3C1,iPhone5C2Apple-iPhone3C1/1101.501,Apple-iPhone5C2/1101.501
arhodesiPhoneiPhone5C1Apple-iPhone5C1/1101.501
asorrentiPhoneiPhoneApple-iPhone4C1/902.206
asuttoniPhoneiPhone4C1Apple-iPhone4C1/1102.511

 


Viewing all articles
Browse latest Browse all 10624

Trending Articles