header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Changing the Sam Account Name
Last Post 14 Jan 2010 01:48 AM by James. 3 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
JamesUser is Offline
Basic Member
Basic Member
Posts:374
Avatar

--
08 Jan 2010 08:10 AM
    Hello,

    I have exported out a list of samaccount names which dont match the firstname.surname (with some help from people in here).

    I have tried to import them back with there new account names and its saying it cant find them of it completed successsfully but its not modified anything.

    My code is :



    #Read in the CSV file Import-Csv -Path C:\users.csv | ForEach-Object { $School = $_.School $NewName = $_."Sam Account Name" $Alias = $_.SamAccountName $mailbox = Get-Mailbox -Identity $Alias $mailbox.EmailAddresses += ($_.TotalName + "@$School.stockport.sch.uk" ) $newaddress = $_.TotalName + "@$School.stockport.sch.uk" #Set Additional SMTP Address. Set-Mailbox $mailbox -EmailAddresses $mailbox.EmailAddresses Set-Mailbox -Identity $mailbox.alias -PrimarySmtpAddress $newaddress -EmailAddressPolicyEnabled $false #Get the User and set the SAMAaccountName Get-QADUser -Name $Alias | Set-QADUser -SamAccountName $NewName



    My CSV lookes like:

    FirstName LastName SamAccountName Sam Account Name School count TotalName 
    forname surname currentname modifiedname schoolname 20 forname.surname

    Can anyone shed any light on this?

    Many Thanks

    James
    cameronoveUser is Offline
    Basic Member
    Basic Member
    Posts:332
    Avatar

    --
    12 Jan 2010 07:34 AM
    This is a bit difficult to figure out. When I copy and paste your code into a text editor it appears as one line. Apparently it is multi-line, that said, you are at least missing ending } on your initial fore-each loop.

    Can you post this so it's a litter easier to read?

    Thanks
    Karl MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:451
    Avatar

    --
    12 Jan 2010 02:21 PM
    Cameron;

    I beleive this is his code, and as you say, it's missing the ending curly brace:
    Import-Csv -Path C:\users.csv | ForEach-Object { $School = $_.School $NewName = $_."Sam Account Name" $Alias = $_.SamAccountName $mailbox = Get-Mailbox -Identity $Alias $mailbox.EmailAddresses += ($_.TotalName + "@$School.stockport.sch.uk" ) $newaddress = $_.TotalName + "@$School.stockport.sch.uk" #Set Additional SMTP Address. Set-Mailbox $mailbox -EmailAddresses $mailbox.EmailAddresses Set-Mailbox -Identity $mailbox.alias -PrimarySmtpAddress $newaddress -EmailAddressPolicyEnabled $false #Get the User and set the SAMAaccountName Get-QADUser -Name $Alias | Set-QADUser -SamAccountName $NewName

    James;
    IF this IS your script, add an ending curly brace (}) as the very last character, after $NewName

    Karl
    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    14 Jan 2010 01:48 AM
    Hello,

    I have the following:

    #Read in the CSV file Import-Csv -Path C:\users.csv | ForEach-Object { $School = $_.School $NewName = $_."Sam Account Name" $Alias = $_.SamAccountName $mailbox = Get-Mailbox -Identity $Alias $mailbox.EmailAddresses += ($_.TotalName + "@$School.stockport.sch.uk" ) $newaddress = $_.TotalName + "@$School.stockport.sch.uk" #Set Additional SMTP Address. Set-Mailbox $mailbox -EmailAddresses $mailbox.EmailAddresses Set-Mailbox -Identity $mailbox.alias -PrimarySmtpAddress $newaddress -EmailAddressPolicyEnabled $false #Get the User and set the SAMAaccountName Get-QADUser -Name $Alias | Set-QADUser -SamAccountName $NewName }

    Its still doing the same thing.

    Does anyone have any ideas?

    Many Thanks

    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