• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1294
  • Last Modified:

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

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
CraigMan
Asked:
CraigMan
1 Solution
 
jjoseph_xCommented:
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
 
CraigManNetwork AdminAuthor Commented:
short and sweet!
Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now