0

I have a csv file with ID, Region and Phone number. I need to run a powershell to update all the items that has ID match to update Region and Phone Number. I have following and not sure if this is going to do it. I am starting with write-host and it shows blank. Any idea

$SiteUrl = "http://inside.power.gov"
$web = Get-SPWeb $SiteUrl
$ListName = "Survey List"
$List = $web.Lists[$ListName]

$csv = import-csv "c:\updateddata.csv"

foreach($item in $csv)
{
    $spItems = $List.GetItemById($item.ID)
    write-host $item.Region
    write-host $item.Phone Number
    write-host $spItems.Region Name

    #$spItems["Region Name"] = $item.Region
    #$spItems["Phone Number"] = $item.Phone Number
    #$spItems.SystemUpdate()
}

$web.Dispose()
  • I updated the code and now it's working. – Todd Bayne Feb 4 '16 at 16:58
1

Answer was discovered by user:

$SiteUrl = "http://inside.power.gov"
$web = Get-SPWeb $SiteUrl
$ListName = "Survey List"
$List = $web.Lists[$ListName]

$csv = import-csv "c:\updateddata.csv"

foreach($item in $csv)
{
    $spItems = $List.GetItemById($item.ID)
    write-host $item.Region
    write-host $item."Phone Number"
    write-host $spItems["Region Name"]

    #$spItems["Region Name"] = $item.Region
    #$spItems["Phone Number"] = $item.Phone Number
    #$spItems.SystemUpdate()
}

$web.Dispose()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.