header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Writing a new target address
Last Post 15 Dec 2009 09:07 AM by James. 28 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
JamesUser is Offline
Basic Member
Basic Member
Posts:374
Avatar

--
03 Dec 2009 01:49 AM
    Hello,

    I am currently trying to set the target address within ad for a list of users.

    I cant seem to find the command to do this anywhere.

    Does anyone know what it would be?

    Many Thanks

    James
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    03 Dec 2009 02:20 AM
    Doyou mean email forwarding address?

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    03 Dec 2009 02:31 AM
    Possibly.

    I have been told I need to change the target address attribute of Active directory.

    Many Thanks

    James
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    03 Dec 2009 03:24 AM
    What Exchange version?

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    03 Dec 2009 03:34 AM
    Its 2007 :)
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    03 Dec 2009 03:45 AM
    Forward a copy of the messages delivered to 'User1' as well as to the forwarding address (administrator).

    Get-Mailbox user1 | Set-Mailbox -ForwardingAddress Administrator -DeliverToMailboxAndForward $true

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    03 Dec 2009 04:00 AM
    Hello,

    I have just found the following link:

    http://msdn.microsoft.com/en-us/lib...G.65).aspx

    I presume this is diffrent to what your code does?

    Or am I incorrect?

    Many Thanks

    James
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    04 Dec 2009 12:44 AM
    Hello,

    I have found the target address and the forwarding address are diffrent attributes within AD. Does anyone know how I can change the targeting address opposed to the forwarding address I was so kindly given the code for?

    Many Thanks

    James
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    04 Dec 2009 02:39 AM
    Hello,

    I have found the following function on the web...

    http://www.mmcug.org/blogs/Lists/Po...f1ba&ID=20

    I have used it in my code however I dont know how I would use it to write the target address opposed to read from it?

    I have attempted the following....

    Any help is greatly appreciated

     <br />  <br /> # Open a specific OU <br /> # Find the users who have STUDENT as their job title <br /> # Populate the Target Address with something@live.edu <br />  <br /> Function Get-LDAPUser ($UserName, $queryDC) { <br />     $domain = new-object DirectoryServices.DirectoryEntry ` <br />         ("LDAP://$queryDC") <br />     $searcher = new-object DirectoryServices.DirectorySearcher($domain) <br />     $searcher.filter = "(&(objectClass=user) ` <br />         (sAMAccountName= $UserName))" <br />     $searcher.findone().getDirectoryEntry() <br /> }  <br /> $School = "schoolnamehere"             #Change School name here <br />  <br /> Get-User -DomainController "dcnamehere" -OrganizationalUnit "domain/OU/" + $School + "/OU2" <br /> Get-QADUser -Title "student" <br /> $prefDC   = "domainnamehere" <br /> $LookupID = "%username%" <br /> $ADUser = Get-LDAPUser $LookupID $prefDC  <br />  <br /> Set-$ADUser.targetAddress = "Something@live.edu" <br />  <br /> 


    So my thinking is that it will find the users with a job title of student in the OU specified and then it will just get the username and write the target address.

    As I am unable to test it currently I thought I would post to see what people's idea's on this were

    Many Thanks for your assistance.

    James
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    04 Dec 2009 07:36 AM
    Hello,

    I dont mean to push or anything however we are getting quite desperate to get these scripts sorted so that we can get the addresses and target addresses done.

    Once we can do this via a script then we can progress with the project which is due to go live next week early on.

    I hope someone can assist.

    Many Thanks for all help and support given so far and in the future.

    James
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    06 Dec 2009 12:34 AM
    Try this:

    Get-QADUser -Title student -SerachRoot 'OUDistinguishedName' -ResultSize 0 | Foreach-Object{
    $TargetAddress = 'put value here or generate it from other user attributes'
    Set-QADUser $_ -ObjectAttributes @{TargetAddress=$TargetAddress} -WhatIf
    }

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    Marco Shaw (MVP)User is Offline
    Veteran Member
    Veteran Member
    Posts:1642
    Avatar

    --
    06 Dec 2009 05:00 AM
    Posted By morpheus83uk on 04 Dec 2009 07:36 AM
    Hello,

    I dont mean to push or anything however we are getting quite desperate to get these scripts sorted so that we can get the addresses and target addresses done.

    Once we can do this via a script then we can progress with the project which is due to go live next week early on.

    I hope someone can assist.

    Many Thanks for all help and support given so far and in the future.

    James

    This is a free support forum with people volunteering their time to help.  When a matter becomes urgent/pressing, I recommend one considers getting professional support services from either Microsoft or even freelancers from www.elance.com to help.
    Marco

    *Microsoft MVP - Windows PowerShell
    https://mvp.support.microsoft.com/profile/Marco.Shaw
    *Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
    *Blog - http://marcoshaw.blogspot.com
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    07 Dec 2009 06:58 AM
    Hello,

    Many thanks for your replys

    I have tried your code and I had to remove the result size from it as it errors saying it didnt know what it was...

    I have the follwoing:

    Get-QADUser -Title "teacher", "staff" -SearchRoot "OU=users,OU=fairway,OU=schools,DC=stockport,DC=sch,DC=uk" | ForEach-Object{
    #$Name Get-QADUser -SearchAttributes
    Set-QADUser -Identity name -PasswordNeverExpires $false
    Write-Host "Creating Mailbox..."
    #New-Mailbox -DisplayName $DisplayName -Password $secureString -Alias $Alias -FirstName $FirstName -LastName $LastName -Name $Name -OrganizationalUnit $OU -UserPrincipalName $PrincipalName -Database $Database
    }

    Aand its prompts me for the Identity.

    I have tried this with the target address also and I get the same result.

    Does anyone know how I can progress this and get the name field from AD to become the identity? I presume someway of getting it into a variable however I have googled around and cant seem to find anything :(

    And I appreciate the use of consultants etc this was my original idea however we have 2 in already working on other things and neither can do powershell and management wont pay for another one its a case of me getting it done! :(

    Many Thanks

    James
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    07 Dec 2009 07:31 AM
    Oops, -ResultSize is for Exchange 2007 cmdlets, try -SizeLimit instead. As for the Name attribute, inside foreach-object refer to it as $_.Name.


    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    07 Dec 2009 07:31 AM
    Oops, -ResultSize is for Exchange 2007 cmdlets, try -SizeLimit instead. As for the Name attribute, inside foreach-object refer to it as $_.Name.


    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    07 Dec 2009 07:32 AM
    Oops, -ResultSize is for Exchange 2007 cmdlets, try -SizeLimit instead. As for the Name attribute, inside foreach-object refer to it as $_.Name.


    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    07 Dec 2009 07:40 AM
    sorry for the triple post :)

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    08 Dec 2009 02:14 AM
    Hello,

    Many Thanks for that it seems to have worked fine :)

    I will try the target addres one the same when we have the target address.

    In the meantime I ned to get the mailbox to be created.

    I take it I just use the $_.FirstName $_.Surname etc to get the AD Attributes but then how do I get the details based on the school from the CSV? Or is that just going to work when I import the CSV file?

    Many Thanks

    James
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    08 Dec 2009 06:02 AM
    Hello,

    I think I have kind of got a solution however its erroring...

    My code is:

     <BR><BR># Look in specific OU (For individual school) <BR># Get the users from AD with a job Title of teacher OR Staff <BR># Set PasswordNeverExpires to False <BR># Match School in CSV <BR># Create the mailbox based on the mailbox location from CSV <BR><BR>#Add-PSSnapin Quest.ActiveRoles.ADManagement <BR>#Change School in SearchRoot (e.g.: OU=USERS,OU=SCHOOL NAME HERE,OU=SCHOOLS) and variable ( e.g: $_.school -eq "SCHOOL NAME HERE") <BR><BR>Get-QADUser -Title "teacher", "staff" -SearchRoot "OU=users,OU=fairway,OU=schools,DC=stockport,DC=sch,DC=uk" -SizeLimit 0 | ForEach-Object{ <BR>Set-QADUser -Identity $_.Name -PasswordNeverExpires $false <BR><BR>Import-Csv -Path "C:\mailboxdatabases.csv" | <BR>Where-Object{$_.school -eq "fairway"} <BR>$Server = $_.ExchangeServer <BR>$StorageGroup = $_.StorageGroup <BR>$MailboxDatabase = $_.MailboxDatabase <BR>$Database = "\\" + $Server + "\" + $StorageGroup + "\" + $MailboxDatabase <BR>$SecondaryAddress = $_.mail <BR><BR>Write-Host "Creating users Mailbox..." <BR>Enable-Mailbox -Identity $_.DisplayName -Alias $_.samAccountName -Database $Database <BR>$mailbox = Get-Mailbox -Identity $_.samAccountName <BR>$newaddress = $SecondaryAddress <BR>$mailbox.EmailAddresses += $newaddress <BR>Write-Host "Adding SMTP Information..." <BR>Set-Mailbox -Identity $mailbox.alias -EmailAddresses $mailbox.EmailAddresses <BR>Set-Mailbox -Identity $mailbox.alias -PrimarySmtpAddress $newaddress -EmailAddressPolicyEnabled $false <BR>Write-Host "Moving to next user............." <BR>} <BR>Write-Host "Complete!" <BR><BR>


    However its giving the following error:

    Creating users Mailbox...
    Enable-Mailbox : Cannot bind parameter 'Database'. Cannot convert value "\\" to
    type "Microsoft.Exchange.Configuration.Tasks.DatabaseIdParameter". Error: "'\'
    is not a valid value for the identity.
    Parameter name: Identity"
    At C:\bulkcreateteachersmailboxes.ps1:22 char:75
    + Enable-Mailbox -Identity $_.DisplayName -Alias $_.samAccountName -Database <
    <<< $Database
    Get-Mailbox : wendy.parker is not a mailbox user.
    At C:\bulkcreateteachersmailboxes.ps1:23 char:23
    + $mailbox = Get-Mailbox <<<< -Identity $_.samAccountName
    Property 'EmailAddresses' cannot be found on this object; make sure it exists a
    nd is settable.
    At C:\bulkcreateteachersmailboxes.ps1:25 char:10
    + $mailbox.E <<<< mailAddresses += $newaddress
    Adding SMTP Information...
    Set-Mailbox : Cannot bind argument to parameter 'Identity' because it is null.
    At C:\bulkcreateteachersmailboxes.ps1:27 char:22
    + Set-Mailbox -Identity <<<< $mailbox.alias -EmailAddresses $mailbox.EmailAddr
    esses
    Set-Mailbox : Cannot bind argument to parameter 'Identity' because it is null.
    At C:\bulkcreateteachersmailboxes.ps1:28 char:22
    + Set-Mailbox -Identity <<<< $mailbox.alias -PrimarySmtpAddress $newaddress -E
    mailAddressPolicyEnabled $false
    Moving to next user.............

    I presume that its just going to be happy when I sort out the database variable thing? As I read that its looking for the school and then it will run.

    Does anyone have any suggestions on how I can fix this?

    Many Thanks

    James
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    09 Dec 2009 02:38 AM
    A Mailbox database identity should look like (without '\\' at the begining):
    SERVER\First Storage Group\Mailbox Database


    Change $Database to:
    $Database = "$Server\$StorageGroup\$MailboxDatabase"


    In addition, you are importing the csv file foreach mailbox, move it to before the foreach loop:

    $fairway = Import-Csv -Path "C:\mailboxdatabases.csv" | Where-Object{$_.school -eq "fairway"}
    $Server = $fairway.ExchangeServer
    $StorageGroup = $fairway.StorageGroup
    $MailboxDatabase = $fairway.MailboxDatabase
    $Database = "$Server\$StorageGroup\$MailboxDatabase"
    $SecondaryAddress = $fairway.mail


    Get-QADUser -Title teacher,staff -SearchRoot "OU=users,OU=fairway,OU=schools,DC=stockport,DC=sch,DC=uk" -SizeLimit 0 | ForEach-Object{

    Set-QADUser -Identity $_.Name -PasswordNeverExpires $false

    Write-Host "Creating users Mailbox..."
    Enable-Mailbox -Identity $_.DisplayName -Alias $_.samAccountName -Database $Database
    $mailbox = Get-Mailbox -Identity $_.samAccountName
    $newaddress = $SecondaryAddress
    $mailbox.EmailAddresses += $newaddress
    Write-Host "Adding SMTP Information..."
    Set-Mailbox -Identity $mailbox.alias -EmailAddresses $mailbox.EmailAddresses
    Set-Mailbox -Identity $mailbox.alias -PrimarySmtpAddress $newaddress -EmailAddressPolicyEnabled $false
    Write-Host "Moving to next user............."
    }

    Write-Host "Complete!"


    One more thing, you're assigning the same $SecondaryAddress to all new mailboxes!

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    09 Dec 2009 03:24 AM
    Hello,

    Many Thanks for your reply.

    I am still getting the same error although "\\" is not in the CSV anywhere or in the code.

    The $_.mail was pulling the mail from the curret AD information since it would be the secondary E-Mail address. Basically its got an AD Aaccount and the mail field is populated with what we would want the secondary Address to be. When it creates the mailbox then it creates the generic one which is why I thought I would read it first and then create the mailbox.

    Also I have the following new code:

     <BR><BR># Look in specific OU (For individual school) <BR># Get the users from AD with a job Title of teacher OR Staff <BR># Set PasswordNeverExpires to False <BR># Match School in CSV <BR># Create the mailbox based on the mailbox location from CSV <BR><BR>#Add-PSSnapin Quest.ActiveRoles.ADManagement <BR>#Change School in SearchRoot (e.g.: OU=USERS,OU=SCHOOL NAME HERE,OU=SCHOOLS) and variable ( e.g: $_.school -eq "SCHOOL NAME HERE") <BR><BR>Import-Csv -Path "C:\mailboxdatabases.csv" | Where-Object{$_.school -eq "fairway"} <BR><BR>$Server = $_.ExchangeServer <BR>$StorageGroup = $_.StorageGroup <BR>$MailboxDatabase = $_.MailboxDatabase <BR>$Database = "$Server\$StorageGroup\$MailboxDatabase" <BR><BR>Get-QADUser -Title "teacher", "staff" -SearchRoot "OU=users,OU=fairway,OU=schools,DC=stockport,DC=sch,DC=uk" -SizeLimit 0 | ForEach-Object{ <BR>Set-QADUser -Identity $_.Name -PasswordNeverExpires $false <BR><BR>Write-Host "Creating users Mailbox..." <BR>Enable-Mailbox -Identity $_.Name -Alias $_.samAccountName -Database $Database <BR>$mailbox = Get-Mailbox -Identity $_.samAccountName <BR>$newaddress = $_.mail <BR>$mailbox.EmailAddresses += $newaddress <BR>Write-Host "Adding SMTP Information..." <BR>Set-Mailbox -Identity $mailbox.alias -EmailAddresses $mailbox.EmailAddresses <BR>Set-Mailbox -Identity $mailbox.alias -PrimarySmtpAddress $newaddress -EmailAddressPolicyEnabled $false <BR>Write-Host "Moving to next user............." <BR>} <BR>Write-Host "Complete!" <BR><BR>


    Also the $_.samAccountName and the $_.Name will be getting pulled from AD its self opposed to the CSV. The CSV file only has the following information:

    school domain UPN ExchangeServer Storagegroup MailboxDatabase

    The rest of the information is being taken from either AD or from the newly enabled mailbox.

    Does this make sense in what I am trying to achieve?

    Many Thanks

    James
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    09 Dec 2009 06:29 AM
    Ok for some bizarre reason I have used write-host $database to see what was being produced and for some reason its not pulling the information from the CSV its just displaying it on screen.

    For the $database its just displaying \\ and thats it.

    Its also displaying all the information ffor the user on screen too.

    Does anyone know why?

    I dont know if this information will help any but I thought it best to share anyway just in case.

    Many Thanks

    James
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    10 Dec 2009 02:53 AM
    Just as an update I have tried the target address script which you orgininally gave me Shay and it works fine I had to change the result size but apart from that it ran through and set everything as needed. So thank you for that and very much appreciated.

    Also I am still having the same issues as above it appears not to be reading the CSV or getting the information into my variables I cant see wy this is happening. I think once this issue is solved the script will run happily however since I dont know enough about powershell to understand whats going on or wrong then I am at a loss :(.

    Any help would be greatly appreciated from anyone.

    Many Thanks for all your assistance so far I have learned lots and I appreciate the time given to help me with my issues.

    James
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    10 Dec 2009 03:33 AM
    Hello,

    I have got it working to an extent...

    I need it tweaking though....

     <br />  <br /> # Look in specific OU (For individual school)  <br /> # Get the users from AD with a job Title of teacher OR Staff <br /> # Set PasswordNeverExpires to False <br /> # Match School in CSV <br /> # Create the mailbox based on the mailbox location from CSV <br />  <br /> #Add-PSSnapin Quest.ActiveRoles.ADManagement  <br /> #Change School in SearchRoot (e.g.: OU=USERS,OU=SCHOOL NAME HERE,OU=SCHOOLS) and variable ( e.g: $_.school -eq "SCHOOL NAME HERE") <br />  <br /> Import-Csv -Path "C:\mailboxdatabases.csv" | Where-Object{$_.school -eq "fairway" <br />  <br /> $Server = $_.ExchangeServer              <br /> $StorageGroup = $_.StorageGroup              <br /> $MailboxDatabase = $_.MailboxDatabase <br /> $Database = $Server + "\" + $StorageGroup + "\" + $MailboxDatabase <br /> }  <br />  <br /> Get-QADUser -Title "teacher", "staff" -SearchRoot "OU=users,OU=fairway,OU=schools,DC=stockport,DC=sch,DC=uk" -SizeLimit 0 |  <br /> ForEach-Object{ Set-QADUser  -Identity  $_.Name -PasswordNeverExpires $false <br />  <br /> Write-Host "Creating users Mailbox..." <br />  <br /> Enable-Mailbox -Identity $_.Name -Alias $_.samAccountName -Database $Database <br /> $mailbox = Get-Mailbox -Identity $_.samAccountName              <br /> $newaddress = $_.mail             <br /> $mailbox.EmailAddresses += $newaddress <br />    <br /> Write-Host "Adding SMTP Information..." <br />  <br /> Set-Mailbox -Identity $mailbox.alias -EmailAddresses $mailbox.EmailAddresses                        <br /> Set-Mailbox -Identity $mailbox.alias -PrimarySmtpAddress $newaddress -EmailAddressPolicyEnabled $false  <br />  <br /> Write-Host "Moving to next user............." <br /> } <br /> Write-Host "Complete!" <br />  <br /> 


    When I run it it just adds everything into the last storage group which I dont want I would like it to add them to the relevant storage groups on the server. The data is in the CSV file.

    Could anyone assist with this in getting it from the CSV and not displaying every attribute about the user it is changing?

    Many Thanks

    James
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    10 Dec 2009 03:57 AM
    Hello,

    I have the following:

     <br />  <br /> # Look in specific OU (For individual school)  <br /> # Get the users from AD with a job Title of teacher OR Staff <br /> # Set PasswordNeverExpires to False <br /> # Match School in CSV <br /> # Create the mailbox based on the mailbox location from CSV <br />  <br /> #Add-PSSnapin Quest.ActiveRoles.ADManagement  <br /> #Change School in SearchRoot (e.g.: OU=USERS,OU=SCHOOL NAME HERE,OU=SCHOOLS) and variable ( e.g: $_.school -eq "SCHOOL NAME HERE") <br />  <br /> Import-Csv -Path "C:\mailboxdatabases.csv" | Where-Object{$_.school -eq "fairway" <br />  <br /> if ($_.school -eq "fairway"){ <br /> $Server = $_.ExchangeServer              <br /> $StorageGroup = $_.StorageGroup              <br /> $MailboxDatabase = $_.MailboxDatabase <br /> } <br /> } <br /> $Database = $Server + "\" + $StorageGroup + "\" + $MailboxDatabase <br />  <br /> Get-QADUser -Title "teacher", "staff" -SearchRoot "OU=users,OU=fairway,OU=schools,DC=stockport,DC=sch,DC=uk" -SizeLimit 0 |  <br /> ForEach-Object{ Set-QADUser  -Identity  $_.Name -PasswordNeverExpires $false <br />  <br /> Write-Host "Creating users Mailbox..." <br />  <br /> Enable-Mailbox -Identity $_.Name -Alias $_.samAccountName -Database $Database <br /> $mailbox = Get-Mailbox -Identity $_.samAccountName              <br /> $newaddress = $_.mail             <br /> $mailbox.EmailAddresses += $newaddress <br />    <br /> Write-Host "Adding SMTP Information..." <br />  <br /> Set-Mailbox -Identity $mailbox.alias -EmailAddresses $mailbox.EmailAddresses                        <br /> Set-Mailbox -Identity $mailbox.alias -PrimarySmtpAddress $newaddress -EmailAddressPolicyEnabled $false  <br />  <br /> Write-Host "Moving to next user............." <br /> } <br /> Write-Host "Complete!" <br />  <br />  <br /> 


    This seems to work ok however I would just like it to show my write-host things so the screen is not full of everything about the user r any contents from the CSV file?

    Is this possible?

    Many Thanks

    James
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    13 Dec 2009 09:25 AM
    Try to assign the *-mailbox to $null, it will suppress any output from these commands (if they emit something):

    $null = enable-mailbox ...
    $null = set-mailbox ...

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    14 Dec 2009 01:42 AM
    forgive me for being a little stupid.

    How would I do that?

    Many Thanks

    James
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    14 Dec 2009 06:22 AM
    There you go...

    Notice that I commented out the IF statement inside Foreach-Object. You already excluded all items (using where-object) which their 'school' value doesn't eq fairway.

    Question: C:\mailboxdatabases.csv contains only one 'school -eq "fairway"' item?




    Import-Csv -Path "C:\mailboxdatabases.csv" | Where-Object{$_.school -eq "fairway"} | Foreach-Object{
    #if ($_.school -eq "fairway"){
    $Server = $_.ExchangeServer
    $StorageGroup = $_.StorageGroup
    $MailboxDatabase = $_.MailboxDatabase
    #}
    }

    $Database = $Server\$StorageGroup\$MailboxDatabase"
    Get-QADUser -Title "teacher", "staff" -SearchRoot "OU=users,OU=fairway,OU=schools,DC=stockport,DC=sch,DC=uk" -SizeLimit 0 | ForEach-Object{
    $null = Set-QADUser -Identity $_.Name -PasswordNeverExpires $false
    Write-Host "Creating users Mailbox..."
    $null = Enable-Mailbox -Identity $_.Name -Alias $_.samAccountName -Database $Database
    $mailbox = Get-Mailbox -Identity $_.samAccountName
    $newaddress = $_.mail
    $mailbox.EmailAddresses += $newaddress
    Write-Host "Adding SMTP Information..."
    $null = Set-Mailbox -Identity $mailbox.alias -EmailAddresses $mailbox.EmailAddresses
    $null = Set-Mailbox -Identity $mailbox.alias -PrimarySmtpAddress $newaddress -EmailAddressPolicyEnabled $false
    Write-Host "Moving to next user............."
    }
    Write-Host "Complete!"




    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    15 Dec 2009 09:07 AM
    Hello,

    No there are multiple schools in there its just the only way I could get the code to run for some odd reason.

    As I am not in work until tomorrow I will give it a shot then if I get a chance.

    Many Thanks for your help

    James
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer