Quantcast
Channel: Directory Services forum
Viewing all articles
Browse latest Browse all 31638

Scripting Question with AD and Exchange

$
0
0

Hey guys, I'm hoping someone can help me out here. This is my issue:

I've got a script that I run to pull all ActiveSync devices we have running, and give me the Display Name, Email, Device Type, Device Model, Device OS, and Last Sync of every device we have in AS. I run this usually to work with security enforced iOS updates. That script is here: 

## 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


Now, I'm wanting to add another tab to my script for the users department name, and job title, to assist with a migration that we're in the middle of working on. The only place I know that that is accurately stored is AD, so I've got this line that I can use to pull that information on a one-by-one basis:

dsquery * domainroot -filter "(displayname=lastname, firstname)" -attr extensionAttribute2, title

However, I've got 2 issues now, the first is that I don't really know how to automate, and combine that line, into my main script, in such a way that it will just add another column or two to the right with the extensionAttribute2 and Title information.

The other problem, is that I'm not sure that this is the best way to get this information, I was hoping for a dsquery/dsget solution, but our AD information is organized in such a way that those don't seem to work the way I would have expected them to.

Does anyone else have any ideas or solutions for this issue? Or hae you ever run into an issue like this?



Viewing all articles
Browse latest Browse all 31638

Trending Articles



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