Solved

use powershell script to parse data for comparion

Posted on 2016-09-13
4
40 Views
Last Modified: 2016-09-13
running a script to check a list of mobile device ID's from a database against a quarantine list for approval. The quarantine list from exchange online does not provide user info in a precise way to be used.

get-mobiledevice -ResultSize unlimited | Where-Object {$_.DeviceAccessState -eq "Quarantined"} | Select-Object -Property identity, deviceaccessstate, devicetype,deviceuseragent, deviceid, userdisplayname | Format-Table -AutoSize

result is as follows

Identity                                                                    DeviceAccessState DeviceType DeviceUserAgent         DeviceId                         UserDisplayName                                                
--------                                                                    ----------------- ---------- ---------------         --------                         ---------------                                                
PYS\ExchangeActiveSyncDevices\Outlook§2988DCEF9E34B54B                      Quarantined       Outlook    Outlook-iOS-Android/1.0 2988DCEF9E34B54B                 NAMPR02A001.prod.outlook.com/Microsoft Exchange Hosted Organizat

i need to use the parsed data from identity "PYS\ExchangeActiveSyncDevices\Outlook§2988DCEF9E34B54B" .... data before the \

looking to run a pshell parse command to extract letters before "/" from userdiplayname  ... in this example PYS
0
Comment
Question by:ARM2009
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 250 total points
ID: 41796458
Well, all you need is a ".Spli()" and Calculated Properties, but you've lost me somewhere when it comes to what it is exactly you need retrieved. You're mentioning both Identity and UserDisplayName, especially wanting to parse PYS from UserDisplayName, where it doesn't appear?
So here's a version that just adds to properties IdentityParsed and UserDisplayNameParsed, reformatted for readability:
Get-MobileDevice -ResultSize Unlimited |
	Where-Object {$_.DeviceAccessState -eq "Quarantined"} |
	Select-Object -Property `
		Identity,
		@{n='IdentityParsed'; e={$_.Identity.Split('\')[0]}},
		DeviceAccessState,
		DeviceType,
		DeviceUserAgent,
		DeviceId,
		UserDisplayName,
		@{n='UserDisplayNameParsed'; e={$_.UserDisplayName.Split('/')[0]}}

Open in new window

0
 

Author Comment

by:ARM2009
ID: 41796475
thanks.. that does the parsing on the identity. problem is that the userdisplayname does not show the user identity properly.

what i am trying to do is the following..

1. get the identity of user (parsed) and device ID from this script
2. run it through a table that is already pulled from SQL with valid device ID's  as below

$Query = "SELECT [IMEI],[ACTIVESYNC_ID],[LAST_INVENTORY_TIME],[FIRST_CONNECTION_DATE],[LAST_USERNAME],[corporate_owned] FROM [prod].[dbo].[DEVICE_SEARCH] Where [corporate_owned] = 1 AND DATEDIFF(d, LAST_INVENTORY_TIME, GETDATE()) <= 90"

3. If the device ID from the script matches a ACTIVESYNC_ID then allow the device to connect.

4. Set-CASMailbox –ActiveSyncAllowedDeviceIDs @{Add=$device.DeviceID} –Identity (parsed user ID)

makes sense? or a better way to do it?
0
 
LVL 41

Assisted Solution

by:Vasil Michev (MVP)
Vasil Michev (MVP) earned 250 total points
ID: 41796477
You can easily use a calculated column, for example:

Get-MobileDevice | Select-Object -Property @{n="identity";e={$_.Identity.Split("\")[0]}}, deviceaccessstate

Open in new window


just add the remaining properties. UserDisplayName is not reliable, I'd advise against using that.

Or if you want to reliably get the UPN:

Get-MobileDevice | Select-Object -Property @{n="id";e={(Get-Mailbox $($_.DistinguishedName.Split(",")[2..10] -join ",")).UserPrincipalName}}

Open in new window

0
 

Author Closing Comment

by:ARM2009
ID: 41797149
Combination of both solutions got me the data i was looking for to complete my script
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
when apply search old messages are not showing up in office 365 4 58
Journaling 2 15
Office 365 not Syncing user object 3 26
invoke-sqlcmd help 5 33
A list of top three free exchange EDB viewers that helps the user to extract a mailbox from an unmounted .edb file and get a clear preview of all emails & other items with just a single click on mailboxes.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question