Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Question about pulling from AD and Exchange in a Script

$
0
0

Hey guys, so I've got a powershell script, that pulls from exchange to tell us who is syncing activesync devices, what device they're syncing, what OS it's running, and what the last successful sync date of the device was.

Now I'm wanting to add two more fields to it though, that come from AD, in our environment the fields are "extensionattribute2" and "title". So below is my existing script to pull all of the exchange information:

## start
#### define parameters

param(
    [Parameter(Mandatory = $true)]
    [string] $exportpath = “”
	)

#### connect to exchange and define scope

##### define new session and import it
$s = New-PSSession -configurationName microsoft.exchange -connectionuri http://exchangeserver/powershell
import-pssession $s
##### set scope to entire forest to pull other domain
Set-AdServerSettings -ViewEntireForest $True

####  get command

$EASDevices = “”
$AllEASDevices = @()

$EASDevices = “”| select ’User’,’Email’,’Type’,’Model’,’OS’,’Sync’
$EasMailboxes = Get-Mailbox -resultsize unlimited
foreach ($EASUser in $EasMailboxes) {
$EASDevices.User = $EASUser.displayname
$EASDevices.Email = $EASUser.primarysmtpaddress.tostring()
    foreach ($EASUserDevices in Get-MobileDeviceStatistics -Mailbox $EasUser.alias) {
    $EASDeviceStatistics = $EASUserDevices | Get-MobileDeviceStatistics
    $EASDevices.Type = $EASUserDevices.devicetype
    $EASDevices.Model = $EASUserDevices.devicemodel
    $EASDevices.OS = $EASUserDevices.deviceos
	$EASDevices.Sync = $EASDeviceStatistics.lastsuccesssync
    $AllEASDevices += $EASDevices | select User,Email,Type,Model,OS,Sync
    }
    }
$AllEASDevices = $AllEASDevices | sort Type
$AllEASDevices
$AllEASDevices | Export-Csv $exportpath\ActiveSyncReport.csv

##end

Thanks, to the help of some other forum users, I've found the best way to get the AD information is a line like this:

dsquery * -Filter "(anr=Jim Smith)" -attr extensionAttribute2, title

So, ultimately what I need to do is combine the two, so I'd like the variable for the anr filter search, to come from the $EASDevices.User variable in the script, then just add on another column or 2 to the .csv that gets output in the script, that contain the extensionAttribute2, and Title information.

The information in the $EASDevices.User variable should be unique user ID's in our environment, so I don't think there should be too many issues with multiple entries per User.

Does anyone have any ideas on this? Or know if it's possible? I think my only other option is probably to take a separate CSV of just the $EASDevices.User column, and use the dsquery to match them up separately, but if we can avoid that, I would definitely prefer it.

Thanks for your guys' help!


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>