Skip to content

Instantly share code, notes, and snippets.

@nonprofittechy
Last active November 1, 2016 17:24
Show Gist options
  • Save nonprofittechy/46192f6f543a0020508f1744ec3316d2 to your computer and use it in GitHub Desktop.
Save nonprofittechy/46192f6f543a0020508f1744ec3316d2 to your computer and use it in GitHub Desktop.
<#
.SYNOPSIS
Updates lists with "Contacts" in the name, replacing any empty "Last Name" fields
with the company name, to prepare for migration to SharePoint Online.
Syntax: fix_missing_lastname.ps1 -url "https://my.sharepoint.site" or update parameter below
.DESCRIPTION
Will scan one-level deep for sub-sites that have a list with 'Contacts' in the title.
.NOTES
Author: Quinten Steenhuis
#>
param (
[string]$url = "https://my.sharepoint.site"
)
Start-SPAssignment -Global
$parentWeb = get-spweb $url
$webs = $parentWeb.webs
foreach ($web in $webs) {
$lists = $web.lists | Where title -like "*contacts*"
foreach ($list in $lists) {
$items = $list.items
foreach ($item in $items) {
if ($item["Last Name"] -like "") {
if (-not ($item["Company"] -like "") ) {
$item["Last Name"] = $item["Company"]
$item.Update()
} else if (-not ($item["First Name"] -like ""){
$item["Last Name"] = $item["First Name"]
$item.Update()
}
}
}
}
}
$ParentWeb.Dispose()
Stop-SPAssignment -Global
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment