Solved

use powershell script to parse data for comparion

Posted on 2016-09-13
4
17 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
  • 2
4 Comments
 
LVL 83

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 38

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Synchronize a new Active Directory domain with an existing Office 365 tenant
This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now