Unable to set variable from each item in csv RRS feed

  • Question

  • Hi all,

    I'm pretty stuck here.. I'm unable to associate a variable with my csv file. I import the csv which has three columns, UserPrincipalName, DisplayName, and NewUserPrincipalName. When I import the CSV attempt to associate the column UserPrincipalName and NewUserPrincipalName with a variable. 

    Here is my script so far..

    $csv = Import-csv "F:\temp\user.csv" -Header ("UserPrincipalName", "DisplayName","NewUserPrincipalName")
    ForEach($item in $csv){
    $UPN = $_.UserPrincipalName
    $NewUPN = $_.NewUserPrincipalName
    Set-MsolUserPrincipalName -UserPrincipalName $UPN -NewUserPrincipalName $NewUPN

    • Moved by Bill_Stewart Friday, March 15, 2019 4:45 PM User answered own question
    Wednesday, December 19, 2018 6:27 PM

All replies

  • I feel bad that I went through this submission but I found my issue. Here is my updated script: 

    $csv = Import-csv "F:\temp\user.csv"
    ForEach($item in $csv){
    $UPN = $item.UserPrincipalName
    $NewUPN = $item.NewUserPrincipalName
    Set-MsolUserPrincipalName -UserPrincipalName $UPN -NewUserPrincipalName $NewUPN

    Wednesday, December 19, 2018 6:30 PM