James
 Basic Member Posts:374

 |
| 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 |
|
|
|
|
cameronove
 Basic Member Posts:332

 |
| 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 Mitschke
 Basic Member Posts:451

 |
| 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$_"}) |
|
|
James
 Basic Member Posts:374

 |
| 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 |
|
|
|
|