?
Solved

use powershell script to parse data for comparion

Posted on 2016-09-13
4
Medium Priority
?
44 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 85

Accepted Solution

by:
oBdA earned 1000 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 42

Assisted Solution

by:Vasil Michev (MVP)
Vasil Michev (MVP) earned 1000 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

WatchGuard's M Series Appliances - Miecom Approved

WatchGuard's newest M series appliances were put to the test by Miercom.  We had great results and outperformed all of our competitors in both stateless and stateful traffic throghput scenarios! Ready to see how your UTM appliance stacked up? Download the Miercom Report!

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
After hours on line I found a solution which pointed to the inherited Active Directory permissions . You have to give/allow permissions to the "Exchange trusted subsystem" for the user in the Active Directory...
This video discusses moving either the default database or any database to a new volume.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…
Suggested Courses

752 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