Solved

use powershell script to parse data for comparion

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

830 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