I have a script that is supposed to go into a list and find a replace values with a different value in a column. The error I get is 'You cannot call a method on null-valued expression' pointing to this line ($oldurl.URL = $oldurl.URL.Replace("T9", "DR"))
Any idea what's wrong?
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$siteUrl = "https://[siteName]"
$webName = “Resources”
$listName = "Training"
$spSite = new-object Microsoft.SharePoint.SPSite($siteurl)
$spWeb = $spSite.OpenWeb($webName)
$spList = $spWeb.Lists[$listName]
Write-Host("URL: [$spList]")
foreach($Item in $spList.Items )
{
$oldurl = new-object Microsoft.SharePoint.SPFieldUrlValue($Item["INUM"])
$oldurl.URL = $oldurl.URL.Replace("T9", "DR")
Write-Host("URL: [$oldurl]")
$Item.Update()
}
$spWeb.Dispose()