Solved

use powershell script to parse data for comparion

Posted on 2016-09-13
4
28 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 40

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Find out what the Office 365 disclaimer function is, why you would use it and its limited ability to create Office 365 signatures.
Adoption of Microsoft’s Enterprise Mobility and Security solution and Office 365 will re-order the File Sync and Share market Microsoft has stated that its Enterprise Mobility + Security (EMS) is the fastest growing product in the history of the …
This video discusses moving either the default database or any database to a new volume.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

810 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