none
powershell script error RRS feed

  • Question

  • Hi Guys,

    I'm writing a script that will help me to move mailbox from 2003 to 2010. I got an error.

    I have a csv file named "user_list.csv"

    This is a part of my script that i'm trying to debug

    <pre lang="x-powershell">$SourceForestUsersToMigrate = @()
    $SourceForestUsersToMigrate = import-CSV "template.csv"
     
     
    foreach ($user in $SourceForestUsersToMigrate) {
     
    Write-Host "Processing user $user" -ForegroundColor Yellow
     
    $TargetObject=(get-user $user).samaccountname
    $TargetObject=$user.samaccountname
    Write-Host $TargetObject
    }
    
    
    The result is that it can't get the information. I got this error message
    [PS] D:\Migration Messenging>.\debug.ps1
    Processing user @{user=jdoetes}
    Cannot process argument transformation on parameter 'Identity'. Cannot convert the "@{user=jdoetes}" value of type "Des
    erialized.System.Management.Automation.PSCustomObject" to type "Microsoft.Exchange.Configuration.Tasks.UserIdParameter"
    .
      + CategoryInfo     : InvalidData: (:) [Get-User], ParameterBindin...mationException
      + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-User
    

    • Moved by Alan.GimModerator Monday, June 6, 2011 5:42 AM script related (From:Exchange Server 2010)
    Friday, June 3, 2011 1:55 PM

All replies

  • The problem seems to be in the format of your template.csv file. Can you post the first few lines from that file?
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Friday, June 3, 2011 2:05 PM
  • user

    eplum

    dbeckam

     

    Friday, June 3, 2011 2:53 PM
  • One more question... when we are using New-MoveRequest on Exchange 2010... what happens to incoming-bound mails during the mailbox migration?
    Friday, June 3, 2011 2:55 PM
  • Okay.  The prolbem is in how you're referencing the user.  When you imported that csv you got an array of objects.  Each object has one property (user).  Even though the user name is the only property, it still has to be referrenced by that property name. eg

    foreach ($user in $SourceForestUsersToMigrate) {

    Write-Host "Processing user $($user.user)" -ForegroundColor Yellow

    Since your csv only has one column, it might be easier to just convert it to a list.  To do that, edit the file and remove the first line (user) that would have been your .csv column heading.  I'd also rename it to a .txt file, but you don't have to.  Then change this line:

    $SourceForestUsersToMigrate = import-CSV "template.csv"

    To:

    $SourceForestUsersToMigrate =get-content "template.csv"

    Now $SourceForestUsersToMigrate is just a list of users, and each one can be referenced as $user, instead of $user.user and you should be able to leave the rest of the script as-is.

    If that makes sense.



    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Friday, June 3, 2011 3:04 PM
  • Thanks for the help... but it's the solution that I ve chosen :)
    Friday, June 3, 2011 3:40 PM
  • You can also do this:

    foreach ($user in ($SourceForestUsersToMigrate |% {$_.user})) {
     

    and use your existing file.
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Friday, June 3, 2011 4:10 PM