?
Solved

How to Enable-Mailbox and Set-QADuser parameters within single script?

Posted on 2010-08-29
2
Medium Priority
?
1,286 Views
Last Modified: 2012-06-27
Hello experts,
I'm a powershell novice and need some guidance.  We are going to migrate 250 AD accounts from several domains, including 2003 DCs, to a new domain on 2008 servers, with Exchange 2010 mail servers. ADMT creates the new accounts just fine. I want to mailbox-enable the migrated accounts and then update the AD attributes with one script, reading the data from a csv file. The attached code works great with just the Enable-Mailbox command, or with just the Set-QADuser command. When both processes are included, if fails at Set-QADuser. I'm guessing that after Enable-Mailbox runs, the data from import csv is cleared, causing the failure when Set-QADuser tries to run.  How do I fix the code to run both processes.
function Select-FileDialog 
{
	param([string]$Title,[string]$Directory,[string]$Filter="CSV Files (*.csv)|*.csv")
	[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
	$objForm = New-Object System.Windows.Forms.OpenFileDialog
	$objForm.InitialDirectory = $Directory
	$objForm.Filter = $Filter
	$objForm.Title = $Title
	$objForm.ShowHelp = $true
	
	$Show = $objForm.ShowDialog()
	
	If ($Show -eq "OK")
	{
		Return $objForm.FileName
	}
	Else
	{
		Exit
	}
}
$FileName = Select-FileDialog -Title "Import a CSV file                          BE CAREFUL - Use the CORRECT CSV File" -Directory "c:\"

Import-Csv $FileName |
	foreach {Enable-Mailbox -Identity $_.UPN -Database $_.Database -DisplayName $_.Name -Alias $_.Alias }

ForEach-Object{
    set-qaduser -Identity $_.sAMAccountName -Email $_.Email -MobilePhone $_.MobilePhone -HomeDirectory $_.HomeDirectory	-HomeDrive $_.HomeDrive -LogonScript $_.LogonScript -UserPrincipalName "$($_.sAMAccountName)@cpa.firm" -FirstName $_.FirstName -LastName $_.LastName -DisplayName $_.Name 
	}

Open in new window

NewUserProfiles.csv
0
Comment
Question by:CraigMan
[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 Comments
 
LVL 9

Accepted Solution

by:
jjoseph_x earned 2000 total points
ID: 33555608
Just put the Set-QADUser command in the same foreach block as the Enable-Mailbox.


Import-Csv $FileName |
	foreach {Enable-Mailbox -Identity $_.UPN -Database $_.Database -DisplayName $_.Name -Alias $_.Alias
    set-qaduser -Identity $_.sAMAccountName -Email $_.Email -MobilePhone $_.MobilePhone -HomeDirectory $_.HomeDirectory	-HomeDrive $_.HomeDrive -LogonScript $_.LogonScript -UserPrincipalName "$($_.sAMAccountName)@cpa.firm" -FirstName $_.FirstName -LastName $_.LastName -DisplayName $_.Name 
	};

Open in new window

0
 

Author Closing Comment

by:CraigMan
ID: 33589254
short and sweet!
Thanks
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦
Suggested Courses
Course of the Month12 days, 22 hours left to enroll

777 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