Below is a script that will change the value of URL field from something to something. Script works fine and is safe to run. Now, I would like to output in a txt file the old and new values.. Please help with this.
$webs = Get-SPSite http://<somesitecollection> | get-spweb -limit all | ?{$_.URL -like ‘<somethinghere’}
foreach ($web in $webs)
{
$list = $web.Lists[“<someList>”]
foreach ($item in $list.Items)
{
# Iterate HyperLink fields
foreach ($field in $fields)
{
# Get field value
$fldValue = $item[“URL”]
# Skip if null
if($fldValue -ne $null)
{
$item[“URL”] = $fldValue -replace “<something>”, “<withSomething>”
$item.update()
}
}
}
}
$webs.Dispose()
Thanks Nico. Is there a way to make the new value dynamic? I would like to confirm that the value has actually changed.
Hi Jason,
You can use the Add-Content cmdlet to output the old value, but as your new value is a static (“<withSomething>”) It would look the same for this every time. That’s why I only added the old value in the next example:
$webs = Get-SPSite http://<somesitecollection> | get-spweb -limit all | ?{$_.URL -like ‘<somethinghere’}
$outputPath = “C:\somepath”
foreach ($web in $webs)
{
$list = $web.Lists[“<someList>”]
foreach ($item in $list.Items)
{
# Iterate HyperLink fields
foreach ($field in $fields)
{
# Get field value
$fldValue = $item[“URL”]
Add-Content -Path $outputPath -Value “$($fldValue)”
# Skip if null
if($fldValue -ne $null)
{
$item[“URL”] = $fldValue -replace “<something>”, “<withSomething>”
$item.update()
}
}
}
}
$webs.Dispose()