How to use EMS to modify LDAP/Exchange Properties for all UM-enabled users
Hi,
Some of our IT Staff are looking to export certain AD/Exchange attributes to a CSV file, then fill in the blanks and import them back. I'm somehow looking to combine the Get-UMMailbox and Get-User cmdlets into one csv file using powershell.
Examples to combine:
get-user | select-object samaccountname, city, company, department, fax, mobilephone, office, phone, stateorprovince, streetaddress, title | export-csv c:\export.csv
and
get-ummailbox | select-object name, phonenumber, operatornumber | export-csv c:\export_um.csv
I'm thinking we need to run the get-ummailbox cmdlet first, then pipe the get-user command just so it removes any non-UM, non-user mailboxes from the start. How does once combine these into a functional script to export data? What about importing
after that? (Import-csv)
Thanks.
Rory Schmitz
January 20th, 2011 4:12pm
Hi Rory,
I'm not a powershell expert. But I think this blog will be helpful to you.
Combining two commands get-mailbox and get-mailboxstatistics
http://get-exchange.blogspot.com/2009/03/did-you-ever-needed-to-supply-list-of.html
Hope some powershell experts will give you a perfect cmdlet :)
Frank Wang
TechNet Subscriber Support
in forum
If you have any feedback on our support, please contact
tngfb@microsoft.com Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Free Windows Admin Tool Kit Click here and download it now
January 21st, 2011 2:47am
Thanks Frank. I'll definitely research and test this over the weekend. If it get's too complex, we may just have to stick with two csv files. If I figure it out, I'll post the script.Rory Schmitz
January 21st, 2011 2:58pm
Rory,
One method is to add additional note properties. I unfortunately do not have any ummailboxs in my test network but the following should get you started:
get-ummailbox | % {
Add-Member -InputObject $_ -MemberType NoteProperty -Name city -Value (Get-User $_.SamAccountName ).city
Add-Member -InputObject $_ -MemberType NoteProperty -Name company -Value (Get-User $_.SamAccountName ).company
Add-Member -InputObject $_ -MemberType NoteProperty -Name department -Value (Get-User $_.SamAccountName ).department
Add-Member -InputObject $_ -MemberType NoteProperty -Name fax -Value (Get-User $_.SamAccountName ).fax
} export-csv c:\export_um.csv
John Milner | MCITP: EMA | MCTS | MCSE: S | MCSA: S/M This post is provided "AS IS" with no warranties or guarantees, and confers no rights.
Free Windows Admin Tool Kit Click here and download it now
January 21st, 2011 5:53pm
Hi Rory,
Any updates?Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
January 25th, 2011 2:52am
Hi,
Finally getting around to posting an update...
@jfrmilner - I tried that command but received the error message below:
ForEach-Object : Cannot bind parameter 'Process'. Cannot convert the "export-csv" value of type "System.String" to type
"System.Management.Automation.ScriptBlock".
At line:1 char:18
+ get-ummailbox | % <<<< {
+ CategoryInfo : InvalidArgument: (:) [ForEach-Object], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ForEachObjectCommand
So when combining that cmdlet, plus Frank.Wang's link and a couple other helpful links I found, I believe I'm close. Just to keep it fairly basic, I've reduced the fields in my script when testing. Here's what I've put together so far:
Get-ummailbox | foreach{
$userinfo = Get-User $_|select samaccountname
$uminfo = $_|select Extensions
get-ummailbox $_|foreach{
$userinfo | add-member -type noteProperty -name SamAccountName -value $userinfo.samaccountname
$uminfo | add-member -type noteProperty -name Extension -value $_.Extensions
}
$umminfo} | export-csv export-test.csv
Either way I called for the NoteProperty field, per jfrmilner, or what's shown above, I still receive the following errors in PS:
Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.
At C:\export\um_3.ps1:10 char:23
+ $umminfo} | export-csv <<<< export-test.csv
+ CategoryInfo : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCo
mmand
Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
+ CategoryInfo : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [],
PSInvalidOperationException
+ FullyQualifiedErrorId : RemotePipelineExecutionFailed
Is this just a formatting issue within the script or am I way off altogether?Rory Schmitz
Free Windows Admin Tool Kit Click here and download it now
January 25th, 2011 2:30pm
Rory,
I missed a pipe on the last line, sorry about that.
Try this:
$Users = get-ummailbox
$Users | % {
Add-Member -InputObject $_ -MemberType NoteProperty -Name city -Value (Get-User $_.SamAccountName ).city
Add-Member -InputObject $_ -MemberType NoteProperty -Name company -Value (Get-User $_.SamAccountName ).company
Add-Member -InputObject $_ -MemberType NoteProperty -Name department -Value (Get-User $_.SamAccountName ).department
Add-Member -InputObject $_ -MemberType NoteProperty -Name fax -Value (Get-User $_.SamAccountName ).fax
}
$Users | export-csv c:\export_um.csv
In this example I also used a variable $Users to simplify the code, I also tested this with the Get-CASMailbox ($Users = Get-CASMailbox) and it seemed to work fine. If you have over 1000 users let me know as we could optimise it further but the above will
work perfectly for a few users.
Let us know how you get on.John Milner | MCITP: EMA | MCTS | MCSE: S | MCSA: S/M This post is provided "AS IS" with no warranties or guarantees, and confers no rights.
January 25th, 2011 3:15pm
That last one seemed to work great. I tried to add the folowing to select only the Extensions field, but it seemed to go into an endless loop about a warning on a couple accounts, which may indicate I have other problems. I'm just not
sure why it's looping through these problem accounts?
Modified cmdlet:
$Users = get-ummailbox | Select Extensions
$Users | % {
Add-Member -InputObject $_ -MemberType NoteProperty -Name city -Value (Get-User $_.SamAccountName ).city
Add-Member -InputObject $_ -MemberType NoteProperty -Name company -Value (Get-User $_.SamAccountName ).company
Add-Member -InputObject $_ -MemberType NoteProperty -Name department -Value (Get-User $_.SamAccountName ).department
Add-Member -InputObject $_ -MemberType NoteProperty -Name fax -Value (Get-User $_.SamAccountName ).fax
}
$Users | export-csv export_online.csv
Warning Message:
WARNING: The object DOMAIN.LOCAL/OrgUnit/MIS/Users/MeetingRoomUser has been corrupted, and it's in an inconsistent state. The
following validation errors happened:
WARNING: Could not convert property WindowsEmailAddress to type SmtpAddress. Error while converting string 'N/A' to
result type Microsoft.Exchange.Data.SmtpAddress: "N/A" is not a valid SMTP addressRory Schmitz
Free Windows Admin Tool Kit Click here and download it now
January 25th, 2011 4:46pm
Rory,
You would be better off sorting the properties you’re after at the end of the script. In your last post you are effectively stripping all information away with
the exception of Extensions, this includes the SamAccountName value used in the foreach loop to create the Note Properties.
For example try this:
$Users | Select SamAccountName,Extensions | export-csv export_online.csv
As for your warning, you seem to have an invalid smtp address on the MeetingRoomUser account, take a look at it with the EMC.John Milner | MCITP: EMA | MCTS | MCSE: S | MCSA: S/M This post is provided "AS IS" with no warranties or guarantees, and confers no rights.
January 25th, 2011 5:31pm
That makes sense as to why it looped. Adding extra properties did take care of it. I appreciate all of the help. I think that takes care of everything. Thank you!Rory Schmitz
Free Windows Admin Tool Kit Click here and download it now
January 26th, 2011 9:08am